@t2000/sdk 5.6.0 → 5.6.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/browser.cjs +35 -22
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +35 -22
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +35 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -269,6 +269,7 @@ var init_token_registry = __esm({
|
|
|
269
269
|
// src/wallet/coinSelection.ts
|
|
270
270
|
var coinSelection_exports = {};
|
|
271
271
|
__export(coinSelection_exports, {
|
|
272
|
+
buildCoinToAddressBalanceMigration: () => buildCoinToAddressBalanceMigration,
|
|
272
273
|
fetchAllCoins: () => fetchAllCoins,
|
|
273
274
|
selectAndSplitCoin: () => selectAndSplitCoin,
|
|
274
275
|
selectSuiCoin: () => selectSuiCoin
|
|
@@ -382,6 +383,32 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
|
|
|
382
383
|
});
|
|
383
384
|
return { coin, effectiveAmount, swapAll };
|
|
384
385
|
}
|
|
386
|
+
function buildCoinToAddressBalanceMigration(args) {
|
|
387
|
+
const { coins, coinType, owner, minAmount } = args;
|
|
388
|
+
const sorted = [...coins].filter((c) => c.balance > 0n).sort((a, b) => b.balance > a.balance ? 1 : b.balance < a.balance ? -1 : 0);
|
|
389
|
+
const selected = [];
|
|
390
|
+
let migratedRaw = 0n;
|
|
391
|
+
for (const c of sorted) {
|
|
392
|
+
if (migratedRaw >= minAmount) break;
|
|
393
|
+
selected.push(c);
|
|
394
|
+
migratedRaw += c.balance;
|
|
395
|
+
}
|
|
396
|
+
if (migratedRaw < minAmount) {
|
|
397
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
|
|
398
|
+
available: migratedRaw.toString(),
|
|
399
|
+
required: minAmount.toString()
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
const tx = new Transaction();
|
|
403
|
+
for (const c of selected) {
|
|
404
|
+
tx.moveCall({
|
|
405
|
+
target: "0x2::coin::send_funds",
|
|
406
|
+
typeArguments: [coinType],
|
|
407
|
+
arguments: [tx.object(c.objectId), tx.pure.address(owner)]
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return { tx, migratedRaw };
|
|
411
|
+
}
|
|
385
412
|
async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, mergeCache) {
|
|
386
413
|
if (sponsoredContext) {
|
|
387
414
|
const { SUI_TYPE: SUI_TYPE2 } = await Promise.resolve().then(() => (init_token_registry(), token_registry_exports));
|
|
@@ -1160,40 +1187,26 @@ async function ensureAddressBalanceCovers(args) {
|
|
|
1160
1187
|
required: amountRaw.toString()
|
|
1161
1188
|
});
|
|
1162
1189
|
}
|
|
1190
|
+
const coins = [];
|
|
1163
1191
|
let coinSum = 0n;
|
|
1164
1192
|
let cursor;
|
|
1165
1193
|
let hasNext = true;
|
|
1166
1194
|
while (hasNext) {
|
|
1167
1195
|
const page = await client.core.listCoins({ owner, coinType: asset, cursor: cursor ?? void 0 });
|
|
1168
|
-
for (const c of page.objects)
|
|
1196
|
+
for (const c of page.objects) {
|
|
1197
|
+
coins.push({ objectId: c.objectId, balance: BigInt(c.balance) });
|
|
1198
|
+
coinSum += BigInt(c.balance);
|
|
1199
|
+
}
|
|
1169
1200
|
cursor = page.cursor;
|
|
1170
1201
|
hasNext = page.hasNextPage;
|
|
1171
1202
|
}
|
|
1172
1203
|
const addressBalance = total - coinSum;
|
|
1173
1204
|
if (addressBalance >= amountRaw) return 0;
|
|
1174
1205
|
const shortfall = amountRaw - addressBalance;
|
|
1175
|
-
const {
|
|
1176
|
-
const { selectAndSplitCoin: selectAndSplitCoin2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
|
|
1206
|
+
const { buildCoinToAddressBalanceMigration: buildCoinToAddressBalanceMigration2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
|
|
1177
1207
|
const grpcClient = await makeGrpcBuildClient(client);
|
|
1178
|
-
const
|
|
1179
|
-
|
|
1180
|
-
signer,
|
|
1181
|
-
async () => {
|
|
1182
|
-
const tx = new Transaction6();
|
|
1183
|
-
const { coin } = await selectAndSplitCoin2(tx, client, owner, asset, shortfall, {
|
|
1184
|
-
sponsoredContext: true,
|
|
1185
|
-
// coin-objects-only — never the address balance
|
|
1186
|
-
allowSwapAll: false
|
|
1187
|
-
});
|
|
1188
|
-
tx.moveCall({
|
|
1189
|
-
target: "0x2::coin::send_funds",
|
|
1190
|
-
typeArguments: [asset],
|
|
1191
|
-
arguments: [coin, tx.pure.address(owner)]
|
|
1192
|
-
});
|
|
1193
|
-
return tx;
|
|
1194
|
-
},
|
|
1195
|
-
{ buildClient: grpcClient }
|
|
1196
|
-
);
|
|
1208
|
+
const { tx } = buildCoinToAddressBalanceMigration2({ coins, coinType: asset, owner, minAmount: shortfall });
|
|
1209
|
+
const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
1197
1210
|
return migration.gasCostSui;
|
|
1198
1211
|
}
|
|
1199
1212
|
async function finalize(response, opts) {
|