@t2000/sdk 5.6.0 → 5.7.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/index.cjs CHANGED
@@ -275,6 +275,7 @@ var init_token_registry = __esm({
275
275
  // src/wallet/coinSelection.ts
276
276
  var coinSelection_exports = {};
277
277
  __export(coinSelection_exports, {
278
+ buildCoinToAddressBalanceMigration: () => buildCoinToAddressBalanceMigration,
278
279
  fetchAllCoins: () => fetchAllCoins,
279
280
  selectAndSplitCoin: () => selectAndSplitCoin,
280
281
  selectSuiCoin: () => selectSuiCoin
@@ -388,6 +389,32 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
388
389
  });
389
390
  return { coin, effectiveAmount, swapAll };
390
391
  }
392
+ function buildCoinToAddressBalanceMigration(args) {
393
+ const { coins, coinType, owner, minAmount } = args;
394
+ const sorted = [...coins].filter((c) => c.balance > 0n).sort((a, b) => b.balance > a.balance ? 1 : b.balance < a.balance ? -1 : 0);
395
+ const selected = [];
396
+ let migratedRaw = 0n;
397
+ for (const c of sorted) {
398
+ if (migratedRaw >= minAmount) break;
399
+ selected.push(c);
400
+ migratedRaw += c.balance;
401
+ }
402
+ if (migratedRaw < minAmount) {
403
+ throw new exports.T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
404
+ available: migratedRaw.toString(),
405
+ required: minAmount.toString()
406
+ });
407
+ }
408
+ const tx = new transactions.Transaction();
409
+ for (const c of selected) {
410
+ tx.moveCall({
411
+ target: "0x2::coin::send_funds",
412
+ typeArguments: [coinType],
413
+ arguments: [tx.object(c.objectId), tx.pure.address(owner)]
414
+ });
415
+ }
416
+ return { tx, migratedRaw };
417
+ }
391
418
  async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, mergeCache) {
392
419
  if (sponsoredContext) {
393
420
  const { SUI_TYPE: SUI_TYPE2 } = await Promise.resolve().then(() => (init_token_registry(), token_registry_exports));
@@ -1166,40 +1193,26 @@ async function ensureAddressBalanceCovers(args) {
1166
1193
  required: amountRaw.toString()
1167
1194
  });
1168
1195
  }
1196
+ const coins = [];
1169
1197
  let coinSum = 0n;
1170
1198
  let cursor;
1171
1199
  let hasNext = true;
1172
1200
  while (hasNext) {
1173
1201
  const page = await client.core.listCoins({ owner, coinType: asset, cursor: cursor ?? void 0 });
1174
- for (const c of page.objects) coinSum += BigInt(c.balance);
1202
+ for (const c of page.objects) {
1203
+ coins.push({ objectId: c.objectId, balance: BigInt(c.balance) });
1204
+ coinSum += BigInt(c.balance);
1205
+ }
1175
1206
  cursor = page.cursor;
1176
1207
  hasNext = page.hasNextPage;
1177
1208
  }
1178
1209
  const addressBalance = total - coinSum;
1179
1210
  if (addressBalance >= amountRaw) return 0;
1180
1211
  const shortfall = amountRaw - addressBalance;
