@elgora/cli 7.2.1 → 7.2.3

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.
Files changed (2) hide show
  1. package/dist/cli.js +90 -18
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -3215,6 +3215,16 @@ function decodeBountyStatus(status) {
3215
3215
  }
3216
3216
  return decoded;
3217
3217
  }
3218
+ var BPS_DENOMINATOR = 10000n;
3219
+ function settlementAmounts(escrowAmount, treasuryFeeBps, guardianFeeBps) {
3220
+ const treasuryAmount = escrowAmount * BigInt(treasuryFeeBps) / BPS_DENOMINATOR;
3221
+ const guardianAmount = escrowAmount * BigInt(guardianFeeBps) / BPS_DENOMINATOR;
3222
+ return {
3223
+ treasuryAmount,
3224
+ guardianAmount,
3225
+ winnerPool: escrowAmount - treasuryAmount - guardianAmount
3226
+ };
3227
+ }
3218
3228
 
3219
3229
  // ../../packages/core/src/api/bounty-detail.ts
3220
3230
  import { zeroAddress } from "viem";
@@ -4101,6 +4111,11 @@ async function main(env = process.env, argv = process.argv.slice(2)) {
4101
4111
  `Award for bounty_id ${args.bountyId.toString()} is already claimed or partially claimed`
4102
4112
  );
4103
4113
  }
4114
+ claimableAmount = settlementAmounts(
4115
+ parameters.escrowAmount,
4116
+ parameters.treasuryFeeBps,
4117
+ parameters.guardianFeeBps
4118
+ ).winnerPool;
4104
4119
  functionName = "claimAward";
