@t2000/sdk 10.15.0 → 10.16.0
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/browser.cjs +8 -0
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +8 -0
- package/dist/browser.js.map +1 -1
- package/dist/{commerce-C4D3VxBu.d.cts → commerce-BkSSPS1w.d.cts} +6 -1
- package/dist/{commerce-C4D3VxBu.d.ts → commerce-BkSSPS1w.d.ts} +6 -1
- package/dist/index.cjs +168 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +168 -157
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1451,6 +1451,11 @@ declare function buildCreateJobTx({ client, buyer, terms, }: {
|
|
|
1451
1451
|
buyer: string;
|
|
1452
1452
|
terms: JobTerms;
|
|
1453
1453
|
}): Promise<Transaction>;
|
|
1454
|
+
/** Seller's pre-delivery abort (SPEC_T2_AGENTS_TRUST §B): FUNDED only →
|
|
1455
|
+
* full fee-free refund to the buyer, terminal state REFUNDED (the
|
|
1456
|
+
* JobDeclined event is what distinguishes a decline from a deadline
|
|
1457
|
+
* refund). Targets the latest package id — `decline` shipped in v3. */
|
|
1458
|
+
declare function buildDeclineJobTx(jobId: string): Transaction;
|
|
1454
1459
|
/** Seller posts the delivery commitment (hex hash) before the deadline. */
|
|
1455
1460
|
declare function buildDeliverJobTx(jobId: string, deliveryHash: string): Transaction;
|
|
1456
1461
|
/** Buyer accepts (or anyone, once the review window lapsed) → funds to seller. */
|
|
@@ -1538,4 +1543,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1538
1543
|
* the store is untrusted; the chain hash is the authority). */
|
|
1539
1544
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1540
1545
|
|
|
1541
|
-
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9,
|
|
1546
|
+
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9, queryTransaction as bA, selectAndSplitCoin as bB, selectSuiCoin as bC, serializeCetusRoute as bD, simulateTransaction as bE, throwIfSimulationFailed as bF, verifyCetusRouteCoinMatch as bG, DEFAULT_GRPC_URL as ba, GASLESS_MIN_STABLE_AMOUNT as bb, GASLESS_STABLE_TYPES as bc, OPERATION_ASSETS as bd, type Operation as be, SENDABLE_ASSETS as bf, type SelectAndSplitResult as bg, type SerializedCetusRoute as bh, type SerializedCetusRoutePath as bi, type SerializedRouterDataV3 as bj, addSendToTx as bk, addSwapToTx as bl, assertAllowedAsset as bm, assertBuyerRequirements as bn, buildDeclineJobTx as bo, deserializeCetusRoute as bp, fetchAllCoins as bq, getCoinMeta as br, getSuiClient as bs, getSuiGrpcClient as bt, isAllowedAsset as bu, isCetusRouteFresh as bv, isInRegistry as bw, normalizeAsset as bx, normalizeCoinType as by, queryHistory as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OverlayFeeConfig as s, PREFLIGHT_OK as t, type PayOptions as u, type PayResult as v, type PreflightResult as w, SUI_DECIMALS as x, SUI_TYPE as y, SUPPORTED_ASSETS as z };
|
|
@@ -1451,6 +1451,11 @@ declare function buildCreateJobTx({ client, buyer, terms, }: {
|
|
|
1451
1451
|
buyer: string;
|
|
1452
1452
|
terms: JobTerms;
|
|
1453
1453
|
}): Promise<Transaction>;
|
|
1454
|
+
/** Seller's pre-delivery abort (SPEC_T2_AGENTS_TRUST §B): FUNDED only →
|
|
1455
|
+
* full fee-free refund to the buyer, terminal state REFUNDED (the
|
|
1456
|
+
* JobDeclined event is what distinguishes a decline from a deadline
|
|
1457
|
+
* refund). Targets the latest package id — `decline` shipped in v3. */
|
|
1458
|
+
declare function buildDeclineJobTx(jobId: string): Transaction;
|
|
1454
1459
|
/** Seller posts the delivery commitment (hex hash) before the deadline. */
|
|
1455
1460
|
declare function buildDeliverJobTx(jobId: string, deliveryHash: string): Transaction;
|
|
1456
1461
|
/** Buyer accepts (or anyone, once the review window lapsed) → funds to seller. */
|
|
@@ -1538,4 +1543,4 @@ declare function putJobSpec(base: string, content: string): Promise<string>;
|
|
|
1538
1543
|
* the store is untrusted; the chain hash is the authority). */
|
|
1539
1544
|
declare function getJobSpec(base: string, hash: string): Promise<string>;
|
|
1540
1545
|
|
|
1541
|
-
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9,
|
|
1546
|
+
export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, type SendResult as F, GAS_RESERVE_MIN as G, type ServiceListing as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listServices as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchService as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9, queryTransaction as bA, selectAndSplitCoin as bB, selectSuiCoin as bC, serializeCetusRoute as bD, simulateTransaction as bE, throwIfSimulationFailed as bF, verifyCetusRouteCoinMatch as bG, DEFAULT_GRPC_URL as ba, GASLESS_MIN_STABLE_AMOUNT as bb, GASLESS_STABLE_TYPES as bc, OPERATION_ASSETS as bd, type Operation as be, SENDABLE_ASSETS as bf, type SelectAndSplitResult as bg, type SerializedCetusRoute as bh, type SerializedCetusRoutePath as bi, type SerializedRouterDataV3 as bj, addSendToTx as bk, addSwapToTx as bl, assertAllowedAsset as bm, assertBuyerRequirements as bn, buildDeclineJobTx as bo, deserializeCetusRoute as bp, fetchAllCoins as bq, getCoinMeta as br, getSuiClient as bs, getSuiGrpcClient as bt, isAllowedAsset as bu, isCetusRouteFresh as bv, isInRegistry as bw, normalizeAsset as bx, normalizeCoinType as by, queryHistory as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OverlayFeeConfig as s, PREFLIGHT_OK as t, type PayOptions as u, type PayResult as v, type PreflightResult as w, SUI_DECIMALS as x, SUI_TYPE as y, SUPPORTED_ASSETS as z };
|
package/dist/index.cjs
CHANGED
|
@@ -3199,14 +3199,153 @@ init_errors();
|
|
|
3199
3199
|
init_token_registry();
|
|
3200
3200
|
init_preflight();
|
|
3201
3201
|
init_coinSelection();
|
|
3202
|
+
|
|
3203
|
+
// src/wallet/opening.ts
|
|
3204
|
+
init_errors();
|
|
3205
|
+
init_token_registry();
|
|
3206
|
+
init_coinSelection();
|
|
3207
|
+
var A2A_ESCROW_OPENING_PACKAGE_ID = process.env.A2A_ESCROW_OPENING_PACKAGE_ID ?? "0x69ad93c555519de520a5c7f7f2963ad6f8b91cefc098fc2eed75942dcb5bcbe7";
|
|
3208
|
+
var CLOCK_ID2 = "0x6";
|
|
3209
|
+
var MODULE = "opening";
|
|
3210
|
+
var SHA256_HEX_RE = /^(0x)?[0-9a-fA-F]{64}$/;
|
|
3211
|
+
var OPENING_CLAIM_POLICY_ANY_ACTIVE = 0;
|
|
3212
|
+
var MAX_OPEN_WINDOW_MS = 2592e6;
|
|
3213
|
+
function feeConfigArg(tx) {
|
|
3214
|
+
return tx.sharedObjectRef({
|
|
3215
|
+
objectId: A2A_ESCROW_FEE_CONFIG_ID,
|
|
3216
|
+
initialSharedVersion: A2A_ESCROW_FEE_CONFIG_VERSION,
|
|
3217
|
+
mutable: false
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
function hexToBytes2(hex) {
|
|
3221
|
+
const clean = hex.replace(/^0x/, "");
|
|
3222
|
+
const bytes = [];
|
|
3223
|
+
for (let i = 0; i < clean.length; i += 2) {
|
|
3224
|
+
bytes.push(Number.parseInt(clean.slice(i, i + 2), 16));
|
|
3225
|
+
}
|
|
3226
|
+
return bytes;
|
|
3227
|
+
}
|
|
3228
|
+
function preflightCreateOpening(terms) {
|
|
3229
|
+
if (!Number.isFinite(terms.amountUsdc) || terms.amountUsdc <= 0) {
|
|
3230
|
+
return { valid: false, code: "INVALID_AMOUNT", error: "Budget must be positive." };
|
|
3231
|
+
}
|
|
3232
|
+
if (terms.amountUsdc > MAX_JOB_USDC) {
|
|
3233
|
+
return {
|
|
3234
|
+
valid: false,
|
|
3235
|
+
code: "INVALID_AMOUNT",
|
|
3236
|
+
error: `Open jobs cap at ${MAX_JOB_USDC} USDC (v1).`
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
if (!SHA256_HEX_RE.test(terms.specHash)) {
|
|
3240
|
+
return { valid: false, code: "INVALID_INPUT", error: "specHash must be a sha256 hex string." };
|
|
3241
|
+
}
|
|
3242
|
+
const now = Date.now();
|
|
3243
|
+
if (terms.openUntilMs <= now) {
|
|
3244
|
+
return { valid: false, code: "INVALID_INPUT", error: "openUntil must be in the future." };
|
|
3245
|
+
}
|
|
3246
|
+
if (terms.openUntilMs > now + MAX_OPEN_WINDOW_MS) {
|
|
3247
|
+
return { valid: false, code: "INVALID_INPUT", error: "Openings can stay claimable at most 30 days." };
|
|
3248
|
+
}
|
|
3249
|
+
if (terms.slaMs <= 0) {
|
|
3250
|
+
return { valid: false, code: "INVALID_INPUT", error: "Delivery window must be positive." };
|
|
3251
|
+
}
|
|
3252
|
+
return { valid: true };
|
|
3253
|
+
}
|
|
3254
|
+
async function buildCreateOpeningTx({
|
|
3255
|
+
client,
|
|
3256
|
+
buyer,
|
|
3257
|
+
terms
|
|
3258
|
+
}) {
|
|
3259
|
+
const pf = preflightCreateOpening(terms);
|
|
3260
|
+
if (!pf.valid) throw new exports.T2000Error(pf.code ?? "INVALID_INPUT", pf.error ?? "Invalid opening.");
|
|
3261
|
+
const rawAmount = BigInt(Math.floor(terms.amountUsdc * 10 ** USDC_DECIMALS));
|
|
3262
|
+
const tx = new transactions.Transaction();
|
|
3263
|
+
const { coin } = await selectAndSplitCoin(tx, client, validateAddress(buyer), exports.USDC_TYPE, rawAmount, {
|
|
3264
|
+
allowSwapAll: false
|
|
3265
|
+
});
|
|
3266
|
+
tx.moveCall({
|
|
3267
|
+
target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE}::create_open`,
|
|
3268
|
+
typeArguments: [exports.USDC_TYPE],
|
|
3269
|
+
arguments: [
|
|
3270
|
+
coin,
|
|
3271
|
+
tx.pure.vector("u8", hexToBytes2(terms.specHash)),
|
|
3272
|
+
tx.pure.u64(terms.openUntilMs),
|
|
3273
|
+
tx.pure.u64(terms.slaMs),
|
|
3274
|
+
tx.pure.u64(terms.reviewWindowMs),
|
|
3275
|
+
tx.pure.u64(terms.rejectSplitBps),
|
|
3276
|
+
tx.pure.u8(OPENING_CLAIM_POLICY_ANY_ACTIVE),
|
|
3277
|
+
feeConfigArg(tx),
|
|
3278
|
+
tx.object(CLOCK_ID2)
|
|
3279
|
+
]
|
|
3280
|
+
});
|
|
3281
|
+
return tx;
|
|
3282
|
+
}
|
|
3283
|
+
function buildClaimOpeningTx({
|
|
3284
|
+
openingId,
|
|
3285
|
+
registryId
|
|
3286
|
+
}) {
|
|
3287
|
+
const tx = new transactions.Transaction();
|
|
3288
|
+
tx.moveCall({
|
|
3289
|
+
target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE}::claim`,
|
|
3290
|
+
typeArguments: [exports.USDC_TYPE],
|
|
3291
|
+
arguments: [
|
|
3292
|
+
tx.object(openingId),
|
|
3293
|
+
tx.object(registryId),
|
|
3294
|
+
feeConfigArg(tx),
|
|
3295
|
+
tx.object(CLOCK_ID2)
|
|
3296
|
+
]
|
|
3297
|
+
});
|
|
3298
|
+
return tx;
|
|
3299
|
+
}
|
|
3300
|
+
function openingCall(openingId, fn) {
|
|
3301
|
+
const tx = new transactions.Transaction();
|
|
3302
|
+
tx.moveCall({
|
|
3303
|
+
target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE}::${fn}`,
|
|
3304
|
+
typeArguments: [exports.USDC_TYPE],
|
|
3305
|
+
arguments: [tx.object(openingId), feeConfigArg(tx), tx.object(CLOCK_ID2)]
|
|
3306
|
+
});
|
|
3307
|
+
return tx;
|
|
3308
|
+
}
|
|
3309
|
+
function buildCancelOpeningTx(openingId) {
|
|
3310
|
+
return openingCall(openingId, "cancel_open");
|
|
3311
|
+
}
|
|
3312
|
+
function buildRefundUnclaimedTx(openingId) {
|
|
3313
|
+
return openingCall(openingId, "refund_unclaimed");
|
|
3314
|
+
}
|
|
3315
|
+
function bytesToHex2(bytes) {
|
|
3316
|
+
return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
3317
|
+
}
|
|
3318
|
+
async function getOpening(client, openingId) {
|
|
3319
|
+
const resp = await client.core.getObject({ objectId: openingId, include: { json: true } }).catch(() => null);
|
|
3320
|
+
const objType = resp?.object?.type ?? "";
|
|
3321
|
+
const json = resp?.object?.json;
|
|
3322
|
+
if (!json || !objType.includes(`::${MODULE}::Opening<`)) {
|
|
3323
|
+
return null;
|
|
3324
|
+
}
|
|
3325
|
+
return {
|
|
3326
|
+
id: openingId,
|
|
3327
|
+
buyer: String(json.buyer),
|
|
3328
|
+
amountUsdc: Number(json.amount) / 10 ** USDC_DECIMALS,
|
|
3329
|
+
feeBps: Number(json.fee_bps ?? 0),
|
|
3330
|
+
specHash: bytesToHex2(json.spec_hash ?? []),
|
|
3331
|
+
openUntilMs: Number(json.open_until_ms),
|
|
3332
|
+
slaMs: Number(json.sla_ms),
|
|
3333
|
+
reviewWindowMs: Number(json.review_window_ms),
|
|
3334
|
+
rejectSplitBps: Number(json.reject_split_bps),
|
|
3335
|
+
claimPolicy: Number(json.claim_policy ?? 0),
|
|
3336
|
+
createdAtMs: Number(json.created_at_ms ?? 0)
|
|
3337
|
+
};
|
|
3338
|
+
}
|
|
3339
|
+
|
|
3340
|
+
// src/wallet/job.ts
|
|
3202
3341
|
var A2A_ESCROW_PACKAGE_ID = process.env.A2A_ESCROW_PACKAGE_ID ?? "0x358a819c1c016e2cc84ef5fbea81cba90c31f7f8a62bf45cb5e5276acf198bdd";
|
|
3203
3342
|
var A2A_ESCROW_FEE_CONFIG_ID = process.env.A2A_ESCROW_FEE_CONFIG_ID ?? "0xddaa25570950b7484dbf20797ebcf75707be9c87cd67bef2a06ed2e81d2c494b";
|
|
3204
3343
|
var A2A_ESCROW_FEE_CONFIG_VERSION = Number(
|
|
3205
3344
|
process.env.A2A_ESCROW_FEE_CONFIG_VERSION ?? 931861903
|
|
3206
3345
|
);
|
|
3207
|
-
var
|
|
3208
|
-
var
|
|
3209
|
-
function
|
|
3346
|
+
var CLOCK_ID3 = "0x6";
|
|
3347
|
+
var MODULE2 = "escrow";
|
|
3348
|
+
function feeConfigArg2(tx) {
|
|
3210
3349
|
return tx.sharedObjectRef({
|
|
3211
3350
|
objectId: A2A_ESCROW_FEE_CONFIG_ID,
|
|
3212
3351
|
initialSharedVersion: A2A_ESCROW_FEE_CONFIG_VERSION,
|
|
@@ -3223,7 +3362,7 @@ var JOB_STATES = [
|
|
|
3223
3362
|
"refunded",
|
|
3224
3363
|
"rejected"
|
|
3225
3364
|
];
|
|
3226
|
-
function
|
|
3365
|
+
function hexToBytes3(hex) {
|
|
3227
3366
|
const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
3228
3367
|
if (clean.length === 0 || clean.length % 2 !== 0 || /[^0-9a-fA-F]/.test(clean)) {
|
|
3229
3368
|
throw new exports.T2000Error(
|
|
@@ -3237,7 +3376,7 @@ function hexToBytes2(hex) {
|
|
|
3237
3376
|
}
|
|
3238
3377
|
return out;
|
|
3239
3378
|
}
|
|
3240
|
-
function
|
|
3379
|
+
function bytesToHex3(bytes) {
|
|
3241
3380
|
const arr = typeof bytes === "string" ? Array.from(atob(bytes), (c) => c.charCodeAt(0)) : bytes;
|
|
3242
3381
|
let s = "0x";
|
|
3243
3382
|
for (const b of arr) s += b.toString(16).padStart(2, "0");
|
|
@@ -3268,7 +3407,7 @@ function preflightCreateJob(terms) {
|
|
|
3268
3407
|
return preflightFail("INVALID_AMOUNT", "rejectSplitBps must be an integer 0\u201310000.");
|
|
3269
3408
|
}
|
|
3270
3409
|
try {
|
|
3271
|
-
|
|
3410
|
+
hexToBytes3(terms.specHash);
|
|
3272
3411
|
} catch (e) {
|
|
3273
3412
|
return preflightFail("INVALID_AMOUNT", e.message);
|
|
3274
3413
|
}
|
|
@@ -3291,40 +3430,49 @@ async function buildCreateJobTx({
|
|
|
3291
3430
|
allowSwapAll: false
|
|
3292
3431
|
});
|
|
3293
3432
|
tx.moveCall({
|
|
3294
|
-
target: `${A2A_ESCROW_PACKAGE_ID}::${
|
|
3433
|
+
target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE2}::create`,
|
|
3295
3434
|
typeArguments: [exports.USDC_TYPE],
|
|
3296
3435
|
arguments: [
|
|
3297
3436
|
tx.pure.address(seller),
|
|
3298
3437
|
coin,
|
|
3299
|
-
tx.pure.vector("u8",
|
|
3438
|
+
tx.pure.vector("u8", hexToBytes3(terms.specHash)),
|
|
3300
3439
|
tx.pure.u64(terms.deliverByMs),
|
|
3301
3440
|
tx.pure.u64(terms.reviewWindowMs),
|
|
3302
3441
|
tx.pure.u64(terms.rejectSplitBps),
|
|
3303
|
-
|
|
3304
|
-
tx.object(
|
|
3442
|
+
feeConfigArg2(tx),
|
|
3443
|
+
tx.object(CLOCK_ID3)
|
|
3305
3444
|
]
|
|
3306
3445
|
});
|
|
3307
3446
|
return tx;
|
|
3308
3447
|
}
|
|
3448
|
+
function buildDeclineJobTx(jobId) {
|
|
3449
|
+
const tx = new transactions.Transaction();
|
|
3450
|
+
tx.moveCall({
|
|
3451
|
+
target: `${A2A_ESCROW_OPENING_PACKAGE_ID}::${MODULE2}::decline`,
|
|
3452
|
+
typeArguments: [exports.USDC_TYPE],
|
|
3453
|
+
arguments: [tx.object(jobId), feeConfigArg2(tx), tx.object(CLOCK_ID3)]
|
|
3454
|
+
});
|
|
3455
|
+
return tx;
|
|
3456
|
+
}
|
|
3309
3457
|
function jobCall(jobId, fn) {
|
|
3310
3458
|
const tx = new transactions.Transaction();
|
|
3311
3459
|
tx.moveCall({
|
|
3312
|
-
target: `${A2A_ESCROW_PACKAGE_ID}::${
|
|
3460
|
+
target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE2}::${fn}`,
|
|
3313
3461
|
typeArguments: [exports.USDC_TYPE],
|
|
3314
|
-
arguments: [tx.object(jobId),
|
|
3462
|
+
arguments: [tx.object(jobId), feeConfigArg2(tx), tx.object(CLOCK_ID3)]
|
|
3315
3463
|
});
|
|
3316
3464
|
return tx;
|
|
3317
3465
|
}
|
|
3318
3466
|
function buildDeliverJobTx(jobId, deliveryHash) {
|
|
3319
3467
|
const tx = new transactions.Transaction();
|
|
3320
3468
|
tx.moveCall({
|
|
3321
|
-
target: `${A2A_ESCROW_PACKAGE_ID}::${
|
|
3469
|
+
target: `${A2A_ESCROW_PACKAGE_ID}::${MODULE2}::deliver`,
|
|
3322
3470
|
typeArguments: [exports.USDC_TYPE],
|
|
3323
3471
|
arguments: [
|
|
3324
3472
|
tx.object(jobId),
|
|
3325
|
-
tx.pure.vector("u8",
|
|
3326
|
-
|
|
3327
|
-
tx.object(
|
|
3473
|
+
tx.pure.vector("u8", hexToBytes3(deliveryHash)),
|
|
3474
|
+
feeConfigArg2(tx),
|
|
3475
|
+
tx.object(CLOCK_ID3)
|
|
3328
3476
|
]
|
|
3329
3477
|
});
|
|
3330
3478
|
return tx;
|
|
@@ -3347,7 +3495,7 @@ async function getJob(client, jobId) {
|
|
|
3347
3495
|
});
|
|
3348
3496
|
const objType = resp.object?.type ?? "";
|
|
3349
3497
|
const json = resp.object?.json;
|
|
3350
|
-
if (!json || !objType.includes(`::${
|
|
3498
|
+
if (!json || !objType.includes(`::${MODULE2}::Job<`)) {
|
|
3351
3499
|
throw new exports.T2000Error("RPC_ERROR", `Object ${jobId} is not an a2a_escrow Job.`);
|
|
3352
3500
|
}
|
|
3353
3501
|
const stateNum = Number(json.state ?? -1);
|
|
@@ -3365,12 +3513,12 @@ async function getJob(client, jobId) {
|
|
|
3365
3513
|
amountUsdc: Number(json.amount) / 10 ** USDC_DECIMALS,
|
|
3366
3514
|
escrowUsdc: Number(json.escrow) / 10 ** USDC_DECIMALS,
|
|
3367
3515
|
feeBps: Number(json.fee_bps ?? 0),
|
|
3368
|
-
specHash:
|
|
3516
|
+
specHash: bytesToHex3(json.spec_hash ?? []),
|
|
3369
3517
|
deliverByMs: Number(json.deliver_by_ms),
|
|
3370
3518
|
reviewWindowMs: Number(json.review_window_ms),
|
|
3371
3519
|
rejectSplitBps: Number(json.reject_split_bps),
|
|
3372
3520
|
state,
|
|
3373
|
-
deliveryHash: hasDelivery ?
|
|
3521
|
+
deliveryHash: hasDelivery ? bytesToHex3(deliveryBytes) : null,
|
|
3374
3522
|
deliveredAtMs: hasDelivery ? deliveredAtMs : null,
|
|
3375
3523
|
createdAtMs: Number(json.created_at_ms)
|
|
3376
3524
|
};
|
|
@@ -3415,143 +3563,6 @@ async function verifyJobForSeller({
|
|
|
3415
3563
|
return { ok: problems.length === 0, job, problems };
|
|
3416
3564
|
}
|
|
3417
3565
|
|
|
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
|
-
|
|
3555
3566
|
// src/commerce.ts
|
|
3556
3567
|
var DEFAULT_COMMERCE_API_BASE = "https://api.t2000.ai/v1";
|
|
3557
3568
|
async function commerceFetchJson(url, init) {
|
|
@@ -4633,6 +4644,7 @@ exports.buildCancelOpeningTx = buildCancelOpeningTx;
|
|
|
4633
4644
|
exports.buildClaimOpeningTx = buildClaimOpeningTx;
|
|
4634
4645
|
exports.buildCreateJobTx = buildCreateJobTx;
|
|
4635
4646
|
exports.buildCreateOpeningTx = buildCreateOpeningTx;
|
|
4647
|
+
exports.buildDeclineJobTx = buildDeclineJobTx;
|
|
4636
4648
|
exports.buildDeliverJobTx = buildDeliverJobTx;
|
|
4637
4649
|
exports.buildDirectPoolSwapTx = buildDirectPoolSwapTx;
|
|
4638
4650
|
exports.buildPublishAgentCoinTx = buildPublishAgentCoinTx;
|