1181
- const { Transaction: Transaction6 } = await import('@mysten/sui/transactions');
1182
- const { selectAndSplitCoin: selectAndSplitCoin2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
1212
+ const { buildCoinToAddressBalanceMigration: buildCoinToAddressBalanceMigration2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
1183
1213
  const grpcClient = await makeGrpcBuildClient(client);
1184
- const migration = await executeTx(
1185
- client,
1186
- signer,
1187
- async () => {
1188
- const tx = new Transaction6();
1189
- const { coin } = await selectAndSplitCoin2(tx, client, owner, asset, shortfall, {
1190
- sponsoredContext: true,
1191
- // coin-objects-only — never the address balance
1192
- allowSwapAll: false
1193
- });
1194
- tx.moveCall({
1195
- target: "0x2::coin::send_funds",
1196
- typeArguments: [asset],
1197
- arguments: [coin, tx.pure.address(owner)]
1198
- });
1199
- return tx;
1200
- },
1201
- { buildClient: grpcClient }
1202
- );
1214
+ const { tx } = buildCoinToAddressBalanceMigration2({ coins, coinType: asset, owner, minAmount: shortfall });
1215
+ const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
1203
1216
  return migration.gasCostSui;
1204
1217
  }
1205
1218
  async function finalize(response, opts) {
@@ -2819,6 +2832,16 @@ init_cetus_swap();
2819
2832
  init_token_registry();
2820
2833
  var AUDRIC_PARENT_NAME = "audric.sui";
2821
2834
  var AUDRIC_PARENT_NFT_ID = "0x070456e283ec988b6302bdd6cc5172bbdcb709998cf116586fb98d19b0870198";
2835
+ var AUDRIC_PARENT = {
2836
+ name: AUDRIC_PARENT_NAME,
2837
+ nftId: AUDRIC_PARENT_NFT_ID
2838
+ };
2839
+ var AGENT_ID_PARENT_NAME = "agent-id.sui";
2840
+ var AGENT_ID_PARENT_NFT_ID = process.env.AGENT_ID_PARENT_NFT_ID ?? "0xc8c13f5b5a6d4c47c04877014794f65e67e2745d3bfa089b736eb54b0ebd5d1f";
2841
+ var AGENT_ID_PARENT = {
2842
+ name: AGENT_ID_PARENT_NAME,
2843
+ nftId: AGENT_ID_PARENT_NFT_ID
2844
+ };
2822
2845
  var LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
2823
2846
  function validateLabel(label) {
2824
2847
  if (typeof label !== "string") {
@@ -2841,7 +2864,7 @@ function validateLabel(label) {
2841
2864
  }
2842
2865
  return { valid: true };
2843
2866
  }
2844
- function buildAddLeafTx(suinsClient, { label, targetAddress }) {
2867
+ function buildAddLeafTx(suinsClient, { label, targetAddress, parent = AUDRIC_PARENT }) {
2845
2868
  const labelCheck = validateLabel(label);
2846
2869
  if (!labelCheck.valid) {
2847
2870
  throw new Error(`buildAddLeafTx: invalid label "${label}" \u2014 ${labelCheck.reason}`);
@@ -2849,39 +2872,49 @@ function buildAddLeafTx(suinsClient, { label, targetAddress }) {
2849
2872
  if (typeof targetAddress !== "string" || !utils.isValidSuiAddress(utils.normalizeSuiAddress(targetAddress))) {
2850
2873
  throw new Error(`buildAddLeafTx: invalid targetAddress "${targetAddress}"`);
2851
2874
  }
2875
+ if (!parent.nftId) {
2876
+ throw new Error(`buildAddLeafTx: parent NFT id not configured for "${parent.name}"`);
2877
+ }
2852
2878
  const tx = new transactions.Transaction();
2853
2879
  const suinsTx = new suins.SuinsTransaction(suinsClient, tx);
2854
2880
  suinsTx.createLeafSubName({
2855
- parentNft: AUDRIC_PARENT_NFT_ID,
2856
- name: `${label}.${AUDRIC_PARENT_NAME}`,
2881
+ parentNft: parent.nftId,
2882
+ name: `${label}.${parent.name}`,
2857
2883
  targetAddress: utils.normalizeSuiAddress(targetAddress)
2858
2884
  });
2859
2885
  return tx;
2860
2886
  }
2861
- function buildRevokeLeafTx(suinsClient, { label }) {
2887
+ function buildRevokeLeafTx(suinsClient, { label, parent = AUDRIC_PARENT }) {
2862
2888
  const labelCheck = validateLabel(label);
2863
2889
  if (!labelCheck.valid) {
2864
2890
  throw new Error(`buildRevokeLeafTx: invalid label "${label}" \u2014 ${labelCheck.reason}`);
2865
2891
  }
2892
+ if (!parent.nftId) {
2893
+ throw new Error(`buildRevokeLeafTx: parent NFT id not configured for "${parent.name}"`);
2894
+ }
2866
2895
  const tx = new transactions.Transaction();
2867
2896
  const suinsTx = new suins.SuinsTransaction(suinsClient, tx);
2868
2897
  suinsTx.removeLeafSubName({
2869
- parentNft: AUDRIC_PARENT_NFT_ID,
2870
- name: `${label}.${AUDRIC_PARENT_NAME}`
2898
+ parentNft: parent.nftId,
2899
+ name: `${label}.${parent.name}`
2871
2900
  });
2872
2901
  return tx;
2873
2902
  }
2874
- function fullHandle(label) {
2875
- return `${label}.${AUDRIC_PARENT_NAME}`;
2903
+ function fullHandle(label, parentName = AUDRIC_PARENT_NAME) {
2904
+ return `${label}.${parentName}`;
2876
2905
  }
2877
- function displayHandle(label) {
2878
- const parentDisplay = AUDRIC_PARENT_NAME.replace(/\.sui$/, "");
2906
+ function displayHandle(label, parentName = AUDRIC_PARENT_NAME) {
2907
+ const parentDisplay = parentName.replace(/\.sui$/, "");
2879
2908
  return `${label}@${parentDisplay}`;
2880
2909
  }
2881
2910
 
2882
2911
  // src/index.ts
2883
2912
  init_preflight();
2884
2913
 
2914
+ exports.AGENT_ID_PARENT = AGENT_ID_PARENT;
2915
+ exports.AGENT_ID_PARENT_NAME = AGENT_ID_PARENT_NAME;
2916
+ exports.AGENT_ID_PARENT_NFT_ID = AGENT_ID_PARENT_NFT_ID;
2917
+ exports.AUDRIC_PARENT = AUDRIC_PARENT;
2885
2918
  exports.AUDRIC_PARENT_NAME = AUDRIC_PARENT_NAME;
2886
2919
  exports.AUDRIC_PARENT_NFT_ID = AUDRIC_PARENT_NFT_ID;
2887
2920
  exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;