4105
4120
  } else if (status === "no_valid_submission" || status === "timed_out") {
4106
4121
  if (parameters.poster.toLowerCase() !== normalizedClaimant) {
@@ -4890,6 +4905,16 @@ function readArgs(argv) {
4890
4905
  };
4891
4906
  }
4892
4907
 
4908
+ // ../../packages/subgraph-client/src/errors.ts
4909
+ var SubgraphReadError = class extends Error {
4910
+ reason;
4911
+ constructor(reason, message, options) {
4912
+ super(message, options);
4913
+ this.name = "SubgraphReadError";
4914
+ this.reason = reason;
4915
+ }
4916
+ };
4917
+
4893
4918
  // ../../packages/subgraph-client/src/status.ts
4894
4919
  function mapSubgraphStatus(value) {
4895
4920
  switch (value) {
@@ -4981,6 +5006,7 @@ var GUARDIAN_ROSTER_SNAPSHOT_FIELDS = `
4981
5006
  id
4982
5007
  memberCount
4983
5008
  members {
5009
+ position
4984
5010
  account
4985
5011
  name
4986
5012
  encryptionPublicKey
@@ -5141,26 +5167,41 @@ function createElgoraSubgraphClient(options) {
5141
5167
  return options.hubAddress;
5142
5168
  }
5143
5169
  async function execute(query, variables) {
5144
- const response = await fetchImpl(
5145
- endpoint,
5146
- JSON.stringify({ query, variables })
5147
- );
5148
- const raw = await response.text();
5170
+ let response;
5171
+ let raw;
5172
+ try {
5173
+ response = await fetchImpl(
5174
+ endpoint,
5175
+ JSON.stringify({ query, variables })
5176
+ );
5177
+ raw = await response.text();
5178
+ } catch (cause) {
5179
+ throw new SubgraphReadError(
5180
+ "transport_failed",
5181
+ "Subgraph request did not complete",
5182
+ { cause }
5183
+ );
5184
+ }
5149
5185
  if (!response.ok) {
5150
- throw new Error(
5186
+ throw new SubgraphReadError(
5187
+ "request_failed",
5151
5188
  `Subgraph request failed with status ${response.status}: ${raw}`
5152
5189
  );
5153
5190
  }
5154
5191
  const parsed = parseJson(raw);
5155
5192
  const errors = readRecord(parsed).errors;
5156
5193
  if (Array.isArray(errors) && errors.length > 0) {
5157
- throw new Error(
5194
+ throw new SubgraphReadError(
5195
+ "query_errors",
5158
5196
  `Subgraph query returned errors: ${JSON.stringify(errors)}`
5159
5197
  );
5160
5198
  }
5161
5199
  const data = readRecord(parsed).data;
5162
5200
  if (data === void 0 || data === null) {
5163
- throw new Error("Subgraph response did not include a data object");
5201
+ throw new SubgraphReadError(
5202
+ "malformed_response",
5203
+ "Subgraph response did not include a data object"
5204
+ );
5164
5205
  }
5165
5206
  return data;
5166
5207
  }
@@ -5350,7 +5391,8 @@ function mapAnalyticsGuardianRoster(row) {
5350
5391
  const members = asArray(record.members, "members");
5351
5392
  const memberCount = asNumber(record.memberCount, "memberCount");
5352
5393
  if (members.length !== memberCount) {
5353
- throw new Error(
5394
+ throw new SubgraphReadError(
5395
+ "unexpected_shape",
5354
5396
  "Historical Guardian roster members do not match memberCount"
5355
5397
  );
5356
5398
  }
@@ -5457,6 +5499,7 @@ function mapSubmissionFields(row) {
5457
5499
  function mapGuardianRosterMember(row) {
5458
5500
  const record = readRecord(row);
5459
5501
  return {
5502
+ position: asSafeInteger(record.position, "members.position"),
5460
5503
  account: asHex(record.account, "account"),
5461
5504
  name: asString(record.name, "name"),
5462
5505
  encryptionPublicKey: asString(
@@ -5467,10 +5510,19 @@ function mapGuardianRosterMember(row) {
5467
5510
  }
5468
5511
  function mapGuardianRosterSnapshot(row) {
5469
5512
  const record = readRecord(row);
5513
+ const members = asArray(record.members, "members").map(mapGuardianRosterMember).sort((left, right) => left.position - right.position);
5514
+ members.forEach((member, index) => {
5515
+ if (member.position !== index) {
5516
+ throw new SubgraphReadError(
5517
+ "unexpected_shape",
5518
+ `Guardian roster snapshot positions are not 0..n-1 for '${asHex(record.id, "id")}'`
5519
+ );
5520
+ }
5521
+ });
5470
5522
  return {
5471
5523
  rosterHash: asHex(record.id, "id"),
5472
5524
  memberCount: asNumber(record.memberCount, "memberCount"),
5473
- members: asArray(record.members, "members").map(mapGuardianRosterMember),
5525
+ members: members.map(({ position: _position, ...member }) => member),
5474
5526
  recordedAt: asString(record.recordedAt, "recordedAt")
5475
5527
  };
5476
5528
  }
@@ -5549,7 +5601,10 @@ function parseJson(raw) {
5549
5601
  try {
5550
5602
  return JSON.parse(raw);
5551
5603
  } catch {
5552
- throw new Error(`Subgraph returned non-JSON response: ${raw}`);
5604
+ throw new SubgraphReadError(
5605
+ "malformed_response",
5606
+ `Subgraph returned non-JSON response: ${raw}`
5607
+ );
5553
5608
  }
5554
5609
  }
5555
5610
  function readRecord(value) {
@@ -5557,12 +5612,16 @@ function readRecord(value) {
5557
5612
  }
5558
5613
  function asString(value, field) {
5559
5614
  if (typeof value === "string") return value;
5560
- throw new Error(`Expected string for subgraph field '${field}'`);
5615
+ throw new SubgraphReadError(
5616
+ "unexpected_shape",
5617
+ `Expected string for subgraph field '${field}'`
5618
+ );
5561
5619
  }
5562
5620
  function asUnsignedBigInt(value, field) {
5563
5621
  const text = asString(value, field);
5564
5622
  if (/^(?:0|[1-9][0-9]*)$/.test(text)) return BigInt(text);
5565
- throw new Error(
5623
+ throw new SubgraphReadError(
5624
+ "unexpected_shape",
5566
5625
  `Expected non-negative integer string for subgraph field '${field}'`
5567
5626
  );
5568
5627
  }
@@ -5572,29 +5631,42 @@ function asNullableString(value, field) {
5572
5631
  }
5573
5632
  function asNumber(value, field) {
5574
5633
  if (typeof value === "number" && Number.isFinite(value)) return value;
5575
- throw new Error(`Expected number for subgraph field '${field}'`);
5634
+ throw new SubgraphReadError(
5635
+ "unexpected_shape",
5636
+ `Expected number for subgraph field '${field}'`
5637
+ );
5576
5638
  }
5577
5639
  function asSafeInteger(value, field) {
5578
5640
  if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) {
5579
5641
  return value;
5580
5642
  }
5581
- throw new Error(
5643
+ throw new SubgraphReadError(
5644
+ "unexpected_shape",
5582
5645
  `Expected non-negative integer for subgraph field '${field}'`
5583
5646
  );
5584
5647
  }
5585
5648
  function asBoolean(value, field) {
5586
5649
  if (typeof value === "boolean") return value;
5587
- throw new Error(`Expected boolean for subgraph field '${field}'`);
5650
+ throw new SubgraphReadError(
5651
+ "unexpected_shape",
5652
+ `Expected boolean for subgraph field '${field}'`
5653
+ );
5588
5654
  }
5589
5655
  function asArray(value, field) {
5590
5656
  if (Array.isArray(value)) return value;
5591
- throw new Error(`Expected array for subgraph field '${field}'`);
5657
+ throw new SubgraphReadError(
5658
+ "unexpected_shape",
5659
+ `Expected array for subgraph field '${field}'`
5660
+ );
5592
5661
  }
5593
5662
  function asHex(value, field) {
5594
5663
  if (typeof value === "string" && value.startsWith("0x")) {
5595
5664
  return value.toLowerCase();
5596
5665
  }
5597
- throw new Error(`Expected hex string for subgraph field '${field}'`);
5666
+ throw new SubgraphReadError(
5667
+ "unexpected_shape",
5668
+ `Expected hex string for subgraph field '${field}'`
5669
+ );
5598
5670
  }
5599
5671
  function asNullableHex(value, field) {
5600
5672
  if (value === null || value === void 0) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elgora/cli",
3
- "version": "7.2.1",
3
+ "version": "7.2.3",
4
4
  "description": "Command-line client for Elgora, a decentralized bounty marketplace for science. Lets Posters, Solvers, and Guardians interact with Elgora's public API and on-chain contracts.",
5
5
  "type": "module",
6
6
  "license": "MIT",