@t2000/cli 9.6.0 → 9.7.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.
@@ -11938,6 +11938,206 @@ var T2000 = class _T2000 extends import_index.default {
11938
11938
  }
11939
11939
  };
11940
11940
  init_errors();
11941
+ init_errors();
11942
+ init_token_registry();
11943
+ init_preflight();
11944
+ init_coinSelection();
11945
+ var A2A_ESCROW_PACKAGE_ID = process.env.A2A_ESCROW_PACKAGE_ID ?? "0x9e67c380fb7079d793d6d15ff916b24d82779d7119bfa4631863102ed485c0a0";
11946
+ var CLOCK_ID2 = "0x6";
11947
+ var MODULE = "escrow";
11948
+ var MAX_JOB_USDC = 50;
11949
+ var JOB_STATES = [
11950
+ "funded",
11951
+ "delivered",
11952
+ "released",
11953
+ "refunded",
11954
+ "rejected"
11955
+ ];
11956
+ function hexToBytes22(hex) {
11957
+ const clean3 = hex.startsWith("0x") ? hex.slice(2) : hex;
11958
+ if (clean3.length === 0 || clean3.length % 2 !== 0 || /[^0-9a-fA-F]/.test(clean3)) {
11959
+ throw new T2000Error(
11960
+ "INVALID_AMOUNT",
11961
+ `Expected a hex hash (0x\u2026), got "${hex.slice(0, 32)}"`
11962
+ );
11963
+ }
11964
+ const out = [];
11965
+ for (let i = 0; i < clean3.length; i += 2) {
11966
+ out.push(Number.parseInt(clean3.slice(i, i + 2), 16));
11967
+ }
11968
+ return out;
11969
+ }
11970
+ function bytesToHex22(bytes) {
11971
+ const arr = typeof bytes === "string" ? Array.from(atob(bytes), (c) => c.charCodeAt(0)) : bytes;
11972
+ let s = "0x";
11973
+ for (const b of arr) s += b.toString(16).padStart(2, "0");
11974
+ return s;
11975
+ }
11976
+ function preflightCreateJob(terms) {
11977
+ const addressCheck = checkSuiAddress(terms.seller);
11978
+ if (!addressCheck.valid) return addressCheck;
11979
+ if (!Number.isFinite(terms.amountUsdc) || terms.amountUsdc <= 0) {
11980
+ return preflightFail("INVALID_AMOUNT", `Amount must be positive. Got ${terms.amountUsdc}.`);
11981
+ }
11982
+ if (terms.amountUsdc > MAX_JOB_USDC) {
11983
+ return preflightFail(
11984
+ "INVALID_AMOUNT",
11985
+ `v1 caps escrow jobs at ${MAX_JOB_USDC} USDC (no-arbitration split only stays fair at small sizes). Got ${terms.amountUsdc}.`
11986
+ );
11987
+ }
11988
+ if (terms.deliverByMs <= Date.now()) {
11989
+ return preflightFail("INVALID_AMOUNT", "deliverByMs must be in the future.");
11990
+ }
11991
+ if (terms.reviewWindowMs < 0) {
11992
+ return preflightFail("INVALID_AMOUNT", "reviewWindowMs must be \u2265 0.");
11993
+ }
11994
+ if (!Number.isInteger(terms.rejectSplitBps) || terms.rejectSplitBps < 0 || terms.rejectSplitBps > 1e4) {
11995
+ return preflightFail("INVALID_AMOUNT", "rejectSplitBps must be an integer 0\u201310000.");
11996
+ }
11997
+ try {
11998
+ hexToBytes22(terms.specHash);
11999
+ } catch (e) {
12000
+ return preflightFail("INVALID_AMOUNT", e.message);
12001
+ }
12002
+ return PREFLIGHT_OK;
12003
+ }
12004
+ async function buildCreateJobTx({
12005
+ client,
12006
+ buyer,
12007
+ terms
12008
+ }) {
12009
+ const pf = preflightCreateJob(terms);
12010
+ if (!pf.valid) throw new T2000Error(pf.code, pf.error);
12011
+ const seller = validateAddress(terms.seller);
12012
+ if (seller === validateAddress(buyer)) {
12013
+ throw new T2000Error("INVALID_ADDRESS", "Buyer and seller must be different wallets.");
12014
+ }
12015
+ const rawAmount = BigInt(Math.floor(terms.amountUsdc * 10 ** USDC_DECIMALS));
12016
+ const tx = new Transaction();
12017
+ const { coin } = await selectAndSplitCoin(tx, client, buyer, USDC_TYPE, rawAmount, {
12018
+ allowSwapAll: false
12019
+ });
12020
+ tx.moveCall({
12021
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::create`,
12022
+ typeArguments: [USDC_TYPE],
12023
+ arguments: [
12024
+ tx.pure.address(seller),
12025
+ coin,
12026
+ tx.pure.vector("u8", hexToBytes22(terms.specHash)),
12027
+ tx.pure.u64(terms.deliverByMs),
12028
+ tx.pure.u64(terms.reviewWindowMs),
12029
+ tx.pure.u64(terms.rejectSplitBps),
12030
+ tx.object(CLOCK_ID2)
12031
+ ]
12032
+ });
12033
+ return tx;
12034
+ }
12035
+ function jobCall(jobId, fn) {
12036
+ const tx = new Transaction();
12037
+ tx.moveCall({
12038
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::${fn}`,
12039
+ typeArguments: [USDC_TYPE],
12040
+ arguments: [tx.object(jobId), tx.object(CLOCK_ID2)]
12041
+ });
12042
+ return tx;
12043
+ }
12044
+ function buildDeliverJobTx(jobId, deliveryHash) {
12045
+ const tx = new Transaction();
12046
+ tx.moveCall({
12047
+ target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE}::deliver`,
12048
+ typeArguments: [USDC_TYPE],
12049
+ arguments: [
12050
+ tx.object(jobId),
12051
+ tx.pure.vector("u8", hexToBytes22(deliveryHash)),
12052
+ tx.object(CLOCK_ID2)
12053
+ ]
12054
+ });
12055
+ return tx;
12056
+ }
12057
+ function buildReleaseJobTx(jobId) {
12058
+ return jobCall(jobId, "release");
12059
+ }
12060
+ function buildRejectJobTx(jobId) {
12061
+ return jobCall(jobId, "reject");
12062
+ }
12063
+ function buildRefundJobTx(jobId) {
12064
+ return jobCall(jobId, "refund");
12065
+ }
12066
+ async function getJob(client, jobId) {
12067
+ const resp = await client.core.getObject({ objectId: jobId, include: { json: true } }).catch((e) => {
12068
+ throw new T2000Error(
12069
+ "RPC_ERROR",
12070
+ `Job ${jobId} not found: ${e instanceof Error ? e.message : String(e)}`
12071
+ );
12072
+ });
12073
+ const objType = resp.object?.type ?? "";
12074
+ const json = resp.object?.json;
12075
+ if (!json || !objType.includes(`::${MODULE}::Job<`)) {
12076
+ throw new T2000Error("RPC_ERROR", `Object ${jobId} is not an a2a_escrow Job.`);
12077
+ }
12078
+ const stateNum = Number(json.state ?? -1);
12079
+ const state = JOB_STATES[stateNum];
12080
+ if (!state) {
12081
+ throw new T2000Error("RPC_ERROR", `Job ${jobId} has unknown state ${stateNum}.`);
12082
+ }
12083
+ const deliveredAtMs = Number(json.delivered_at_ms ?? 0);
12084
+ const deliveryBytes = json.delivery_hash ?? [];
12085
+ const hasDelivery = deliveredAtMs > 0;
12086
+ return {
12087
+ id: jobId,
12088
+ buyer: String(json.buyer),
12089
+ seller: String(json.seller),
12090
+ amountUsdc: Number(json.amount) / 10 ** USDC_DECIMALS,
12091
+ escrowUsdc: Number(json.escrow) / 10 ** USDC_DECIMALS,
12092
+ specHash: bytesToHex22(json.spec_hash ?? []),
12093
+ deliverByMs: Number(json.deliver_by_ms),
12094
+ reviewWindowMs: Number(json.review_window_ms),
12095
+ rejectSplitBps: Number(json.reject_split_bps),
12096
+ state,
12097
+ deliveryHash: hasDelivery ? bytesToHex22(deliveryBytes) : null,
12098
+ deliveredAtMs: hasDelivery ? deliveredAtMs : null,
12099
+ createdAtMs: Number(json.created_at_ms)
12100
+ };
12101
+ }
12102
+ function jobActionsFor(job, caller, nowMs = Date.now()) {
12103
+ const me = validateAddress(caller);
12104
+ const isBuyer = me === job.buyer;
12105
+ const isSeller = me === job.seller;
12106
+ const actions = [];
12107
+ if (job.state === "funded") {
12108
+ if (isSeller && nowMs <= job.deliverByMs) actions.push("deliver");
12109
+ if (isBuyer) actions.push("release");
12110
+ if (nowMs > job.deliverByMs) actions.push("refund");
12111
+ } else if (job.state === "delivered") {
12112
+ const windowClosesMs = (job.deliveredAtMs ?? 0) + job.reviewWindowMs;
12113
+ if (isBuyer && nowMs <= windowClosesMs) actions.push("release", "reject");
12114
+ if (nowMs > windowClosesMs) actions.push("release");
12115
+ }
12116
+ return actions;
12117
+ }
12118
+ async function verifyJobForSeller({
12119
+ client,
12120
+ jobId,
12121
+ seller,
12122
+ minAmountUsdc,
12123
+ minRunwayMs = 6e4
12124
+ }) {
12125
+ const job = await getJob(client, jobId);
12126
+ const problems = [];
12127
+ if (job.state !== "funded") {
12128
+ problems.push(`state is "${job.state}", expected "funded"`);
12129
+ }
12130
+ if (job.seller !== validateAddress(seller)) {
12131
+ problems.push(`job pays ${job.seller}, not this seller`);
12132
+ }
12133
+ if (job.escrowUsdc < minAmountUsdc) {
12134
+ problems.push(`escrow holds ${job.escrowUsdc} USDC, price is ${minAmountUsdc}`);
12135
+ }
12136
+ if (job.deliverByMs - Date.now() < minRunwayMs) {
12137
+ problems.push("deadline too close to accept");
12138
+ }
12139
+ return { ok: problems.length === 0, job, problems };
12140
+ }
11941
12141
  init_coinSelection();
11942
12142
  init_cetus_swap();
11943
12143
  init_coinSelection();
@@ -12487,6 +12687,18 @@ export {
12487
12687
  assertLimitConfig,
12488
12688
  LimitEnforcer,
12489
12689
  T2000,
12690
+ A2A_ESCROW_PACKAGE_ID,
12691
+ MAX_JOB_USDC,
12692
+ JOB_STATES,
12693
+ preflightCreateJob,
12694
+ buildCreateJobTx,
12695
+ buildDeliverJobTx,
12696
+ buildReleaseJobTx,
12697
+ buildRejectJobTx,
12698
+ buildRefundJobTx,
12699
+ getJob,
12700
+ jobActionsFor,
12701
+ verifyJobForSeller,
12490
12702
  SPONSORED_PYTH_DEPENDENT_PROVIDERS,
12491
12703
  getSponsoredSwapProviders,
12492
12704
  WRITE_APPENDER_REGISTRY,
@@ -12526,4 +12738,4 @@ export {
12526
12738
  @scure/bip39/index.js:
12527
12739
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
12528
12740
  */
12529
- //# sourceMappingURL=chunk-UGQY67E3.js.map
12741
+ //# sourceMappingURL=chunk-SXB4BX4Y.js.map