@t2000/sdk 10.14.1 → 10.15.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/dist/index.cjs CHANGED
@@ -3415,6 +3415,143 @@ async function verifyJobForSeller({
3415
3415
  return { ok: problems.length === 0, job, problems };
3416
3416
  }
3417
3417
 
3418
+ // src/wallet/opening.ts
3419
+ init_errors();
3420
+ init_token_registry();
3421
+ init_coinSelection();
3422
+ var A2A_ESCROW_OPENING_PACKAGE_ID = process.env.A2A_ESCROW_OPENING_PACKAGE_ID ?? "0x860288d789dc617f6474a0a6801d6011e53bf30d5fb801cdad47b9bc6adb098b";
3423
+ var CLOCK_ID3 = "0x6";
3424
+ var MODULE2 = "opening";
3425
+ var SHA256_HEX_RE = /^(0x)?[0-9a-fA-F]{64}$/;
3426
+ var OPENING_CLAIM_POLICY_ANY_ACTIVE = 0;
3427
+ var MAX_OPEN_WINDOW_MS = 2592e6;
3428
+ function feeConfigArg2(tx) {
3429
+ return tx.sharedObjectRef({
3430
+ objectId: A2A_ESCROW_FEE_CONFIG_ID,
3431
+ initialSharedVersion: A2A_ESCROW_FEE_CONFIG_VERSION,
3432
+ mutable: false
3433
+ });
3434
+ }
3435
+ function hexToBytes3(hex) {
3436
+ const clean = hex.replace(/^0x/, "");
3437
+ const bytes = [];
3438
+ for (let i = 0; i < clean.length; i += 2) {
3439
+ bytes.push(Number.parseInt(clean.slice(i, i + 2), 16));
3440
+ }
3441
+ return bytes;
3442
+ }
3443
+ function preflightCreateOpening(terms) {
3444
+ if (!Number.isFinite(terms.amountUsdc) || terms.amountUsdc <= 0) {
3445
+ return { valid: false, code: "INVALID_AMOUNT", error: "Budget must be positive." };
3446
+ }
3447
+ if (terms.amountUsdc > MAX_JOB_USDC) {
3448
+ return {
3449
+ valid: false,
3450
+ code: "INVALID_AMOUNT",
3451
+ error: `Open jobs cap at ${MAX_JOB_USDC} USDC (v1).`
3452
+ };
3453
+ }
3454
+ if (!SHA256_HEX_RE.test(terms.specHash)) {
3455
+ return { valid: false, code: "INVALID_INPUT", error: "specHash must be a sha256 hex string." };
3456
+ }
3457
+ const now = Date.now();
3458
+ if (terms.openUntilMs <= now) {
3459
+ return { valid: false, code: "INVALID_INPUT", error: "openUntil must be in the future." };
3460
+ }
3461
+ if (terms.openUntilMs > now + MAX_OPEN_WINDOW_MS) {
3462
+ return { valid: false, code: "INVALID_INPUT", error: "Openings can stay claimable at most 30 days." };
3463
+ }
3464
+ if (terms.slaMs <= 0) {
3465
+ return { valid: false, code: "INVALID_INPUT", error: "Delivery window must be positive." };
3466
+ }
3467
+ return { valid: true };
3468
+ }
3469
+ async function buildCreateOpeningTx({
3470
+ client,
3471
+ buyer,
3472
+ terms
3473
+ }) {
3474
+ const pf = preflightCreateOpening(terms);
3475
+ if (!pf.valid) throw new exports.T2000Error(pf.code ?? "INVALID_INPUT", pf.error ?? "Invalid opening.");
3476
+ const rawAmount = BigInt(Math.floor(terms.amountUsdc * 10 ** USDC_DECIMALS));
3477
+ const tx = new transactions.Transaction();
3478
+ const { coin } = await selectAndSplitCoin(tx, client, validateAddress(buyer), exports.USDC_TYPE, rawAmount, {
3479
+ allowSwapAll: false
3480
+ });
3481
+ tx.moveCall({
3482
+ target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE2}::create_open`,
3483
+ typeArguments: [exports.USDC_TYPE],
3484
+ arguments: [
3485
+ coin,
3486
+ tx.pure.vector("u8", hexToBytes3(terms.specHash)),
3487
+ tx.pure.u64(terms.openUntilMs),
3488
+ tx.pure.u64(terms.slaMs),
3489
+ tx.pure.u64(terms.reviewWindowMs),
3490
+ tx.pure.u64(terms.rejectSplitBps),
3491
+ tx.pure.u8(OPENING_CLAIM_POLICY_ANY_ACTIVE),
3492
+ feeConfigArg2(tx),
3493
+ tx.object(CLOCK_ID3)
3494
+ ]
3495
+ });
3496
+ return tx;
3497
+ }
3498
+ function buildClaimOpeningTx({
3499
+ openingId,
3500
+ registryId
3501
+ }) {
3502
+ const tx = new transactions.Transaction();
3503
+ tx.moveCall({
3504
+ target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE2}::claim`,
3505
+ typeArguments: [exports.USDC_TYPE],
3506
+ arguments: [
3507
+ tx.object(openingId),
3508
+ tx.object(registryId),
3509
+ feeConfigArg2(tx),
3510
+ tx.object(CLOCK_ID3)
3511
+ ]
3512
+ });
3513
+ return tx;
3514
+ }
3515
+ function openingCall(openingId, fn) {
3516
+ const tx = new transactions.Transaction();
3517
+ tx.moveCall({
3518
+ target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE2}::${fn}`,
3519
+ typeArguments: [exports.USDC_TYPE],
3520
+ arguments: [tx.object(openingId), feeConfigArg2(tx), tx.object(CLOCK_ID3)]
3521
+ });
3522
+ return tx;
3523
+ }
3524
+ function buildCancelOpeningTx(openingId) {
3525
+ return openingCall(openingId, "cancel_open");
3526
+ }
3527
+ function buildRefundUnclaimedTx(openingId) {
3528
+ return openingCall(openingId, "refund_unclaimed");
3529
+ }
3530
+ function bytesToHex3(bytes) {
3531
+ return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
3532
+ }
3533
+ async function getOpening(client, openingId) {
3534
+ const resp = await client.core.getObject({ objectId: openingId, include: { json: true } }).catch(() => null);
3535
+ const objType = resp?.object?.type ?? "";
3536
+ const json = resp?.object?.json;
3537
+ if (!json || !objType.includes(`::${MODULE2}::Opening<`)) {
3538
+ return null;
3539
+ }
3540
+ return {
3541
+ id: openingId,
3542
+ buyer: String(json.buyer),
3543
+ amountUsdc: Number(json.amount) / 10 ** USDC_DECIMALS,
3544
+ feeBps: Number(json.fee_bps ?? 0),
3545
+ specHash: bytesToHex3(json.spec_hash ?? []),
3546
+ openUntilMs: Number(json.open_until_ms),
3547
+ slaMs: Number(json.sla_ms),
3548
+ reviewWindowMs: Number(json.review_window_ms),
3549
+ rejectSplitBps: Number(json.reject_split_bps),
3550
+ claimPolicy: Number(json.claim_policy ?? 0),
3551
+ createdAtMs: Number(json.created_at_ms ?? 0)
3552
+ };
3553
+ }
3554
+
3418
3555
  // src/commerce.ts
3419
3556
  var DEFAULT_COMMERCE_API_BASE = "https://api.t2000.ai/v1";
3420
3557
  async function commerceFetchJson(url, init) {
@@ -3565,7 +3702,6 @@ async function listOpenJobs(base, filter = {}) {
3565
3702
  if (filter.status) params.set("status", filter.status);
3566
3703
  if (filter.query) params.set("q", filter.query);
3567
3704
  if (filter.buyer) params.set("buyer", filter.buyer);
3568
- if (filter.seller) params.set("seller", filter.seller);
3569
3705
  if (filter.limit) params.set("limit", String(filter.limit));
3570
3706
  const qs = params.size > 0 ? `?${params.toString()}` : "";
3571
3707
  const json = await fetchJson(`${base}/open-jobs${qs}`);
@@ -3577,74 +3713,45 @@ async function getOpenJob(base, id) {
3577
3713
  );
3578
3714
  return json.openJob;
3579
3715
  }
3580
- async function signedChallenge(base, signer, action, id) {
3581
- const address = signer.getAddress();
3582
- const challenge = await fetchJson(`${base}/agent/challenge`, {
3583
- method: "POST",
3584
- body: { address }
3585
- });
3586
- const nonce = challenge.nonce;
3587
- if (!nonce) {
3588
- throw new Error("Failed to get a challenge nonce.");
3589
- }
3590
- const message = new TextEncoder().encode(
3591
- id ? `t2000-open-${action}:${nonce}:${id}` : `t2000-open-${action}:${nonce}`
3592
- );
3593
- const { signature } = await signer.signPersonalMessage(message);
3594
- return { address, nonce, signature };
3595
- }
3596
- async function createOpenJob(base, signer, input) {
3597
- const auth = await signedChallenge(base, signer, "create");
3598
- const json = await fetchJson(`${base}/open-jobs`, {
3599
- method: "POST",
3600
- body: { ...auth, ...input }
3601
- });
3602
- return json.openJob;
3603
- }
3604
- async function claimOpenJob(base, signer, id) {
3605
- const auth = await signedChallenge(base, signer, "claim", id);
3606
- const json = await fetchJson(
3607
- `${base}/open-jobs/${encodeURIComponent(id)}/claim`,
3608
- { method: "POST", body: auth }
3609
- );
3610
- return json.openJob ?? null;
3611
- }
3612
- async function unclaimOpenJob(base, signer, id) {
3613
- const auth = await signedChallenge(base, signer, "unclaim", id);
3614
- await fetchJson(`${base}/open-jobs/${encodeURIComponent(id)}/unclaim`, {
3615
- method: "POST",
3616
- body: auth
3617
- });
3618
- }
3619
- async function cancelOpenJob(base, signer, id) {
3620
- const auth = await signedChallenge(base, signer, "cancel", id);
3621
- await fetchJson(`${base}/open-jobs/${encodeURIComponent(id)}/cancel`, {
3622
- method: "POST",
3623
- body: auth
3624
- });
3625
- }
3626
- async function fundOpenJob(base, signer, id) {
3716
+ async function sponsoredOpeningVerb(base, signer, action, params) {
3627
3717
  const address = signer.getAddress();
3628
- const encoded = encodeURIComponent(id.trim());
3629
- const prep = await fetchJson(`${base}/open-jobs/${encoded}/fund-prepare`, {
3718
+ const prep = await fetchJson(`${base}/job/prepare`, {
3630
3719
  method: "POST",
3631
- body: { address }
3720
+ body: { address, action, params }
3632
3721
  });
3633
3722
  const nonce = prep.nonce;
3634
3723
  const txBytes = prep.txBytes;
3635
3724
  if (!(nonce && txBytes)) {
3636
- throw new Error("Failed to prepare the funding transaction.");
3725
+ throw new Error("Failed to prepare the transaction.");
3637
3726
  }
3638
3727
  const { signature } = await signer.signTransaction(utils.fromBase64(txBytes));
3639
- const json = await fetchJson(`${base}/open-jobs/${encoded}/fund-submit`, {
3728
+ const json = await fetchJson(`${base}/job/submit`, {
3640
3729
  method: "POST",
3641
3730
  body: { nonce, address, signature }
3642
3731
  });
3643
3732
  const digest = json.digest;
3644
3733
  if (!digest) {
3645
- throw new Error("The funding transaction did not go through.");
3734
+ throw new Error("The transaction did not go through.");
3646
3735
  }
3647
- return { digest, jobId: json.jobId ?? null };
3736
+ return digest;
3737
+ }
3738
+ function postOpenJob(base, signer, input) {
3739
+ return sponsoredOpeningVerb(base, signer, "open-create", input);
3740
+ }
3741
+ function claimOpenJob(base, signer, openingId) {
3742
+ return sponsoredOpeningVerb(base, signer, "open-claim", {
3743
+ openingId: openingId.trim()
3744
+ });
3745
+ }
3746
+ function cancelOpenJob(base, signer, openingId) {
3747
+ return sponsoredOpeningVerb(base, signer, "open-cancel", {
3748
+ openingId: openingId.trim()
3749
+ });
3750
+ }
3751
+ function refundOpenJob(base, signer, openingId) {
3752
+ return sponsoredOpeningVerb(base, signer, "open-refund", {
3753
+ openingId: openingId.trim()
3754
+ });
3648
3755
  }
3649
3756
 
3650
3757
  // src/index.ts
@@ -4452,6 +4559,7 @@ async function buildDirectPoolSwapTx(args) {
4452
4559
  }
4453
4560
 
4454
4561
  exports.A2A_ESCROW_FEE_CONFIG_ID = A2A_ESCROW_FEE_CONFIG_ID;
4562
+ exports.A2A_ESCROW_OPENING_PACKAGE_ID = A2A_ESCROW_OPENING_PACKAGE_ID;
4455
4563
  exports.A2A_ESCROW_PACKAGE_ID = A2A_ESCROW_PACKAGE_ID;
4456
4564
  exports.AGENT_CAPITAL_PACKAGE_ID = AGENT_CAPITAL_PACKAGE_ID;
4457
4565
  exports.AGENT_CAPITAL_PUBLISHED_AT = AGENT_CAPITAL_PUBLISHED_AT;
@@ -4491,9 +4599,11 @@ exports.LimitEnforcer = LimitEnforcer;
4491
4599
  exports.LimitExceededError = LimitExceededError;
4492
4600
  exports.MAX_DELIVER_HORIZON_MS = MAX_DELIVER_HORIZON_MS;
4493
4601
  exports.MAX_JOB_USDC = MAX_JOB_USDC;
4602
+ exports.MAX_OPEN_WINDOW_MS = MAX_OPEN_WINDOW_MS;
4494
4603
  exports.MAX_REVIEW_WINDOW_MS = MAX_REVIEW_WINDOW_MS;
4495
4604
  exports.MIN_LP_USDC = MIN_LP_USDC;
4496
4605
  exports.MIST_PER_SUI = MIST_PER_SUI;
4606
+ exports.OPENING_CLAIM_POLICY_ANY_ACTIVE = OPENING_CLAIM_POLICY_ANY_ACTIVE;
4497
4607
  exports.OPERATION_ASSETS = OPERATION_ASSETS;
4498
4608
  exports.SENDABLE_ASSETS = SENDABLE_ASSETS;
4499
4609
  exports.SPONSORED_PYTH_DEPENDENT_PROVIDERS = SPONSORED_PYTH_DEPENDENT_PROVIDERS;
@@ -4519,11 +4629,15 @@ exports.assertBuyerRequirements = assertBuyerRequirements;
4519
4629
  exports.assertLimitConfig = assertLimitConfig;
4520
4630
  exports.buildAddLeafTx = buildAddLeafTx;
4521
4631
  exports.buildAgentCoinModule = buildAgentCoinModule;
4632
+ exports.buildCancelOpeningTx = buildCancelOpeningTx;
4633
+ exports.buildClaimOpeningTx = buildClaimOpeningTx;
4522
4634
  exports.buildCreateJobTx = buildCreateJobTx;
4635
+ exports.buildCreateOpeningTx = buildCreateOpeningTx;
4523
4636
  exports.buildDeliverJobTx = buildDeliverJobTx;
4524
4637
  exports.buildDirectPoolSwapTx = buildDirectPoolSwapTx;
4525
4638
  exports.buildPublishAgentCoinTx = buildPublishAgentCoinTx;
4526
4639
  exports.buildRefundJobTx = buildRefundJobTx;
4640
+ exports.buildRefundUnclaimedTx = buildRefundUnclaimedTx;
4527
4641
  exports.buildRejectJobTx = buildRejectJobTx;
4528
4642
  exports.buildReleaseJobTx = buildReleaseJobTx;
4529
4643
  exports.buildRevokeLeafTx = buildRevokeLeafTx;
@@ -4541,7 +4655,6 @@ exports.classifyLabel = classifyLabel;
4541
4655
  exports.classifyTransaction = classifyTransaction;
4542
4656
  exports.clearLimits = clearLimits;
4543
4657
  exports.composeTx = composeTx;
4544
- exports.createOpenJob = createOpenJob;
4545
4658
  exports.dailySpentToday = dailySpentToday;
4546
4659
  exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
4547
4660
  exports.deserializeCetusRoute = deserializeCetusRoute;
@@ -4560,7 +4673,6 @@ exports.formatAssetAmount = formatAssetAmount;
4560
4673
  exports.formatSui = formatSui;
4561
4674
  exports.formatUsd = formatUsd;
4562
4675
  exports.fullHandle = fullHandle;
4563
- exports.fundOpenJob = fundOpenJob;
4564
4676
  exports.generateKeypair = generateKeypair;
4565
4677
  exports.getAddress = getAddress;
4566
4678
  exports.getCoinMeta = getCoinMeta;
@@ -4570,6 +4682,7 @@ exports.getJob = getJob;
4570
4682
  exports.getJobSpec = getJobSpec;
4571
4683
  exports.getLimits = getLimits;
4572
4684
  exports.getOpenJob = getOpenJob;
4685
+ exports.getOpening = getOpening;
4573
4686
  exports.getSponsoredSwapProviders = getSponsoredSwapProviders;
4574
4687
  exports.getSuiClient = getSuiClient;
4575
4688
  exports.getSuiGrpcClient = getSuiGrpcClient;
@@ -4594,7 +4707,9 @@ exports.normalizeCoinType = normalizeCoinType;
4594
4707
  exports.parseMppSuiChallenge = parseMppSuiChallenge;
4595
4708
  exports.parseSuiRpcTx = parseSuiRpcTx;
4596
4709
  exports.payWithMpp = payWithMpp;
4710
+ exports.postOpenJob = postOpenJob;
4597
4711
  exports.preflightCreateJob = preflightCreateJob;
4712
+ exports.preflightCreateOpening = preflightCreateOpening;
4598
4713
  exports.preflightFail = preflightFail;
4599
4714
  exports.preflightPay = preflightPay;
4600
4715
  exports.preflightSend = preflightSend;
@@ -4608,6 +4723,7 @@ exports.rawToUsdc = rawToUsdc;
4608
4723
  exports.readLimitsFile = readLimitsFile;
4609
4724
  exports.recordDailySpend = recordDailySpend;
4610
4725
  exports.refineLendingLabel = refineLendingLabel;
4726
+ exports.refundOpenJob = refundOpenJob;
4611
4727
  exports.resolveAddressToSuinsViaRpc = resolveAddressToSuinsViaRpc;
4612
4728
  exports.resolveSuinsViaRpc = resolveSuinsViaRpc;
4613
4729
  exports.resolveSymbol = resolveSymbol;
@@ -4623,7 +4739,6 @@ exports.stableToRaw = stableToRaw;
4623
4739
  exports.suiToMist = suiToMist;
4624
4740
  exports.throwIfSimulationFailed = throwIfSimulationFailed;
4625
4741
  exports.truncateAddress = truncateAddress;
4626
- exports.unclaimOpenJob = unclaimOpenJob;
4627
4742
  exports.usdcToRaw = usdcToRaw;
4628
4743
  exports.validateAddress = validateAddress;
4629
4744
  exports.validateAgentCoinParams = validateAgentCoinParams;