@t2000/sdk 0.1.5 → 0.1.7
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 +15 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -890,11 +890,7 @@ async function tryAutoTopUpThenSelfFund(client, keypair, tx) {
|
|
|
890
890
|
const address = keypair.getPublicKey().toSuiAddress();
|
|
891
891
|
const canTopUp = await shouldAutoTopUp(client, address);
|
|
892
892
|
if (!canTopUp) return null;
|
|
893
|
-
|
|
894
|
-
await executeAutoTopUp(client, keypair);
|
|
895
|
-
} catch {
|
|
896
|
-
return null;
|
|
897
|
-
}
|
|
893
|
+
await executeAutoTopUp(client, keypair);
|
|
898
894
|
tx.setSender(address);
|
|
899
895
|
const result = await client.signAndExecuteTransaction({
|
|
900
896
|
signer: keypair,
|
|
@@ -912,19 +908,9 @@ async function tryAutoTopUpThenSelfFund(client, keypair, tx) {
|
|
|
912
908
|
async function trySponsored(client, keypair, tx) {
|
|
913
909
|
const address = keypair.getPublicKey().toSuiAddress();
|
|
914
910
|
tx.setSender(address);
|
|
915
|
-
|
|
916
|
-
try {
|
|
917
|
-
txBytes = await tx.build({ client, onlyTransactionKind: true });
|
|
918
|
-
} catch {
|
|
919
|
-
return null;
|
|
920
|
-
}
|
|
911
|
+
const txBytes = await tx.build({ client, onlyTransactionKind: true });
|
|
921
912
|
const txBytesBase64 = Buffer.from(txBytes).toString("base64");
|
|
922
|
-
|
|
923
|
-
try {
|
|
924
|
-
sponsoredResult = await requestGasSponsorship(txBytesBase64, address);
|
|
925
|
-
} catch {
|
|
926
|
-
return null;
|
|
927
|
-
}
|
|
913
|
+
const sponsoredResult = await requestGasSponsorship(txBytesBase64, address);
|
|
928
914
|
const sponsoredTxBytes = Buffer.from(sponsoredResult.txBytes, "base64");
|
|
929
915
|
const { signature: agentSig } = await keypair.signTransaction(sponsoredTxBytes);
|
|
930
916
|
const result = await client.executeTransactionBlock({
|
|
@@ -943,28 +929,35 @@ async function trySponsored(client, keypair, tx) {
|
|
|
943
929
|
};
|
|
944
930
|
}
|
|
945
931
|
async function executeWithGas(client, keypair, buildTx) {
|
|
932
|
+
const errors = [];
|
|
946
933
|
try {
|
|
947
934
|
const tx = await buildTx();
|
|
948
935
|
const result = await trySelfFunded(client, keypair, tx);
|
|
949
936
|
if (result) return result;
|
|
950
|
-
|
|
937
|
+
errors.push("self-funded: SUI below threshold");
|
|
938
|
+
} catch (err) {
|
|
939
|
+
errors.push(`self-funded: ${err instanceof Error ? err.message : String(err)}`);
|
|
951
940
|
}
|
|
952
941
|
try {
|
|
953
942
|
const tx = await buildTx();
|
|
954
943
|
const result = await tryAutoTopUpThenSelfFund(client, keypair, tx);
|
|
955
944
|
if (result) return result;
|
|
956
|
-
|
|
945
|
+
errors.push("auto-topup: not eligible (low USDC or sufficient SUI)");
|
|
946
|
+
} catch (err) {
|
|
947
|
+
errors.push(`auto-topup: ${err instanceof Error ? err.message : String(err)}`);
|
|
957
948
|
}
|
|
958
949
|
try {
|
|
959
950
|
const tx = await buildTx();
|
|
960
951
|
const result = await trySponsored(client, keypair, tx);
|
|
961
952
|
if (result) return result;
|
|
962
|
-
|
|
953
|
+
errors.push("sponsored: returned null");
|
|
954
|
+
} catch (err) {
|
|
955
|
+
errors.push(`sponsored: ${err instanceof Error ? err.message : String(err)}`);
|
|
963
956
|
}
|
|
964
957
|
throw new T2000Error(
|
|
965
958
|
"INSUFFICIENT_GAS",
|
|
966
|
-
|
|
967
|
-
{ reason: "all_gas_methods_exhausted" }
|
|
959
|
+
`No SUI for gas and Gas Station unavailable. Fund your wallet with SUI or USDC. [${errors.join(" | ")}]`,
|
|
960
|
+
{ reason: "all_gas_methods_exhausted", errors }
|
|
968
961
|
);
|
|
969
962
|
}
|
|
970
963
|
|