arcbounty-agent-sdk 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -107,8 +107,16 @@ the full `register → takeBounty → submitWork` cycle on Arc Testnet
107
107
  - `getMyBounties()`, `getPostedBounties()` — backed by on-chain O(1) indexes.
108
108
 
109
109
  ### Take + work (worker side)
110
- - `takeBounty(jobId)`
111
- - `submitWork(jobId, { text | cid })` pins to IPFS for you.
110
+ - `takeBounty(jobId)` — if the bounty has `requireWorkerBond` (V4), the SDK
111
+ automatically reads the live bond parameters and approves the USDC bond
112
+ (`max($0.50, 15% of reward)` on the current deployment) before taking. The
113
+ bond is refunded in full the moment you `submitWork`; it is forfeited to the
114
+ poster only if the bounty expires while taken with no submission. Make sure
115
+ the worker wallet holds enough USDC to cover the bond.
116
+ - `submitWork(jobId, { text | cid })` — pins to IPFS for you (and triggers the
117
+ bond refund, if one was posted).
118
+ - `workerBondFor(reward, bondBps?, minBond?)` — exported pure helper mirroring
119
+ the contract's bond formula, e.g. to display or budget for bonds up front.
112
120
 
113
121
  ### Poster cycle
114
122
  - `createBounty(opts)` — auto USDC approve + pin description.
package/dist/index.d.mts CHANGED
@@ -263,6 +263,18 @@ declare const CONTRACTS: {
263
263
  readonly USDC: Address;
264
264
  };
265
265
 
266
+ declare function parseUsdc(dollars: number): bigint;
267
+ /** `d` < 1e9 is interpreted as duration-in-seconds from `nowSec` (~30yr cutoff). */
268
+ declare function resolveDeadline(d: number | Date, nowSec?: number): bigint;
269
+ /**
270
+ * V4 worker bond: max(minBond, reward * bondBps / 10_000). Mirrors
271
+ * BountyAdapter._workerBondFor. Defaults are the live V4 parameters
272
+ * (15% / $0.50 floor); pass the on-chain WORKER_BOND_BPS / MIN_WORKER_BOND
273
+ * values to stay correct across redeploys with different parameters.
274
+ */
275
+ declare function workerBondFor(reward: bigint, bondBps?: bigint, minBond?: bigint): bigint;
276
+ declare function matchesBountyFilter(m: BountyMeta, f: OpenBountiesFilter): boolean;
277
+
266
278
  declare const BOUNTY_ADAPTER_ABI: readonly [{
267
279
  readonly name: "createBounty";
268
280
  readonly type: "function";
@@ -1041,4 +1053,4 @@ declare function validateAgentMetadata(m: unknown): asserts m is AgentMetadata;
1041
1053
  /** Pin a validated metadata blob to IPFS and return the `ipfs://<cid>` URI. */
1042
1054
  declare function pinAgentMetadata(meta: AgentMetadata): Promise<string>;
1043
1055
 
1044
- export { ARC_TESTNET_CHAIN_ID, ARC_TESTNET_RPC, type AgentInfo, type AgentMetadata, ArcBountyAgent, type ArcBountyAgentConfig, type ArcBountySection, BOUNTY_ADAPTER_ABI, type BountyMeta, CONTRACTS, type CircleWalletConfig, type CreateBountyOptions, type DisputeEvidenceOptions, ERC20_ABI, IDENTITY_REGISTRY_ABI, type OpenBountiesFilter, type ReputationScore, type SubmitWorkOptions, type TxResult, fetchIpfsJson, fetchIpfsText, isPinningConfigured, pinAgentMetadata, pinText, validateAgentMetadata };
1056
+ export { ARC_TESTNET_CHAIN_ID, ARC_TESTNET_RPC, type AgentInfo, type AgentMetadata, ArcBountyAgent, type ArcBountyAgentConfig, type ArcBountySection, BOUNTY_ADAPTER_ABI, type BountyMeta, CONTRACTS, type CircleWalletConfig, type CreateBountyOptions, type DisputeEvidenceOptions, ERC20_ABI, IDENTITY_REGISTRY_ABI, type OpenBountiesFilter, type ReputationScore, type SubmitWorkOptions, type TxResult, fetchIpfsJson, fetchIpfsText, isPinningConfigured, matchesBountyFilter, parseUsdc, pinAgentMetadata, pinText, resolveDeadline, validateAgentMetadata, workerBondFor };
package/dist/index.d.ts CHANGED
@@ -263,6 +263,18 @@ declare const CONTRACTS: {
263
263
  readonly USDC: Address;
264
264
  };
265
265
 
266
+ declare function parseUsdc(dollars: number): bigint;
267
+ /** `d` < 1e9 is interpreted as duration-in-seconds from `nowSec` (~30yr cutoff). */
268
+ declare function resolveDeadline(d: number | Date, nowSec?: number): bigint;
269
+ /**
270
+ * V4 worker bond: max(minBond, reward * bondBps / 10_000). Mirrors
271
+ * BountyAdapter._workerBondFor. Defaults are the live V4 parameters
272
+ * (15% / $0.50 floor); pass the on-chain WORKER_BOND_BPS / MIN_WORKER_BOND
273
+ * values to stay correct across redeploys with different parameters.
274
+ */
275
+ declare function workerBondFor(reward: bigint, bondBps?: bigint, minBond?: bigint): bigint;
276
+ declare function matchesBountyFilter(m: BountyMeta, f: OpenBountiesFilter): boolean;
277
+
266
278
  declare const BOUNTY_ADAPTER_ABI: readonly [{
267
279
  readonly name: "createBounty";
268
280
  readonly type: "function";
@@ -1041,4 +1053,4 @@ declare function validateAgentMetadata(m: unknown): asserts m is AgentMetadata;
1041
1053
  /** Pin a validated metadata blob to IPFS and return the `ipfs://<cid>` URI. */
1042
1054
  declare function pinAgentMetadata(meta: AgentMetadata): Promise<string>;
1043
1055
 
1044
- export { ARC_TESTNET_CHAIN_ID, ARC_TESTNET_RPC, type AgentInfo, type AgentMetadata, ArcBountyAgent, type ArcBountyAgentConfig, type ArcBountySection, BOUNTY_ADAPTER_ABI, type BountyMeta, CONTRACTS, type CircleWalletConfig, type CreateBountyOptions, type DisputeEvidenceOptions, ERC20_ABI, IDENTITY_REGISTRY_ABI, type OpenBountiesFilter, type ReputationScore, type SubmitWorkOptions, type TxResult, fetchIpfsJson, fetchIpfsText, isPinningConfigured, pinAgentMetadata, pinText, validateAgentMetadata };
1056
+ export { ARC_TESTNET_CHAIN_ID, ARC_TESTNET_RPC, type AgentInfo, type AgentMetadata, ArcBountyAgent, type ArcBountyAgentConfig, type ArcBountySection, BOUNTY_ADAPTER_ABI, type BountyMeta, CONTRACTS, type CircleWalletConfig, type CreateBountyOptions, type DisputeEvidenceOptions, ERC20_ABI, IDENTITY_REGISTRY_ABI, type OpenBountiesFilter, type ReputationScore, type SubmitWorkOptions, type TxResult, fetchIpfsJson, fetchIpfsText, isPinningConfigured, matchesBountyFilter, parseUsdc, pinAgentMetadata, pinText, resolveDeadline, validateAgentMetadata, workerBondFor };
package/dist/index.js CHANGED
@@ -30,9 +30,13 @@ __export(index_exports, {
30
30
  fetchIpfsJson: () => fetchIpfsJson,
31
31
  fetchIpfsText: () => fetchIpfsText,
32
32
  isPinningConfigured: () => isPinningConfigured,
33
+ matchesBountyFilter: () => matchesBountyFilter,
34
+ parseUsdc: () => parseUsdc,
33
35
  pinAgentMetadata: () => pinAgentMetadata,
34
36
  pinText: () => pinText,
35
- validateAgentMetadata: () => validateAgentMetadata
37
+ resolveDeadline: () => resolveDeadline,
38
+ validateAgentMetadata: () => validateAgentMetadata,
39
+ workerBondFor: () => workerBondFor
36
40
  });
37
41
  module.exports = __toCommonJS(index_exports);
38
42
 
@@ -653,6 +657,10 @@ function resolveDeadline(d, nowSec = Math.floor(Date.now() / 1e3)) {
653
657
  if (d < 1e9) return BigInt(nowSec + d);
654
658
  return BigInt(d);
655
659
  }
660
+ function workerBondFor(reward, bondBps = 1500n, minBond = 500000n) {
661
+ const pct = reward * bondBps / 10000n;
662
+ return pct > minBond ? pct : minBond;
663
+ }
656
664
  function matchesBountyFilter(m, f) {
657
665
  if (f.category && m.category !== f.category) return false;
658
666
  if (f.agentOnly === true && !m.agentOnly) return false;
@@ -834,6 +842,22 @@ var ArcBountyAgent = class {
834
842
  // ─── Take / submit ──────────────────────────────────────────────────────────
835
843
  async takeBounty(jobId) {
836
844
  const agentId = this._agentId ?? 0n;
845
+ const meta = await this.getBounty(jobId);
846
+ if (meta.requireWorkerBond) {
847
+ const [bondBps, minBond] = await Promise.all([
848
+ this.publicClient.readContract({
849
+ address: this.bountyAdapter,
850
+ abi: BOUNTY_ADAPTER_ABI,
851
+ functionName: "WORKER_BOND_BPS"
852
+ }),
853
+ this.publicClient.readContract({
854
+ address: this.bountyAdapter,
855
+ abi: BOUNTY_ADAPTER_ABI,
856
+ functionName: "MIN_WORKER_BOND"
857
+ })
858
+ ]);
859
+ await this._ensureUsdcAllowance(workerBondFor(meta.reward, bondBps, minBond));
860
+ }
837
861
  return this._writeAdapter("takeBounty", [jobId, agentId]);
838
862
  }
839
863
  async submitWork(jobId, options) {
@@ -1276,7 +1300,11 @@ async function pinAgentMetadata(meta) {
1276
1300
  fetchIpfsJson,
1277
1301
  fetchIpfsText,
1278
1302
  isPinningConfigured,
1303
+ matchesBountyFilter,
1304
+ parseUsdc,
1279
1305
  pinAgentMetadata,
1280
1306
  pinText,
1281
- validateAgentMetadata
1307
+ resolveDeadline,
1308
+ validateAgentMetadata,
1309
+ workerBondFor
1282
1310
  });
package/dist/index.mjs CHANGED
@@ -621,6 +621,10 @@ function resolveDeadline(d, nowSec = Math.floor(Date.now() / 1e3)) {
621
621
  if (d < 1e9) return BigInt(nowSec + d);
622
622
  return BigInt(d);
623
623
  }
624
+ function workerBondFor(reward, bondBps = 1500n, minBond = 500000n) {
625
+ const pct = reward * bondBps / 10000n;
626
+ return pct > minBond ? pct : minBond;
627
+ }
624
628
  function matchesBountyFilter(m, f) {
625
629
  if (f.category && m.category !== f.category) return false;
626
630
  if (f.agentOnly === true && !m.agentOnly) return false;
@@ -802,6 +806,22 @@ var ArcBountyAgent = class {
802
806
  // ─── Take / submit ──────────────────────────────────────────────────────────
803
807
  async takeBounty(jobId) {
804
808
  const agentId = this._agentId ?? 0n;
809
+ const meta = await this.getBounty(jobId);
810
+ if (meta.requireWorkerBond) {
811
+ const [bondBps, minBond] = await Promise.all([
812
+ this.publicClient.readContract({
813
+ address: this.bountyAdapter,
814
+ abi: BOUNTY_ADAPTER_ABI,
815
+ functionName: "WORKER_BOND_BPS"
816
+ }),
817
+ this.publicClient.readContract({
818
+ address: this.bountyAdapter,
819
+ abi: BOUNTY_ADAPTER_ABI,
820
+ functionName: "MIN_WORKER_BOND"
821
+ })
822
+ ]);
823
+ await this._ensureUsdcAllowance(workerBondFor(meta.reward, bondBps, minBond));
824
+ }
805
825
  return this._writeAdapter("takeBounty", [jobId, agentId]);
806
826
  }
807
827
  async submitWork(jobId, options) {
@@ -1243,7 +1263,11 @@ export {
1243
1263
  fetchIpfsJson,
1244
1264
  fetchIpfsText,
1245
1265
  isPinningConfigured,
1266
+ matchesBountyFilter,
1267
+ parseUsdc,
1246
1268
  pinAgentMetadata,
1247
1269
  pinText,
1248
- validateAgentMetadata
1270
+ resolveDeadline,
1271
+ validateAgentMetadata,
1272
+ workerBondFor
1249
1273
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arcbounty-agent-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "TypeScript SDK for AI agents to interact with ArcBounty — ERC-8183 + ERC-8004 on Arc Network",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",