@ton/mcp 0.1.10 → 0.1.11
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/README.md +72 -122
- package/dist/cli.js +753 -436
- package/dist/factory.d.ts.map +1 -1
- package/dist/index.cjs +656 -326
- package/dist/index.js +656 -326
- package/dist/serverless.cjs +31387 -23963
- package/dist/serverless.js +31387 -23963
- package/dist/services/McpWalletService.d.ts +7 -0
- package/dist/services/McpWalletService.d.ts.map +1 -1
- package/dist/tools/balance-tools.d.ts +6 -0
- package/dist/tools/balance-tools.d.ts.map +1 -1
- package/llms.txt +7 -4
- package/package.json +2 -2
- package/skills/SKILL.md +8 -7
package/dist/index.js
CHANGED
|
@@ -19942,6 +19942,15 @@ var require_ShardStateUnsplit = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
19942
19942
|
exports.loadShardStateUnsplit = loadShardStateUnsplit;
|
|
19943
19943
|
}));
|
|
19944
19944
|
|
|
19945
|
+
//#endregion
|
|
19946
|
+
//#region ../../node_modules/@ton/core/dist/types/SignatureDomain.js
|
|
19947
|
+
var require_SignatureDomain = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
19948
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19949
|
+
exports.signatureDomainEmptyTag = exports.signatureDomainL2Tag = void 0;
|
|
19950
|
+
exports.signatureDomainL2Tag = 1907576545;
|
|
19951
|
+
exports.signatureDomainEmptyTag = 236803867;
|
|
19952
|
+
}));
|
|
19953
|
+
|
|
19945
19954
|
//#endregion
|
|
19946
19955
|
//#region ../../node_modules/@ton/core/dist/types/SplitMergeInfo.js
|
|
19947
19956
|
var require_SplitMergeInfo = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -20458,8 +20467,8 @@ var require__export = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
20458
20467
|
* LICENSE file in the root directory of this source tree.
|
|
20459
20468
|
*/
|
|
20460
20469
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20461
|
-
exports.
|
|
20462
|
-
exports.storeTransactionsStoragePhase = exports.loadTransactionStoragePhase = exports.storeTransactionDescription = exports.loadTransactionDescription = exports.storeTransactionCreditPhase = exports.loadTransactionCreditPhase = exports.storeTransactionComputePhase = exports.loadTransactionComputePhase = exports.storeTransactionBouncePhase = exports.loadTransactionBouncePhase = exports.storeTransactionActionPhase = exports.loadTransactionActionPhase = exports.storeTransaction = exports.loadTransaction = exports.storeTickTock = exports.loadTickTock = exports.storeStorageUsed = exports.loadStorageUsed = exports.storeStorageInfo = exports.loadStorageInfo = exports.storeStateInit = exports.loadStateInit = exports.storeSplitMergeInfo = exports.loadSplitMergeInfo = exports.storeLibRef = exports.loadLibRef = exports.storeSimpleLibrary = void 0;
|
|
20470
|
+
exports.signatureDomainEmptyTag = exports.loadShardStateUnsplit = exports.storeShardIdent = exports.loadShardIdent = exports.storeShardAccounts = exports.loadShardAccounts = exports.ShardAccountRefValue = exports.storeShardAccount = exports.loadShardAccount = exports.ReserveMode = exports.SendMode = exports.storeMessageRelaxed = exports.loadMessageRelaxed = exports.storeMessage = exports.loadMessage = exports.loadMasterchainStateExtra = exports.storeHashUpdate = exports.loadHashUpdate = exports.storeExtraCurrency = exports.loadMaybeExtraCurrency = exports.loadExtraCurrency = exports.packExtraCurrencyDict = exports.packExtraCurrencyCell = exports.storeDepthBalanceInfo = exports.loadDepthBalanceInfo = exports.storeCurrencyCollection = exports.loadCurrencyCollection = exports.storeComputeSkipReason = exports.loadComputeSkipReason = exports.storeCommonMessageInfoRelaxed = exports.loadCommonMessageInfoRelaxed = exports.storeCommonMessageInfo = exports.loadCommonMessageInfo = exports.storeOutList = exports.loadOutList = exports.storeOutAction = exports.loadOutAction = exports.storeAccountStorage = exports.loadAccountStorage = exports.storeAccountStatusChange = exports.loadAccountStatusChange = exports.storeAccountStatus = exports.loadAccountStatus = exports.storeAccountState = exports.loadAccountState = exports.storeAccount = exports.loadAccount = exports.comment = exports.external = exports.internal = void 0;
|
|
20471
|
+
exports.storeTransactionsStoragePhase = exports.loadTransactionStoragePhase = exports.storeTransactionDescription = exports.loadTransactionDescription = exports.storeTransactionCreditPhase = exports.loadTransactionCreditPhase = exports.storeTransactionComputePhase = exports.loadTransactionComputePhase = exports.storeTransactionBouncePhase = exports.loadTransactionBouncePhase = exports.storeTransactionActionPhase = exports.loadTransactionActionPhase = exports.storeTransaction = exports.loadTransaction = exports.storeTickTock = exports.loadTickTock = exports.storeStorageUsed = exports.loadStorageUsed = exports.storeStorageInfo = exports.loadStorageInfo = exports.storeStateInit = exports.loadStateInit = exports.storeSplitMergeInfo = exports.loadSplitMergeInfo = exports.storeLibRef = exports.loadLibRef = exports.storeSimpleLibrary = exports.loadSimpleLibrary = exports.signatureDomainL2Tag = void 0;
|
|
20463
20472
|
var _helpers_1 = require__helpers();
|
|
20464
20473
|
Object.defineProperty(exports, "internal", {
|
|
20465
20474
|
enumerable: true,
|
|
@@ -20777,6 +20786,19 @@ var require__export = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
20777
20786
|
return ShardStateUnsplit_1.loadShardStateUnsplit;
|
|
20778
20787
|
}
|
|
20779
20788
|
});
|
|
20789
|
+
var SignatureDomain_1 = require_SignatureDomain();
|
|
20790
|
+
Object.defineProperty(exports, "signatureDomainEmptyTag", {
|
|
20791
|
+
enumerable: true,
|
|
20792
|
+
get: function() {
|
|
20793
|
+
return SignatureDomain_1.signatureDomainEmptyTag;
|
|
20794
|
+
}
|
|
20795
|
+
});
|
|
20796
|
+
Object.defineProperty(exports, "signatureDomainL2Tag", {
|
|
20797
|
+
enumerable: true,
|
|
20798
|
+
get: function() {
|
|
20799
|
+
return SignatureDomain_1.signatureDomainL2Tag;
|
|
20800
|
+
}
|
|
20801
|
+
});
|
|
20780
20802
|
var SimpleLibrary_1 = require_SimpleLibrary();
|
|
20781
20803
|
Object.defineProperty(exports, "loadSimpleLibrary", {
|
|
20782
20804
|
enumerable: true,
|
|
@@ -21344,6 +21366,53 @@ var require_safeSign = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
21344
21366
|
exports.safeSignVerify = safeSignVerify;
|
|
21345
21367
|
}));
|
|
21346
21368
|
|
|
21369
|
+
//#endregion
|
|
21370
|
+
//#region ../../node_modules/@ton/core/dist/crypto/domainSignature.js
|
|
21371
|
+
var require_domainSignature = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
21372
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21373
|
+
exports.domainSignVerify = exports.domainSign = exports.signatureDomainPrefix = exports.signatureDomainHash = void 0;
|
|
21374
|
+
const crypto_1 = require_dist$2();
|
|
21375
|
+
const SignatureDomain_1 = require_SignatureDomain();
|
|
21376
|
+
function signatureDomainHash(domain) {
|
|
21377
|
+
switch (domain.type) {
|
|
21378
|
+
case "empty":
|
|
21379
|
+
const tl = Buffer.alloc(4);
|
|
21380
|
+
tl.writeInt32LE(SignatureDomain_1.signatureDomainEmptyTag);
|
|
21381
|
+
return (0, crypto_1.sha256_sync)(tl);
|
|
21382
|
+
case "l2": {
|
|
21383
|
+
const tl = Buffer.alloc(8);
|
|
21384
|
+
tl.writeInt32LE(SignatureDomain_1.signatureDomainL2Tag);
|
|
21385
|
+
tl.writeInt32LE(domain.globalId, 4);
|
|
21386
|
+
return (0, crypto_1.sha256_sync)(tl);
|
|
21387
|
+
}
|
|
21388
|
+
default: throw new Error(`Unknown SignatureDomain type ${domain.type}`);
|
|
21389
|
+
}
|
|
21390
|
+
}
|
|
21391
|
+
exports.signatureDomainHash = signatureDomainHash;
|
|
21392
|
+
const signatureDomainEmptyHash = signatureDomainHash({ type: "empty" });
|
|
21393
|
+
function signatureDomainPrefix(domainOrHash) {
|
|
21394
|
+
const domainHash = Buffer.isBuffer(domainOrHash) ? domainOrHash : signatureDomainHash(domainOrHash);
|
|
21395
|
+
if (domainHash.length !== 32) throw new Error("Invalid signature domain hash length");
|
|
21396
|
+
if (domainHash.equals(signatureDomainEmptyHash)) return null;
|
|
21397
|
+
return domainHash;
|
|
21398
|
+
}
|
|
21399
|
+
exports.signatureDomainPrefix = signatureDomainPrefix;
|
|
21400
|
+
function domainDataToSign(data, domain) {
|
|
21401
|
+
const prefix = signatureDomainPrefix(domain);
|
|
21402
|
+
return prefix ? Buffer.concat([prefix, data]) : data;
|
|
21403
|
+
}
|
|
21404
|
+
function domainSign({ data, secretKey, domain = { type: "empty" } }) {
|
|
21405
|
+
const dataToSign = domainDataToSign(data, domain);
|
|
21406
|
+
return (0, crypto_1.sign)(dataToSign, secretKey);
|
|
21407
|
+
}
|
|
21408
|
+
exports.domainSign = domainSign;
|
|
21409
|
+
function domainSignVerify({ data, signature, publicKey, domain = { type: "empty" } }) {
|
|
21410
|
+
const dataToSign = domainDataToSign(data, domain);
|
|
21411
|
+
return (0, crypto_1.signVerify)(dataToSign, signature, publicKey);
|
|
21412
|
+
}
|
|
21413
|
+
exports.domainSignVerify = domainSignVerify;
|
|
21414
|
+
}));
|
|
21415
|
+
|
|
21347
21416
|
//#endregion
|
|
21348
21417
|
//#region ../../node_modules/@ton/core/dist/index.js
|
|
21349
21418
|
var require_dist$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -21372,7 +21441,7 @@ var require_dist$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
21372
21441
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$3, p)) __createBinding(exports$3, m, p);
|
|
21373
21442
|
};
|
|
21374
21443
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21375
|
-
exports.safeSignVerify = exports.safeSign = exports.getMethodId = exports.base32Encode = exports.base32Decode = exports.crc32c = exports.crc16 = exports.fromNano = exports.toNano = exports.ComputeError = exports.openContract = exports.TupleBuilder = exports.TupleReader = exports.serializeTupleItem = exports.parseTupleItem = exports.serializeTuple = exports.parseTuple = exports.generateMerkleUpdate = exports.generateMerkleProofDirect = exports.generateMerkleProof = exports.exoticPruned = exports.exoticMerkleUpdate = exports.convertToMerkleProof = exports.exoticMerkleProof = exports.Dictionary = exports.Cell = exports.CellType = exports.Slice = exports.beginCell = exports.Builder = exports.BitBuilder = exports.BitReader = exports.BitString = exports.contractAddress = exports.ADNLAddress = exports.ExternalAddress = exports.address = exports.Address = void 0;
|
|
21444
|
+
exports.domainSignVerify = exports.domainSign = exports.signatureDomainPrefix = exports.signatureDomainHash = exports.safeSignVerify = exports.safeSign = exports.getMethodId = exports.base32Encode = exports.base32Decode = exports.crc32c = exports.crc16 = exports.fromNano = exports.toNano = exports.ComputeError = exports.openContract = exports.TupleBuilder = exports.TupleReader = exports.serializeTupleItem = exports.parseTupleItem = exports.serializeTuple = exports.parseTuple = exports.generateMerkleUpdate = exports.generateMerkleProofDirect = exports.generateMerkleProof = exports.exoticPruned = exports.exoticMerkleUpdate = exports.convertToMerkleProof = exports.exoticMerkleProof = exports.Dictionary = exports.Cell = exports.CellType = exports.Slice = exports.beginCell = exports.Builder = exports.BitBuilder = exports.BitReader = exports.BitString = exports.contractAddress = exports.ADNLAddress = exports.ExternalAddress = exports.address = exports.Address = void 0;
|
|
21376
21445
|
var Address_1 = require_Address();
|
|
21377
21446
|
Object.defineProperty(exports, "Address", {
|
|
21378
21447
|
enumerable: true,
|
|
@@ -21630,6 +21699,31 @@ var require_dist$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
21630
21699
|
return safeSign_1.safeSignVerify;
|
|
21631
21700
|
}
|
|
21632
21701
|
});
|
|
21702
|
+
var domainSignature_1 = require_domainSignature();
|
|
21703
|
+
Object.defineProperty(exports, "signatureDomainHash", {
|
|
21704
|
+
enumerable: true,
|
|
21705
|
+
get: function() {
|
|
21706
|
+
return domainSignature_1.signatureDomainHash;
|
|
21707
|
+
}
|
|
21708
|
+
});
|
|
21709
|
+
Object.defineProperty(exports, "signatureDomainPrefix", {
|
|
21710
|
+
enumerable: true,
|
|
21711
|
+
get: function() {
|
|
21712
|
+
return domainSignature_1.signatureDomainPrefix;
|
|
21713
|
+
}
|
|
21714
|
+
});
|
|
21715
|
+
Object.defineProperty(exports, "domainSign", {
|
|
21716
|
+
enumerable: true,
|
|
21717
|
+
get: function() {
|
|
21718
|
+
return domainSignature_1.domainSign;
|
|
21719
|
+
}
|
|
21720
|
+
});
|
|
21721
|
+
Object.defineProperty(exports, "domainSignVerify", {
|
|
21722
|
+
enumerable: true,
|
|
21723
|
+
get: function() {
|
|
21724
|
+
return domainSignature_1.domainSignVerify;
|
|
21725
|
+
}
|
|
21726
|
+
});
|
|
21633
21727
|
}));
|
|
21634
21728
|
|
|
21635
21729
|
//#endregion
|
|
@@ -23920,7 +24014,7 @@ var TONConnectStoredSessionManager = class {
|
|
|
23920
24014
|
};
|
|
23921
24015
|
|
|
23922
24016
|
//#endregion
|
|
23923
|
-
//#region ../../node_modules
|
|
24017
|
+
//#region ../../node_modules/eventsource/lib/eventsource.js
|
|
23924
24018
|
var require_eventsource = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
23925
24019
|
var parse = __require("url").parse;
|
|
23926
24020
|
var events = __require("events");
|
|
@@ -24335,7 +24429,7 @@ var import_eventsource = /* @__PURE__ */ __toESM(require_eventsource(), 1);
|
|
|
24335
24429
|
if (!global.EventSource) global.EventSource = import_eventsource.default;
|
|
24336
24430
|
|
|
24337
24431
|
//#endregion
|
|
24338
|
-
//#region ../../node_modules/
|
|
24432
|
+
//#region ../../node_modules/node-fetch/node_modules/webidl-conversions/lib/index.js
|
|
24339
24433
|
var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
24340
24434
|
var conversions = {};
|
|
24341
24435
|
module.exports = conversions;
|
|
@@ -24452,7 +24546,7 @@ var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
24452
24546
|
}));
|
|
24453
24547
|
|
|
24454
24548
|
//#endregion
|
|
24455
|
-
//#region ../../node_modules/whatwg-url/lib/utils.js
|
|
24549
|
+
//#region ../../node_modules/node-fetch/node_modules/whatwg-url/lib/utils.js
|
|
24456
24550
|
var require_utils = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
24457
24551
|
module.exports.mixin = function mixin(target, source) {
|
|
24458
24552
|
const keys = Object.getOwnPropertyNames(source);
|
|
@@ -60166,7 +60260,7 @@ var require_tr46 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
60166
60260
|
}));
|
|
60167
60261
|
|
|
60168
60262
|
//#endregion
|
|
60169
|
-
//#region ../../node_modules/whatwg-url/lib/url-state-machine.js
|
|
60263
|
+
//#region ../../node_modules/node-fetch/node_modules/whatwg-url/lib/url-state-machine.js
|
|
60170
60264
|
var require_url_state_machine = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
60171
60265
|
const punycode = __require("punycode");
|
|
60172
60266
|
const tr46 = require_tr46();
|
|
@@ -61038,7 +61132,7 @@ var require_url_state_machine = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
61038
61132
|
}));
|
|
61039
61133
|
|
|
61040
61134
|
//#endregion
|
|
61041
|
-
//#region ../../node_modules/whatwg-url/lib/URL-impl.js
|
|
61135
|
+
//#region ../../node_modules/node-fetch/node_modules/whatwg-url/lib/URL-impl.js
|
|
61042
61136
|
var require_URL_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
61043
61137
|
const usm = require_url_state_machine();
|
|
61044
61138
|
exports.implementation = class URLImpl {
|
|
@@ -61177,7 +61271,7 @@ var require_URL_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
61177
61271
|
}));
|
|
61178
61272
|
|
|
61179
61273
|
//#endregion
|
|
61180
|
-
//#region ../../node_modules/whatwg-url/lib/URL.js
|
|
61274
|
+
//#region ../../node_modules/node-fetch/node_modules/whatwg-url/lib/URL.js
|
|
61181
61275
|
var require_URL = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
61182
61276
|
const conversions = require_lib$1();
|
|
61183
61277
|
const utils = require_utils();
|
|
@@ -61343,7 +61437,7 @@ var require_URL = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
61343
61437
|
}));
|
|
61344
61438
|
|
|
61345
61439
|
//#endregion
|
|
61346
|
-
//#region ../../node_modules/whatwg-url/lib/public-api.js
|
|
61440
|
+
//#region ../../node_modules/node-fetch/node_modules/whatwg-url/lib/public-api.js
|
|
61347
61441
|
var require_public_api = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
61348
61442
|
exports.URL = require_URL().interface;
|
|
61349
61443
|
exports.serializeURL = require_url_state_machine().serializeURL;
|
|
@@ -64315,7 +64409,8 @@ var BridgeManager = class {
|
|
|
64315
64409
|
tabId: event?.tabId,
|
|
64316
64410
|
messageId: event?.messageId,
|
|
64317
64411
|
traceId: event?.traceId,
|
|
64318
|
-
walletId: event?.walletId
|
|
64412
|
+
walletId: event?.walletId,
|
|
64413
|
+
returnStrategy: event?.returnStrategy
|
|
64319
64414
|
};
|
|
64320
64415
|
if (!rawEvent.traceId) rawEvent.traceId = v7_default();
|
|
64321
64416
|
await this.sessionManager.initialize();
|
|
@@ -64465,9 +64560,11 @@ function isValidHost(host) {
|
|
|
64465
64560
|
*/
|
|
64466
64561
|
const log$18 = globalLogger.createChild("ConnectHandler");
|
|
64467
64562
|
var ConnectHandler = class ConnectHandler extends BasicHandler {
|
|
64563
|
+
config;
|
|
64468
64564
|
analytics;
|
|
64469
|
-
constructor(notify, analyticsManager) {
|
|
64565
|
+
constructor(notify, config, analyticsManager) {
|
|
64470
64566
|
super(notify);
|
|
64567
|
+
this.config = config;
|
|
64471
64568
|
this.analytics = analyticsManager?.scoped();
|
|
64472
64569
|
}
|
|
64473
64570
|
canHandle(event) {
|
|
@@ -64492,7 +64589,8 @@ var ConnectHandler = class ConnectHandler extends BasicHandler {
|
|
|
64492
64589
|
preview,
|
|
64493
64590
|
dAppInfo: preview.dAppInfo,
|
|
64494
64591
|
isJsBridge: event.isJsBridge,
|
|
64495
|
-
tabId: event.tabId
|
|
64592
|
+
tabId: event.tabId,
|
|
64593
|
+
returnStrategy: event.params.returnStrategy
|
|
64496
64594
|
};
|
|
64497
64595
|
this.analytics?.emitWalletConnectRequestReceived({
|
|
64498
64596
|
trace_id: event.traceId,
|
|
@@ -64537,18 +64635,20 @@ var ConnectHandler = class ConnectHandler extends BasicHandler {
|
|
|
64537
64635
|
const manifest = fetchedManifest || eventManifest;
|
|
64538
64636
|
const dAppUrl = (event?.domain || manifest?.url?.toString() || "").trim();
|
|
64539
64637
|
let finalManifestFetchErrorCode = manifestFetchErrorCode;
|
|
64540
|
-
if (!
|
|
64541
|
-
|
|
64542
|
-
|
|
64543
|
-
|
|
64544
|
-
|
|
64545
|
-
|
|
64546
|
-
|
|
64638
|
+
if (!this.config.dev?.disableManifestDomainCheck) {
|
|
64639
|
+
if (!finalManifestFetchErrorCode && dAppUrl) try {
|
|
64640
|
+
const parsedDAppUrl = new URL(dAppUrl);
|
|
64641
|
+
if (!isValidHost(parsedDAppUrl.host)) {
|
|
64642
|
+
log$18.warn("Invalid dApp URL in manifest - invalid host format", {
|
|
64643
|
+
dAppUrl,
|
|
64644
|
+
host: parsedDAppUrl.host
|
|
64645
|
+
});
|
|
64646
|
+
finalManifestFetchErrorCode = CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR;
|
|
64647
|
+
}
|
|
64648
|
+
} catch (_) {
|
|
64649
|
+
log$18.warn("Invalid dApp URL in manifest - failed to parse", { dAppUrl });
|
|
64547
64650
|
finalManifestFetchErrorCode = CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR;
|
|
64548
64651
|
}
|
|
64549
|
-
} catch (_) {
|
|
64550
|
-
log$18.warn("Invalid dApp URL in manifest - failed to parse", { dAppUrl });
|
|
64551
|
-
finalManifestFetchErrorCode = CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR;
|
|
64552
64652
|
}
|
|
64553
64653
|
const sanitizedManifest = manifest && {
|
|
64554
64654
|
name: manifest.name?.toString()?.trim() || "",
|
|
@@ -64606,15 +64706,25 @@ var ConnectHandler = class ConnectHandler extends BasicHandler {
|
|
|
64606
64706
|
async tryFetchManifest(url) {
|
|
64607
64707
|
try {
|
|
64608
64708
|
const response = await fetch(url);
|
|
64609
|
-
if (!response.ok)
|
|
64610
|
-
manifest
|
|
64611
|
-
|
|
64612
|
-
|
|
64709
|
+
if (!response.ok) {
|
|
64710
|
+
log$18.error("Failed to fetch manifest not ok", {
|
|
64711
|
+
url,
|
|
64712
|
+
status: response.status
|
|
64713
|
+
});
|
|
64714
|
+
return {
|
|
64715
|
+
manifest: null,
|
|
64716
|
+
manifestFetchErrorCode: CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR
|
|
64717
|
+
};
|
|
64718
|
+
}
|
|
64613
64719
|
return {
|
|
64614
64720
|
manifest: await response.json(),
|
|
64615
64721
|
manifestFetchErrorCode: void 0
|
|
64616
64722
|
};
|
|
64617
|
-
} catch (
|
|
64723
|
+
} catch (e) {
|
|
64724
|
+
log$18.error("Failed to fetch manifest catched", {
|
|
64725
|
+
url,
|
|
64726
|
+
error: e
|
|
64727
|
+
});
|
|
64618
64728
|
return {
|
|
64619
64729
|
manifest: null,
|
|
64620
64730
|
manifestFetchErrorCode: CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR
|
|
@@ -64716,6 +64826,17 @@ function toExtraCurrencies(extraCurrency) {
|
|
|
64716
64826
|
if (!extraCurrency) return;
|
|
64717
64827
|
return extraCurrency;
|
|
64718
64828
|
}
|
|
64829
|
+
/**
|
|
64830
|
+
* Parse raw TON Connect transaction params to internal format
|
|
64831
|
+
*/
|
|
64832
|
+
function parseConnectTransactionParamContent(raw) {
|
|
64833
|
+
return {
|
|
64834
|
+
messages: raw.messages,
|
|
64835
|
+
network: raw.network,
|
|
64836
|
+
validUntil: raw.valid_until,
|
|
64837
|
+
from: raw.from
|
|
64838
|
+
};
|
|
64839
|
+
}
|
|
64719
64840
|
function toTransactionRequestMessage(msg) {
|
|
64720
64841
|
asAddressFriendly(msg.address);
|
|
64721
64842
|
return {
|
|
@@ -64737,14 +64858,20 @@ function toConnectTransactionParamMessage(message) {
|
|
|
64737
64858
|
mode: message.mode ? SendModeToValue(message.mode) : void 0
|
|
64738
64859
|
};
|
|
64739
64860
|
}
|
|
64861
|
+
/**
|
|
64862
|
+
* Convert internal params format to TransactionRequest model.
|
|
64863
|
+
*/
|
|
64740
64864
|
function toTransactionRequest(params) {
|
|
64741
64865
|
return {
|
|
64742
64866
|
messages: params.messages.map(toTransactionRequestMessage),
|
|
64743
64867
|
network: params.network ? { chainId: params.network } : void 0,
|
|
64744
|
-
validUntil: params.
|
|
64868
|
+
validUntil: params.validUntil,
|
|
64745
64869
|
fromAddress: params.from
|
|
64746
64870
|
};
|
|
64747
64871
|
}
|
|
64872
|
+
/**
|
|
64873
|
+
* Convert internal TransactionRequest to raw TON Connect protocol
|
|
64874
|
+
*/
|
|
64748
64875
|
function toConnectTransactionParamContent(request) {
|
|
64749
64876
|
return {
|
|
64750
64877
|
messages: request.messages.map(toConnectTransactionParamMessage),
|
|
@@ -65349,10 +65476,10 @@ var TransactionHandler = class extends BasicHandler {
|
|
|
65349
65476
|
paramCount: event.params.length,
|
|
65350
65477
|
eventId: event.id
|
|
65351
65478
|
});
|
|
65352
|
-
const params = JSON.parse(event.params[0]);
|
|
65353
|
-
const validUntilValidation = this.validateValidUntil(params.
|
|
65479
|
+
const params = parseConnectTransactionParamContent(JSON.parse(event.params[0]));
|
|
65480
|
+
const validUntilValidation = this.validateValidUntil(params.validUntil);
|
|
65354
65481
|
if (!validUntilValidation.isValid) errors = errors.concat(validUntilValidation.errors);
|
|
65355
|
-
else params.
|
|
65482
|
+
else params.validUntil = validUntilValidation.result;
|
|
65356
65483
|
const networkValidation = this.validateNetwork(params.network, wallet);
|
|
65357
65484
|
if (!networkValidation.isValid) errors = errors.concat(networkValidation.errors);
|
|
65358
65485
|
else params.network = networkValidation.result;
|
|
@@ -65853,7 +65980,7 @@ var EventRouter = class {
|
|
|
65853
65980
|
*/
|
|
65854
65981
|
setupHandlers() {
|
|
65855
65982
|
this.handlers = [
|
|
65856
|
-
new ConnectHandler(this.notifyConnectRequestCallbacks.bind(this), this.analyticsManager),
|
|
65983
|
+
new ConnectHandler(this.notifyConnectRequestCallbacks.bind(this), this.config, this.analyticsManager),
|
|
65857
65984
|
new TransactionHandler(this.notifyTransactionRequestCallbacks.bind(this), this.config, this.eventEmitter, this.walletManager, this.sessionManager, this.analyticsManager),
|
|
65858
65985
|
new SignDataHandler(this.notifySignDataRequestCallbacks.bind(this), this.walletManager, this.sessionManager, this.analyticsManager),
|
|
65859
65986
|
new DisconnectHandler(this.notifyDisconnectCallbacks.bind(this), this.sessionManager)
|
|
@@ -67188,144 +67315,6 @@ var StorageEventProcessor = class {
|
|
|
67188
67315
|
}
|
|
67189
67316
|
};
|
|
67190
67317
|
|
|
67191
|
-
//#endregion
|
|
67192
|
-
//#region ../walletkit/dist/esm/core/wallet/extensions/ton.js
|
|
67193
|
-
/**
|
|
67194
|
-
* Copyright (c) TonTech.
|
|
67195
|
-
*
|
|
67196
|
-
* This source code is licensed under the MIT license found in the
|
|
67197
|
-
* LICENSE file in the root directory of this source tree.
|
|
67198
|
-
*
|
|
67199
|
-
*/
|
|
67200
|
-
const log$11 = globalLogger.createChild("WalletTonClass");
|
|
67201
|
-
var WalletTonClass = class {
|
|
67202
|
-
async createTransferTonTransaction(param) {
|
|
67203
|
-
if (!isValidAddress(param.recipientAddress)) throw new Error(`Invalid to address: ${param.recipientAddress}`);
|
|
67204
|
-
if (!isValidNanotonAmount(param.transferAmount)) throw new Error(`Invalid amount: ${param.transferAmount}`);
|
|
67205
|
-
let body;
|
|
67206
|
-
if (param.payload) body = param.payload;
|
|
67207
|
-
else if (param.comment) body = (0, import_dist$2.beginCell)().storeUint(0, 32).storeStringTail(param.comment).endCell().toBoc().toString("base64");
|
|
67208
|
-
const message = {
|
|
67209
|
-
address: param.recipientAddress,
|
|
67210
|
-
amount: param.transferAmount,
|
|
67211
|
-
payload: body,
|
|
67212
|
-
stateInit: param.stateInit,
|
|
67213
|
-
extraCurrency: param.extraCurrency,
|
|
67214
|
-
mode: param.mode
|
|
67215
|
-
};
|
|
67216
|
-
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
67217
|
-
return {
|
|
67218
|
-
messages: [message],
|
|
67219
|
-
fromAddress: this.getAddress()
|
|
67220
|
-
};
|
|
67221
|
-
}
|
|
67222
|
-
async createTransferMultiTonTransaction(params) {
|
|
67223
|
-
let messages = [];
|
|
67224
|
-
for (const param of params) {
|
|
67225
|
-
if (!isValidAddress(param.recipientAddress)) throw new Error(`Invalid to address: ${param.recipientAddress}`);
|
|
67226
|
-
if (!isValidNanotonAmount(param.transferAmount)) throw new Error(`Invalid amount: ${param.transferAmount}`);
|
|
67227
|
-
let body;
|
|
67228
|
-
if (param.payload) body = param.payload;
|
|
67229
|
-
else if (param.comment) body = (0, import_dist$2.beginCell)().storeUint(0, 32).storeStringTail(param.comment).endCell().toBoc().toString("base64");
|
|
67230
|
-
const message = {
|
|
67231
|
-
address: param.recipientAddress,
|
|
67232
|
-
amount: param.transferAmount,
|
|
67233
|
-
payload: body,
|
|
67234
|
-
stateInit: param.stateInit,
|
|
67235
|
-
extraCurrency: param.extraCurrency,
|
|
67236
|
-
mode: param.mode
|
|
67237
|
-
};
|
|
67238
|
-
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
67239
|
-
messages.push(message);
|
|
67240
|
-
}
|
|
67241
|
-
return {
|
|
67242
|
-
messages,
|
|
67243
|
-
fromAddress: this.getAddress()
|
|
67244
|
-
};
|
|
67245
|
-
}
|
|
67246
|
-
async getTransactionPreview(param) {
|
|
67247
|
-
const transaction = await param;
|
|
67248
|
-
return await CallForSuccess(() => createTransactionPreview(this.client, transaction, this));
|
|
67249
|
-
}
|
|
67250
|
-
async sendTransaction(request) {
|
|
67251
|
-
try {
|
|
67252
|
-
const boc = await this.getSignedSendTransaction(request);
|
|
67253
|
-
await CallForSuccess(() => this.getClient().sendBoc(boc));
|
|
67254
|
-
return { boc };
|
|
67255
|
-
} catch (error) {
|
|
67256
|
-
log$11.error("Failed to send transaction", { error });
|
|
67257
|
-
if (error instanceof WalletKitError) throw error;
|
|
67258
|
-
if (error?.message?.includes("Ledger device")) throw new WalletKitError(ERROR_CODES.LEDGER_DEVICE_ERROR, "Ledger device error", error);
|
|
67259
|
-
throw error;
|
|
67260
|
-
}
|
|
67261
|
-
}
|
|
67262
|
-
async getBalance() {
|
|
67263
|
-
return await CallForSuccess(async () => this.getClient().getBalance(this.getAddress()));
|
|
67264
|
-
}
|
|
67265
|
-
};
|
|
67266
|
-
|
|
67267
|
-
//#endregion
|
|
67268
|
-
//#region ../walletkit/dist/esm/utils/tvmStack.js
|
|
67269
|
-
/**
|
|
67270
|
-
* Copyright (c) TonTech.
|
|
67271
|
-
*
|
|
67272
|
-
* This source code is licensed under the MIT license found in the
|
|
67273
|
-
* LICENSE file in the root directory of this source tree.
|
|
67274
|
-
*
|
|
67275
|
-
*/
|
|
67276
|
-
function ParseStackItem(item) {
|
|
67277
|
-
switch (item.type) {
|
|
67278
|
-
case "num": if (item.value.startsWith("-")) return {
|
|
67279
|
-
type: "int",
|
|
67280
|
-
value: -BigInt(item.value.slice(1))
|
|
67281
|
-
};
|
|
67282
|
-
else return {
|
|
67283
|
-
type: "int",
|
|
67284
|
-
value: BigInt(item.value)
|
|
67285
|
-
};
|
|
67286
|
-
case "null": return { type: "null" };
|
|
67287
|
-
case "cell": return {
|
|
67288
|
-
type: "cell",
|
|
67289
|
-
cell: import_dist$2.Cell.fromBoc(Buffer.from(item.value, "base64"))[0]
|
|
67290
|
-
};
|
|
67291
|
-
case "tuple":
|
|
67292
|
-
case "list":
|
|
67293
|
-
if (item.value.length === 0) return { type: "null" };
|
|
67294
|
-
return {
|
|
67295
|
-
type: "tuple",
|
|
67296
|
-
items: item.value.map((value) => ParseStackItem(value))
|
|
67297
|
-
};
|
|
67298
|
-
default: throw Error(`Unsupported parse stack item type: ${JSON.stringify(item)}`);
|
|
67299
|
-
}
|
|
67300
|
-
}
|
|
67301
|
-
function ParseStack(list) {
|
|
67302
|
-
let stack = [];
|
|
67303
|
-
for (let item of list) stack.push(ParseStackItem(item));
|
|
67304
|
-
return stack;
|
|
67305
|
-
}
|
|
67306
|
-
function SerializeStackItem(item) {
|
|
67307
|
-
switch (item.type) {
|
|
67308
|
-
case "int": return {
|
|
67309
|
-
type: "num",
|
|
67310
|
-
value: `${item.value < 0 ? "-" : ""}0x${item.value.toString(16)}`
|
|
67311
|
-
};
|
|
67312
|
-
case "slice": return {
|
|
67313
|
-
type: "slice",
|
|
67314
|
-
value: item.cell.toBoc().toString("base64")
|
|
67315
|
-
};
|
|
67316
|
-
case "cell": return {
|
|
67317
|
-
type: "cell",
|
|
67318
|
-
value: item.cell.toBoc().toString("base64")
|
|
67319
|
-
};
|
|
67320
|
-
default: throw Error(`Unsupported serialize stack item type: ${item.type}`);
|
|
67321
|
-
}
|
|
67322
|
-
}
|
|
67323
|
-
function SerializeStack(list) {
|
|
67324
|
-
let stack = [];
|
|
67325
|
-
for (let item of list) stack.push(SerializeStackItem(item));
|
|
67326
|
-
return stack;
|
|
67327
|
-
}
|
|
67328
|
-
|
|
67329
67318
|
//#endregion
|
|
67330
67319
|
//#region ../walletkit/dist/esm/types/toncenter/parsers/messageHandler.js
|
|
67331
67320
|
/**
|
|
@@ -68243,6 +68232,68 @@ function getUnixtime() {
|
|
|
68243
68232
|
return Math.floor(Date.now() / 1e3);
|
|
68244
68233
|
}
|
|
68245
68234
|
|
|
68235
|
+
//#endregion
|
|
68236
|
+
//#region ../walletkit/dist/esm/utils/tvmStack.js
|
|
68237
|
+
/**
|
|
68238
|
+
* Copyright (c) TonTech.
|
|
68239
|
+
*
|
|
68240
|
+
* This source code is licensed under the MIT license found in the
|
|
68241
|
+
* LICENSE file in the root directory of this source tree.
|
|
68242
|
+
*
|
|
68243
|
+
*/
|
|
68244
|
+
function ParseStackItem(item) {
|
|
68245
|
+
switch (item.type) {
|
|
68246
|
+
case "num": if (item.value.startsWith("-")) return {
|
|
68247
|
+
type: "int",
|
|
68248
|
+
value: -BigInt(item.value.slice(1))
|
|
68249
|
+
};
|
|
68250
|
+
else return {
|
|
68251
|
+
type: "int",
|
|
68252
|
+
value: BigInt(item.value)
|
|
68253
|
+
};
|
|
68254
|
+
case "null": return { type: "null" };
|
|
68255
|
+
case "cell": return {
|
|
68256
|
+
type: "cell",
|
|
68257
|
+
cell: import_dist$2.Cell.fromBoc(Buffer.from(item.value, "base64"))[0]
|
|
68258
|
+
};
|
|
68259
|
+
case "tuple":
|
|
68260
|
+
case "list":
|
|
68261
|
+
if (item.value.length === 0) return { type: "null" };
|
|
68262
|
+
return {
|
|
68263
|
+
type: "tuple",
|
|
68264
|
+
items: item.value.map((value) => ParseStackItem(value))
|
|
68265
|
+
};
|
|
68266
|
+
default: throw Error(`Unsupported parse stack item type: ${JSON.stringify(item)}`);
|
|
68267
|
+
}
|
|
68268
|
+
}
|
|
68269
|
+
function ParseStack(list) {
|
|
68270
|
+
let stack = [];
|
|
68271
|
+
for (let item of list) stack.push(ParseStackItem(item));
|
|
68272
|
+
return stack;
|
|
68273
|
+
}
|
|
68274
|
+
function SerializeStackItem(item) {
|
|
68275
|
+
switch (item.type) {
|
|
68276
|
+
case "int": return {
|
|
68277
|
+
type: "num",
|
|
68278
|
+
value: `${item.value < 0 ? "-" : ""}0x${item.value.toString(16)}`
|
|
68279
|
+
};
|
|
68280
|
+
case "slice": return {
|
|
68281
|
+
type: "slice",
|
|
68282
|
+
value: item.cell.toBoc().toString("base64")
|
|
68283
|
+
};
|
|
68284
|
+
case "cell": return {
|
|
68285
|
+
type: "cell",
|
|
68286
|
+
value: item.cell.toBoc().toString("base64")
|
|
68287
|
+
};
|
|
68288
|
+
default: throw Error(`Unsupported serialize stack item type: ${item.type}`);
|
|
68289
|
+
}
|
|
68290
|
+
}
|
|
68291
|
+
function SerializeStack(list) {
|
|
68292
|
+
let stack = [];
|
|
68293
|
+
for (let item of list) stack.push(SerializeStackItem(item));
|
|
68294
|
+
return stack;
|
|
68295
|
+
}
|
|
68296
|
+
|
|
68246
68297
|
//#endregion
|
|
68247
68298
|
//#region ../walletkit/dist/esm/utils/version.js
|
|
68248
68299
|
/**
|
|
@@ -68277,7 +68328,7 @@ function createWalletId(network, address) {
|
|
|
68277
68328
|
}
|
|
68278
68329
|
|
|
68279
68330
|
//#endregion
|
|
68280
|
-
//#region ../walletkit/dist/esm/
|
|
68331
|
+
//#region ../walletkit/dist/esm/utils/assetHelpers.js
|
|
68281
68332
|
/**
|
|
68282
68333
|
* Copyright (c) TonTech.
|
|
68283
68334
|
*
|
|
@@ -68285,6 +68336,79 @@ function createWalletId(network, address) {
|
|
|
68285
68336
|
* LICENSE file in the root directory of this source tree.
|
|
68286
68337
|
*
|
|
68287
68338
|
*/
|
|
68339
|
+
/**
|
|
68340
|
+
* Gets the jetton wallet address for an owner
|
|
68341
|
+
*/
|
|
68342
|
+
async function getJettonWalletAddressFromClient(client, jettonAddress, ownerAddress) {
|
|
68343
|
+
if (!isValidAddress(jettonAddress)) throw new Error(`Invalid jetton address: ${jettonAddress}`);
|
|
68344
|
+
try {
|
|
68345
|
+
const parsedStack = ParseStack((await client.runGetMethod(jettonAddress, "get_wallet_address", SerializeStack([{
|
|
68346
|
+
type: "slice",
|
|
68347
|
+
cell: (0, import_dist$2.beginCell)().storeAddress(import_dist$2.Address.parse(ownerAddress)).endCell()
|
|
68348
|
+
}]))).stack);
|
|
68349
|
+
const jettonWalletAddress = parsedStack[0].type === "slice" || parsedStack[0].type === "cell" ? parsedStack[0].cell.asSlice().loadAddress() : null;
|
|
68350
|
+
if (!jettonWalletAddress) throw new Error("Failed to get jetton wallet address");
|
|
68351
|
+
return asAddressFriendly(jettonWalletAddress.toString());
|
|
68352
|
+
} catch (error) {
|
|
68353
|
+
throw new Error(`Failed to get jetton wallet address for ${jettonAddress}: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
68354
|
+
}
|
|
68355
|
+
}
|
|
68356
|
+
/**
|
|
68357
|
+
* Gets the jetton balance for an owner's jetton wallet
|
|
68358
|
+
*/
|
|
68359
|
+
async function getJettonBalanceFromClient(client, jettonWalletAddress) {
|
|
68360
|
+
try {
|
|
68361
|
+
const parsedStack = ParseStack((await client.runGetMethod(jettonWalletAddress, "get_wallet_data")).stack);
|
|
68362
|
+
return (parsedStack[0].type === "int" ? parsedStack[0].value : 0n).toString();
|
|
68363
|
+
} catch (_error) {
|
|
68364
|
+
return "0";
|
|
68365
|
+
}
|
|
68366
|
+
}
|
|
68367
|
+
/**
|
|
68368
|
+
* Gets jettons owned by an address
|
|
68369
|
+
*/
|
|
68370
|
+
async function getJettonsFromClient(client, ownerAddress, params) {
|
|
68371
|
+
return client.jettonsByOwnerAddress({
|
|
68372
|
+
ownerAddress,
|
|
68373
|
+
offset: params?.pagination.offset,
|
|
68374
|
+
limit: params?.pagination.limit
|
|
68375
|
+
});
|
|
68376
|
+
}
|
|
68377
|
+
/**
|
|
68378
|
+
* Gets NFTs owned by an address
|
|
68379
|
+
*/
|
|
68380
|
+
async function getNftsFromClient(client, ownerAddress, params) {
|
|
68381
|
+
return client.nftItemsByOwner({
|
|
68382
|
+
ownerAddress,
|
|
68383
|
+
pagination: params.pagination
|
|
68384
|
+
});
|
|
68385
|
+
}
|
|
68386
|
+
/**
|
|
68387
|
+
* Gets a single NFT by address
|
|
68388
|
+
*/
|
|
68389
|
+
async function getNftFromClient(client, address) {
|
|
68390
|
+
const result = await client.nftItemsByAddress({ address });
|
|
68391
|
+
return result.nfts.length > 0 ? result.nfts[0] : null;
|
|
68392
|
+
}
|
|
68393
|
+
|
|
68394
|
+
//#endregion
|
|
68395
|
+
//#region ../walletkit/dist/esm/utils/messageBuilders.js
|
|
68396
|
+
/**
|
|
68397
|
+
* Copyright (c) TonTech.
|
|
68398
|
+
*
|
|
68399
|
+
* This source code is licensed under the MIT license found in the
|
|
68400
|
+
* LICENSE file in the root directory of this source tree.
|
|
68401
|
+
*
|
|
68402
|
+
*/
|
|
68403
|
+
/** Default gas fee for jetton transfers (0.05 TON) */
|
|
68404
|
+
const DEFAULT_JETTON_GAS_FEE = "50000000";
|
|
68405
|
+
/** Default gas fee for NFT transfers (0.1 TON) */
|
|
68406
|
+
const DEFAULT_NFT_GAS_FEE = "100000000";
|
|
68407
|
+
/** Default forward amount for jetton/NFT transfers (1 nanoton) */
|
|
68408
|
+
const DEFAULT_FORWARD_AMOUNT = 1n;
|
|
68409
|
+
/**
|
|
68410
|
+
* Stores a jetton transfer message into a builder
|
|
68411
|
+
*/
|
|
68288
68412
|
function storeJettonTransferMessage(src) {
|
|
68289
68413
|
return (builder) => {
|
|
68290
68414
|
builder.storeUint(Number(OpCode.JettonTransfer), 32);
|
|
@@ -68297,28 +68421,119 @@ function storeJettonTransferMessage(src) {
|
|
|
68297
68421
|
builder.storeMaybeRef(src.forwardPayload);
|
|
68298
68422
|
};
|
|
68299
68423
|
}
|
|
68300
|
-
|
|
68301
|
-
|
|
68302
|
-
|
|
68303
|
-
|
|
68304
|
-
|
|
68305
|
-
|
|
68306
|
-
|
|
68424
|
+
/**
|
|
68425
|
+
* Creates a jetton transfer payload cell
|
|
68426
|
+
*/
|
|
68427
|
+
function createJettonTransferPayload(params) {
|
|
68428
|
+
const forwardPayload = params.comment ? createCommentPayload(params.comment) : null;
|
|
68429
|
+
return (0, import_dist$2.beginCell)().store(storeJettonTransferMessage({
|
|
68430
|
+
queryId: params.queryId ?? 0n,
|
|
68431
|
+
amount: params.amount,
|
|
68432
|
+
destination: import_dist$2.Address.parse(params.destination),
|
|
68433
|
+
responseDestination: import_dist$2.Address.parse(params.responseDestination),
|
|
68434
|
+
customPayload: params.customPayload ?? null,
|
|
68435
|
+
forwardAmount: params.forwardAmount ?? DEFAULT_FORWARD_AMOUNT,
|
|
68436
|
+
forwardPayload
|
|
68437
|
+
})).endCell();
|
|
68438
|
+
}
|
|
68439
|
+
/**
|
|
68440
|
+
* Stores an NFT transfer message into a builder
|
|
68441
|
+
*/
|
|
68442
|
+
function storeNftTransferMessage(message) {
|
|
68443
|
+
return (builder) => {
|
|
68444
|
+
builder.storeUint(Number(OpCode.NftTransfer), 32);
|
|
68445
|
+
builder.storeUint(message.queryId, 64);
|
|
68446
|
+
builder.storeAddress(message.newOwner);
|
|
68447
|
+
builder.storeAddress(message.responseDestination);
|
|
68448
|
+
builder.storeMaybeRef(message.customPayload);
|
|
68449
|
+
builder.storeCoins(message.forwardAmount);
|
|
68450
|
+
builder.storeMaybeRef(message.forwardPayload);
|
|
68451
|
+
};
|
|
68452
|
+
}
|
|
68453
|
+
/**
|
|
68454
|
+
* Creates an NFT transfer payload cell
|
|
68455
|
+
*/
|
|
68456
|
+
function createNftTransferPayload(params) {
|
|
68457
|
+
const forwardPayload = params.comment ? createCommentPayload(params.comment) : null;
|
|
68458
|
+
return (0, import_dist$2.beginCell)().store(storeNftTransferMessage({
|
|
68459
|
+
queryId: params.queryId ?? 0n,
|
|
68460
|
+
newOwner: import_dist$2.Address.parse(params.newOwner),
|
|
68461
|
+
responseDestination: import_dist$2.Address.parse(params.responseDestination),
|
|
68462
|
+
customPayload: params.customPayload ?? null,
|
|
68463
|
+
forwardAmount: params.forwardAmount ?? DEFAULT_FORWARD_AMOUNT,
|
|
68464
|
+
forwardPayload
|
|
68465
|
+
})).endCell();
|
|
68466
|
+
}
|
|
68467
|
+
/**
|
|
68468
|
+
* Creates an NFT transfer payload cell from raw parameters
|
|
68469
|
+
* Handles string/Address conversion automatically
|
|
68470
|
+
*/
|
|
68471
|
+
function createNftTransferRawPayload(params) {
|
|
68472
|
+
const transferMessage = {
|
|
68473
|
+
queryId: BigInt(params.queryId),
|
|
68474
|
+
newOwner: typeof params.newOwner === "string" ? import_dist$2.Address.parse(params.newOwner) : params.newOwner,
|
|
68475
|
+
responseDestination: params.responseDestination ? typeof params.responseDestination === "string" ? import_dist$2.Address.parse(params.responseDestination) : params.responseDestination : null,
|
|
68476
|
+
customPayload: params.customPayload ? typeof params.customPayload === "string" ? import_dist$2.Cell.fromBase64(params.customPayload) : params.customPayload : null,
|
|
68477
|
+
forwardAmount: BigInt(params.forwardAmount),
|
|
68478
|
+
forwardPayload: params.forwardPayload ? typeof params.forwardPayload === "string" ? import_dist$2.Cell.fromBase64(params.forwardPayload) : params.forwardPayload : null
|
|
68479
|
+
};
|
|
68480
|
+
return (0, import_dist$2.beginCell)().store(storeNftTransferMessage(transferMessage)).endCell();
|
|
68481
|
+
}
|
|
68482
|
+
/**
|
|
68483
|
+
* Creates a comment payload cell (op code 0 + text)
|
|
68484
|
+
*/
|
|
68485
|
+
function createCommentPayload(comment) {
|
|
68486
|
+
return (0, import_dist$2.beginCell)().storeUint(0, 32).storeStringTail(comment).endCell();
|
|
68487
|
+
}
|
|
68488
|
+
/**
|
|
68489
|
+
* Creates a comment payload as base64 string
|
|
68490
|
+
*/
|
|
68491
|
+
function createCommentPayloadBase64(comment) {
|
|
68492
|
+
return createCommentPayload(comment).toBoc().toString("base64");
|
|
68493
|
+
}
|
|
68494
|
+
/**
|
|
68495
|
+
* Creates a standard transfer transaction request with default send mode flags
|
|
68496
|
+
*/
|
|
68497
|
+
function createTransferTransaction(params) {
|
|
68498
|
+
const message = {
|
|
68499
|
+
address: params.targetAddress,
|
|
68500
|
+
amount: params.amount,
|
|
68501
|
+
payload: params.payload.toBoc().toString("base64"),
|
|
68502
|
+
stateInit: void 0,
|
|
68503
|
+
extraCurrency: void 0,
|
|
68504
|
+
mode: { flags: [SendModeFlag.IGNORE_ERRORS, SendModeFlag.PAY_GAS_SEPARATELY] }
|
|
68505
|
+
};
|
|
68506
|
+
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
68507
|
+
return {
|
|
68508
|
+
messages: [message],
|
|
68509
|
+
fromAddress: params.fromAddress
|
|
68510
|
+
};
|
|
68511
|
+
}
|
|
68512
|
+
|
|
68513
|
+
//#endregion
|
|
68514
|
+
//#region ../walletkit/dist/esm/core/wallet/extensions/ton.js
|
|
68515
|
+
/**
|
|
68516
|
+
* Copyright (c) TonTech.
|
|
68517
|
+
*
|
|
68518
|
+
* This source code is licensed under the MIT license found in the
|
|
68519
|
+
* LICENSE file in the root directory of this source tree.
|
|
68520
|
+
*
|
|
68521
|
+
*/
|
|
68522
|
+
const log$11 = globalLogger.createChild("WalletTonClass");
|
|
68523
|
+
var WalletTonClass = class {
|
|
68524
|
+
async createTransferTonTransaction(param) {
|
|
68525
|
+
if (!isValidAddress(param.recipientAddress)) throw new Error(`Invalid to address: ${param.recipientAddress}`);
|
|
68526
|
+
if (!isValidNanotonAmount(param.transferAmount)) throw new Error(`Invalid amount: ${param.transferAmount}`);
|
|
68527
|
+
let body;
|
|
68528
|
+
if (param.payload) body = param.payload;
|
|
68529
|
+
else if (param.comment) body = createCommentPayloadBase64(param.comment);
|
|
68307
68530
|
const message = {
|
|
68308
|
-
address:
|
|
68309
|
-
amount:
|
|
68310
|
-
payload:
|
|
68311
|
-
|
|
68312
|
-
|
|
68313
|
-
|
|
68314
|
-
responseDestination: import_dist$2.Address.parse(this.getAddress()),
|
|
68315
|
-
customPayload: null,
|
|
68316
|
-
forwardAmount: 1n,
|
|
68317
|
-
forwardPayload
|
|
68318
|
-
})).endCell().toBoc().toString("base64"),
|
|
68319
|
-
stateInit: void 0,
|
|
68320
|
-
extraCurrency: void 0,
|
|
68321
|
-
mode: { flags: [SendModeFlag.IGNORE_ERRORS, SendModeFlag.PAY_GAS_SEPARATELY] }
|
|
68531
|
+
address: param.recipientAddress,
|
|
68532
|
+
amount: param.transferAmount,
|
|
68533
|
+
payload: body,
|
|
68534
|
+
stateInit: param.stateInit,
|
|
68535
|
+
extraCurrency: param.extraCurrency,
|
|
68536
|
+
mode: param.mode
|
|
68322
68537
|
};
|
|
68323
68538
|
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
68324
68539
|
return {
|
|
@@ -68326,36 +68541,87 @@ var WalletJettonClass = class {
|
|
|
68326
68541
|
fromAddress: this.getAddress()
|
|
68327
68542
|
};
|
|
68328
68543
|
}
|
|
68329
|
-
async
|
|
68330
|
-
const
|
|
68331
|
-
|
|
68332
|
-
|
|
68333
|
-
|
|
68334
|
-
|
|
68335
|
-
|
|
68544
|
+
async createTransferMultiTonTransaction(params) {
|
|
68545
|
+
const messages = [];
|
|
68546
|
+
for (const param of params) {
|
|
68547
|
+
if (!isValidAddress(param.recipientAddress)) throw new Error(`Invalid to address: ${param.recipientAddress}`);
|
|
68548
|
+
if (!isValidNanotonAmount(param.transferAmount)) throw new Error(`Invalid amount: ${param.transferAmount}`);
|
|
68549
|
+
let body;
|
|
68550
|
+
if (param.payload) body = param.payload;
|
|
68551
|
+
else if (param.comment) body = createCommentPayloadBase64(param.comment);
|
|
68552
|
+
const message = {
|
|
68553
|
+
address: param.recipientAddress,
|
|
68554
|
+
amount: param.transferAmount,
|
|
68555
|
+
payload: body,
|
|
68556
|
+
stateInit: param.stateInit,
|
|
68557
|
+
extraCurrency: param.extraCurrency,
|
|
68558
|
+
mode: param.mode
|
|
68559
|
+
};
|
|
68560
|
+
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
68561
|
+
messages.push(message);
|
|
68336
68562
|
}
|
|
68563
|
+
return {
|
|
68564
|
+
messages,
|
|
68565
|
+
fromAddress: this.getAddress()
|
|
68566
|
+
};
|
|
68337
68567
|
}
|
|
68338
|
-
async
|
|
68339
|
-
|
|
68568
|
+
async getTransactionPreview(param) {
|
|
68569
|
+
const transaction = await param;
|
|
68570
|
+
return await CallForSuccess(() => createTransactionPreview(this.client, transaction, this));
|
|
68571
|
+
}
|
|
68572
|
+
async sendTransaction(request) {
|
|
68340
68573
|
try {
|
|
68341
|
-
const
|
|
68342
|
-
|
|
68343
|
-
|
|
68344
|
-
}]))).stack);
|
|
68345
|
-
const jettonWalletAddress = parsedStack[0].type === "slice" || parsedStack[0].type === "cell" ? parsedStack[0].cell.asSlice().loadAddress() : null;
|
|
68346
|
-
if (!jettonWalletAddress) throw new Error("Failed to get jetton wallet address");
|
|
68347
|
-
return asAddressFriendly(jettonWalletAddress.toString());
|
|
68574
|
+
const boc = await this.getSignedSendTransaction(request);
|
|
68575
|
+
await CallForSuccess(() => this.getClient().sendBoc(boc));
|
|
68576
|
+
return { boc };
|
|
68348
68577
|
} catch (error) {
|
|
68349
|
-
|
|
68578
|
+
log$11.error("Failed to send transaction", { error });
|
|
68579
|
+
if (error instanceof WalletKitError) throw error;
|
|
68580
|
+
if (error?.message?.includes("Ledger device")) throw new WalletKitError(ERROR_CODES.LEDGER_DEVICE_ERROR, "Ledger device error", error);
|
|
68581
|
+
throw error;
|
|
68350
68582
|
}
|
|
68351
68583
|
}
|
|
68352
|
-
async
|
|
68353
|
-
return this.getClient().
|
|
68354
|
-
|
|
68355
|
-
|
|
68356
|
-
|
|
68584
|
+
async getBalance() {
|
|
68585
|
+
return await CallForSuccess(async () => this.getClient().getBalance(this.getAddress()));
|
|
68586
|
+
}
|
|
68587
|
+
};
|
|
68588
|
+
|
|
68589
|
+
//#endregion
|
|
68590
|
+
//#region ../walletkit/dist/esm/core/wallet/extensions/jetton.js
|
|
68591
|
+
/**
|
|
68592
|
+
* Copyright (c) TonTech.
|
|
68593
|
+
*
|
|
68594
|
+
* This source code is licensed under the MIT license found in the
|
|
68595
|
+
* LICENSE file in the root directory of this source tree.
|
|
68596
|
+
*
|
|
68597
|
+
*/
|
|
68598
|
+
var WalletJettonClass = class {
|
|
68599
|
+
async createTransferJettonTransaction(params) {
|
|
68600
|
+
if (!isValidAddress(params.recipientAddress)) throw new Error(`Invalid to address: ${params.recipientAddress}`);
|
|
68601
|
+
if (!isValidAddress(params.jettonAddress)) throw new Error(`Invalid jetton address: ${params.jettonAddress}`);
|
|
68602
|
+
if (!params.transferAmount || BigInt(params.transferAmount) <= 0n) throw new Error(`Invalid amount: ${params.transferAmount}`);
|
|
68603
|
+
return createTransferTransaction({
|
|
68604
|
+
targetAddress: await CallForSuccess(() => this.getJettonWalletAddress(params.jettonAddress)),
|
|
68605
|
+
amount: DEFAULT_JETTON_GAS_FEE,
|
|
68606
|
+
payload: createJettonTransferPayload({
|
|
68607
|
+
amount: BigInt(params.transferAmount),
|
|
68608
|
+
destination: params.recipientAddress,
|
|
68609
|
+
responseDestination: this.getAddress(),
|
|
68610
|
+
comment: params.comment
|
|
68611
|
+
}),
|
|
68612
|
+
fromAddress: this.getAddress()
|
|
68357
68613
|
});
|
|
68358
68614
|
}
|
|
68615
|
+
async getJettonBalance(jettonAddress) {
|
|
68616
|
+
const jettonWalletAddress = await this.getJettonWalletAddress(jettonAddress);
|
|
68617
|
+
return getJettonBalanceFromClient(this.getClient(), jettonWalletAddress);
|
|
68618
|
+
}
|
|
68619
|
+
async getJettonWalletAddress(jettonAddress) {
|
|
68620
|
+
return getJettonWalletAddressFromClient(this.getClient(), jettonAddress, this.getAddress());
|
|
68621
|
+
}
|
|
68622
|
+
async getJettons(params) {
|
|
68623
|
+
return getJettonsFromClient(this.getClient(), this.getAddress(), params);
|
|
68624
|
+
}
|
|
68359
68625
|
};
|
|
68360
68626
|
|
|
68361
68627
|
//#endregion
|
|
@@ -68367,76 +68633,41 @@ var WalletJettonClass = class {
|
|
|
68367
68633
|
* LICENSE file in the root directory of this source tree.
|
|
68368
68634
|
*
|
|
68369
68635
|
*/
|
|
68370
|
-
function storeNftTransferMessage(message) {
|
|
68371
|
-
return (builder) => {
|
|
68372
|
-
builder.storeUint(Number(OpCode.NftTransfer), 32);
|
|
68373
|
-
builder.storeUint(message.queryId, 64);
|
|
68374
|
-
builder.storeAddress(message.newOwner);
|
|
68375
|
-
builder.storeAddress(message.responseDestination);
|
|
68376
|
-
builder.storeMaybeRef(message.customPayload);
|
|
68377
|
-
builder.storeCoins(message.forwardAmount);
|
|
68378
|
-
builder.storeMaybeRef(message.forwardPayload);
|
|
68379
|
-
};
|
|
68380
|
-
}
|
|
68381
68636
|
var WalletNftClass = class {
|
|
68382
68637
|
async getNfts(params) {
|
|
68383
|
-
return
|
|
68384
|
-
ownerAddress: this.getAddress(),
|
|
68385
|
-
pagination: params.pagination
|
|
68386
|
-
});
|
|
68638
|
+
return getNftsFromClient(this.getClient(), this.getAddress(), params);
|
|
68387
68639
|
}
|
|
68388
68640
|
async getNft(address) {
|
|
68389
|
-
|
|
68390
|
-
if (result.nfts.length > 0) return result.nfts[0];
|
|
68391
|
-
return null;
|
|
68641
|
+
return getNftFromClient(this.getClient(), address);
|
|
68392
68642
|
}
|
|
68393
|
-
async createTransferNftTransaction(
|
|
68394
|
-
const
|
|
68395
|
-
|
|
68396
|
-
|
|
68397
|
-
|
|
68398
|
-
|
|
68399
|
-
|
|
68400
|
-
|
|
68401
|
-
|
|
68402
|
-
|
|
68403
|
-
const message = {
|
|
68404
|
-
address: nftTransferMessage.nftAddress,
|
|
68405
|
-
amount: nftTransferMessage.transferAmount?.toString() ?? "100000000",
|
|
68406
|
-
payload: nftPayload.toBoc().toString("base64"),
|
|
68407
|
-
stateInit: void 0,
|
|
68408
|
-
extraCurrency: void 0,
|
|
68409
|
-
mode: { flags: [SendModeFlag.IGNORE_ERRORS, SendModeFlag.PAY_GAS_SEPARATELY] }
|
|
68410
|
-
};
|
|
68411
|
-
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
68412
|
-
return {
|
|
68413
|
-
messages: [message],
|
|
68643
|
+
async createTransferNftTransaction(params) {
|
|
68644
|
+
const nftPayload = createNftTransferPayload({
|
|
68645
|
+
newOwner: params.recipientAddress,
|
|
68646
|
+
responseDestination: this.getAddress(),
|
|
68647
|
+
comment: params.comment
|
|
68648
|
+
});
|
|
68649
|
+
return createTransferTransaction({
|
|
68650
|
+
targetAddress: params.nftAddress,
|
|
68651
|
+
amount: params.transferAmount?.toString() ?? DEFAULT_NFT_GAS_FEE,
|
|
68652
|
+
payload: nftPayload,
|
|
68414
68653
|
fromAddress: this.getAddress()
|
|
68415
|
-
};
|
|
68654
|
+
});
|
|
68416
68655
|
}
|
|
68417
68656
|
async createTransferNftRawTransaction(params) {
|
|
68418
|
-
const
|
|
68419
|
-
queryId:
|
|
68420
|
-
newOwner:
|
|
68421
|
-
responseDestination: params.message.responseDestination
|
|
68422
|
-
customPayload: params.message.customPayload
|
|
68423
|
-
forwardAmount:
|
|
68424
|
-
forwardPayload: params.message.forwardPayload
|
|
68425
|
-
};
|
|
68426
|
-
|
|
68427
|
-
|
|
68428
|
-
address: params.nftAddress,
|
|
68657
|
+
const nftPayload = createNftTransferRawPayload({
|
|
68658
|
+
queryId: params.message.queryId,
|
|
68659
|
+
newOwner: params.message.newOwner,
|
|
68660
|
+
responseDestination: params.message.responseDestination,
|
|
68661
|
+
customPayload: params.message.customPayload,
|
|
68662
|
+
forwardAmount: params.message.forwardAmount,
|
|
68663
|
+
forwardPayload: params.message.forwardPayload
|
|
68664
|
+
});
|
|
68665
|
+
return createTransferTransaction({
|
|
68666
|
+
targetAddress: params.nftAddress,
|
|
68429
68667
|
amount: params.transferAmount.toString(),
|
|
68430
|
-
payload: nftPayload
|
|
68431
|
-
stateInit: void 0,
|
|
68432
|
-
extraCurrency: void 0,
|
|
68433
|
-
mode: { flags: [SendModeFlag.IGNORE_ERRORS, SendModeFlag.PAY_GAS_SEPARATELY] }
|
|
68434
|
-
};
|
|
68435
|
-
if (!validateTransactionMessage(message, false).isValid) throw new Error(`Invalid transaction message: ${JSON.stringify(message)}`);
|
|
68436
|
-
return {
|
|
68437
|
-
messages: [message],
|
|
68668
|
+
payload: nftPayload,
|
|
68438
68669
|
fromAddress: this.getAddress()
|
|
68439
|
-
};
|
|
68670
|
+
});
|
|
68440
68671
|
}
|
|
68441
68672
|
};
|
|
68442
68673
|
|
|
@@ -68582,7 +68813,7 @@ async function wrapWalletInterface(wallet) {
|
|
|
68582
68813
|
}
|
|
68583
68814
|
|
|
68584
68815
|
//#endregion
|
|
68585
|
-
//#region
|
|
68816
|
+
//#region ../../node_modules/lru-cache/dist/esm/index.js
|
|
68586
68817
|
/**
|
|
68587
68818
|
* @module LRUCache
|
|
68588
68819
|
*/
|
|
@@ -70079,7 +70310,9 @@ var JettonsManager = class {
|
|
|
70079
70310
|
* }
|
|
70080
70311
|
* ```
|
|
70081
70312
|
*/
|
|
70082
|
-
var SwapProvider = class {
|
|
70313
|
+
var SwapProvider = class {
|
|
70314
|
+
type = "swap";
|
|
70315
|
+
};
|
|
70083
70316
|
|
|
70084
70317
|
//#endregion
|
|
70085
70318
|
//#region ../walletkit/dist/esm/defi/errors.js
|
|
@@ -70218,19 +70451,19 @@ var SwapManager = class extends DefiManager {
|
|
|
70218
70451
|
/**
|
|
70219
70452
|
* Get a quote for swapping tokens
|
|
70220
70453
|
* @param params - Quote parameters
|
|
70221
|
-
* @param
|
|
70454
|
+
* @param providerId - Optional provider name to use
|
|
70222
70455
|
* @returns Promise resolving to swap quote
|
|
70223
70456
|
*/
|
|
70224
|
-
async getQuote(params,
|
|
70457
|
+
async getQuote(params, providerId) {
|
|
70225
70458
|
log$8.debug("Getting swap quote", {
|
|
70226
|
-
fromToken: params.
|
|
70227
|
-
toToken: params.
|
|
70459
|
+
fromToken: params.from,
|
|
70460
|
+
toToken: params.to,
|
|
70228
70461
|
amount: params.amount,
|
|
70229
70462
|
isReverseSwap: params.isReverseSwap,
|
|
70230
|
-
|
|
70463
|
+
providerId: providerId || this.defaultProviderId
|
|
70231
70464
|
});
|
|
70232
70465
|
try {
|
|
70233
|
-
const quote = await this.getProvider(
|
|
70466
|
+
const quote = await this.getProvider(providerId || this.defaultProviderId).getQuote(params);
|
|
70234
70467
|
log$8.debug("Received swap quote", {
|
|
70235
70468
|
fromAmount: quote.fromAmount,
|
|
70236
70469
|
toAmount: quote.toAmount,
|
|
@@ -70248,16 +70481,16 @@ var SwapManager = class extends DefiManager {
|
|
|
70248
70481
|
/**
|
|
70249
70482
|
* Build a transaction for executing a swap
|
|
70250
70483
|
* @param params - Swap parameters including quote
|
|
70251
|
-
* @param provider - Optional provider name to use
|
|
70252
70484
|
* @returns Promise resolving to transaction request
|
|
70253
70485
|
*/
|
|
70254
|
-
async buildSwapTransaction(params
|
|
70486
|
+
async buildSwapTransaction(params) {
|
|
70487
|
+
const providerId = params.quote.providerId || this.defaultProviderId;
|
|
70255
70488
|
log$8.debug("Building swap transaction", {
|
|
70256
|
-
|
|
70257
|
-
|
|
70489
|
+
providerId,
|
|
70490
|
+
userAddress: params.userAddress
|
|
70258
70491
|
});
|
|
70259
70492
|
try {
|
|
70260
|
-
const transaction = await this.getProvider(
|
|
70493
|
+
const transaction = await this.getProvider(providerId).buildSwapTransaction(params);
|
|
70261
70494
|
log$8.debug("Built swap transaction", params.quote);
|
|
70262
70495
|
return transaction;
|
|
70263
70496
|
} catch (error) {
|
|
@@ -71388,7 +71621,7 @@ const log$4 = globalLogger.createChild("NetworkManager");
|
|
|
71388
71621
|
* Each network (identified by CHAIN) has its own ApiClient instance.
|
|
71389
71622
|
* At least one network must be configured.
|
|
71390
71623
|
*/
|
|
71391
|
-
var
|
|
71624
|
+
var KitNetworkManager = class {
|
|
71392
71625
|
clients = /* @__PURE__ */ new Map();
|
|
71393
71626
|
constructor(options) {
|
|
71394
71627
|
this.initializeClients(options);
|
|
@@ -71512,7 +71745,7 @@ var TonWalletKit = class {
|
|
|
71512
71745
|
...options?.analytics?.appInfo
|
|
71513
71746
|
}
|
|
71514
71747
|
});
|
|
71515
|
-
this.networkManager = new
|
|
71748
|
+
this.networkManager = new KitNetworkManager(options);
|
|
71516
71749
|
this.eventEmitter = new EventEmitter$2();
|
|
71517
71750
|
this.initializer = new Initializer(options, this.eventEmitter, this.analyticsManager);
|
|
71518
71751
|
this.initializationPromise = this.initialize();
|
|
@@ -72192,7 +72425,7 @@ var WalletV5R1Adapter = class WalletV5R1Adapter {
|
|
|
72192
72425
|
if (input.validUntil) {
|
|
72193
72426
|
const now = Math.floor(Date.now() / 1e3);
|
|
72194
72427
|
const maxValidUntil = now + 600;
|
|
72195
|
-
if (input.validUntil < now) throw new WalletKitError(ERROR_CODES.VALIDATION_ERROR, "Transaction
|
|
72428
|
+
if (input.validUntil < now) throw new WalletKitError(ERROR_CODES.VALIDATION_ERROR, "Transaction validUntil timestamp is in the past", void 0, {
|
|
72196
72429
|
validUntil: input.validUntil,
|
|
72197
72430
|
currentTime: now
|
|
72198
72431
|
});
|
|
@@ -72458,6 +72691,72 @@ const WalletV4R2CodeCell = import_dist$2.Cell.fromBoc(Buffer.from("te6ccgECFAEAA
|
|
|
72458
72691
|
*/
|
|
72459
72692
|
const log$1 = globalLogger.createChild("WalletV4R2Adapter");
|
|
72460
72693
|
|
|
72694
|
+
//#endregion
|
|
72695
|
+
//#region ../walletkit/dist/esm/utils/units.js
|
|
72696
|
+
/**
|
|
72697
|
+
* Copyright (c) TonTech.
|
|
72698
|
+
*
|
|
72699
|
+
* This source code is licensed under the MIT license found in the
|
|
72700
|
+
* LICENSE file in the root directory of this source tree.
|
|
72701
|
+
*
|
|
72702
|
+
*/
|
|
72703
|
+
/**
|
|
72704
|
+
* Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
|
|
72705
|
+
*
|
|
72706
|
+
* - Docs: https://viem.sh/docs/utilities/parseUnits
|
|
72707
|
+
*
|
|
72708
|
+
* @example
|
|
72709
|
+
* import { parseUnits } from 'viem'
|
|
72710
|
+
*
|
|
72711
|
+
* parseUnits('420', 9)
|
|
72712
|
+
* // 420000000000n
|
|
72713
|
+
*/
|
|
72714
|
+
function parseUnits(value, decimals) {
|
|
72715
|
+
let [integer, fraction = "0"] = value.split(".");
|
|
72716
|
+
const negative = integer.startsWith("-");
|
|
72717
|
+
if (negative) integer = integer.slice(1);
|
|
72718
|
+
fraction = fraction.replace(/(0+)$/, "");
|
|
72719
|
+
if (decimals === 0) {
|
|
72720
|
+
if (Math.round(Number(`.${fraction}`)) === 1) integer = `${BigInt(integer) + 1n}`;
|
|
72721
|
+
fraction = "";
|
|
72722
|
+
} else if (fraction.length > decimals) {
|
|
72723
|
+
const [left, unit, right] = [
|
|
72724
|
+
fraction.slice(0, decimals - 1),
|
|
72725
|
+
fraction.slice(decimals - 1, decimals),
|
|
72726
|
+
fraction.slice(decimals)
|
|
72727
|
+
];
|
|
72728
|
+
const rounded = Math.round(Number(`${unit}.${right}`));
|
|
72729
|
+
if (rounded > 9) fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, "0");
|
|
72730
|
+
else fraction = `${left}${rounded}`;
|
|
72731
|
+
if (fraction.length > decimals) {
|
|
72732
|
+
fraction = fraction.slice(1);
|
|
72733
|
+
integer = `${BigInt(integer) + 1n}`;
|
|
72734
|
+
}
|
|
72735
|
+
fraction = fraction.slice(0, decimals);
|
|
72736
|
+
} else fraction = fraction.padEnd(decimals, "0");
|
|
72737
|
+
return BigInt(`${negative ? "-" : ""}${integer}${fraction}`);
|
|
72738
|
+
}
|
|
72739
|
+
/**
|
|
72740
|
+
* Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number..
|
|
72741
|
+
*
|
|
72742
|
+
* - Docs: https://viem.sh/docs/utilities/formatUnits
|
|
72743
|
+
*
|
|
72744
|
+
* @example
|
|
72745
|
+
* import { formatUnits } from 'viem'
|
|
72746
|
+
*
|
|
72747
|
+
* formatUnits(420000000000n, 9)
|
|
72748
|
+
* // '420'
|
|
72749
|
+
*/
|
|
72750
|
+
function formatUnits(value, decimals) {
|
|
72751
|
+
let display = value.toString();
|
|
72752
|
+
const negative = display.startsWith("-");
|
|
72753
|
+
if (negative) display = display.slice(1);
|
|
72754
|
+
display = display.padStart(decimals, "0");
|
|
72755
|
+
let [integer, fraction] = [display.slice(0, display.length - decimals), display.slice(display.length - decimals)];
|
|
72756
|
+
fraction = fraction.replace(/(0+)$/, "");
|
|
72757
|
+
return `${negative ? "-" : ""}${integer || "0"}${fraction ? `.${fraction}` : ""}`;
|
|
72758
|
+
}
|
|
72759
|
+
|
|
72461
72760
|
//#endregion
|
|
72462
72761
|
//#region ../../node_modules/@ston-fi/omniston-sdk/node_modules/rxjs/dist/cjs/internal/util/isFunction.js
|
|
72463
72762
|
var require_isFunction = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -84690,7 +84989,7 @@ var require_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
84690
84989
|
}));
|
|
84691
84990
|
|
|
84692
84991
|
//#endregion
|
|
84693
|
-
//#region ../../node_modules
|
|
84992
|
+
//#region ../../node_modules/json-rpc-2.0/dist/models.js
|
|
84694
84993
|
var require_models = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
84695
84994
|
var __extends = exports && exports.__extends || (function() {
|
|
84696
84995
|
var extendStatics = function(d, b) {
|
|
@@ -84799,7 +85098,7 @@ var require_models = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
84799
85098
|
}));
|
|
84800
85099
|
|
|
84801
85100
|
//#endregion
|
|
84802
|
-
//#region ../../node_modules
|
|
85101
|
+
//#region ../../node_modules/json-rpc-2.0/dist/internal.js
|
|
84803
85102
|
var require_internal = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
84804
85103
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84805
85104
|
exports.DefaultErrorCode = void 0;
|
|
@@ -84807,7 +85106,7 @@ var require_internal = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
84807
85106
|
}));
|
|
84808
85107
|
|
|
84809
85108
|
//#endregion
|
|
84810
|
-
//#region ../../node_modules
|
|
85109
|
+
//#region ../../node_modules/json-rpc-2.0/dist/client.js
|
|
84811
85110
|
var require_client = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
84812
85111
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
84813
85112
|
function adopt(value) {
|
|
@@ -85060,13 +85359,13 @@ var require_client = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
85060
85359
|
}));
|
|
85061
85360
|
|
|
85062
85361
|
//#endregion
|
|
85063
|
-
//#region ../../node_modules
|
|
85362
|
+
//#region ../../node_modules/json-rpc-2.0/dist/interfaces.js
|
|
85064
85363
|
var require_interfaces = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
85065
85364
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85066
85365
|
}));
|
|
85067
85366
|
|
|
85068
85367
|
//#endregion
|
|
85069
|
-
//#region ../../node_modules
|
|
85368
|
+
//#region ../../node_modules/json-rpc-2.0/dist/server.js
|
|
85070
85369
|
var require_server = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
85071
85370
|
var __assign = exports && exports.__assign || function() {
|
|
85072
85371
|
__assign = Object.assign || function(t) {
|
|
@@ -85363,7 +85662,7 @@ var require_server = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
85363
85662
|
}));
|
|
85364
85663
|
|
|
85365
85664
|
//#endregion
|
|
85366
|
-
//#region ../../node_modules
|
|
85665
|
+
//#region ../../node_modules/json-rpc-2.0/dist/server-and-client.js
|
|
85367
85666
|
var require_server_and_client = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
85368
85667
|
var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
85369
85668
|
function adopt(value) {
|
|
@@ -85551,7 +85850,7 @@ var require_server_and_client = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
85551
85850
|
}));
|
|
85552
85851
|
|
|
85553
85852
|
//#endregion
|
|
85554
|
-
//#region ../../node_modules
|
|
85853
|
+
//#region ../../node_modules/json-rpc-2.0/dist/index.js
|
|
85555
85854
|
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
85556
85855
|
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
85557
85856
|
if (k2 === void 0) k2 = k;
|
|
@@ -87573,20 +87872,23 @@ function unwrapObservable(originalMethod) {
|
|
|
87573
87872
|
*
|
|
87574
87873
|
*/
|
|
87575
87874
|
const tokenToAddress = (token) => {
|
|
87576
|
-
if (token.
|
|
87577
|
-
return import_dist$2.Address.parse(token.
|
|
87875
|
+
if (token.address === "ton") return "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
|
|
87876
|
+
return import_dist$2.Address.parse(token.address).toRawString();
|
|
87578
87877
|
};
|
|
87579
|
-
const addressToToken = (address) => {
|
|
87580
|
-
if (address === "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c") return {
|
|
87878
|
+
const addressToToken = (address, decimals = 9) => {
|
|
87879
|
+
if (address === "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c") return {
|
|
87880
|
+
address: "ton",
|
|
87881
|
+
decimals: 9
|
|
87882
|
+
};
|
|
87581
87883
|
try {
|
|
87582
87884
|
return {
|
|
87583
|
-
|
|
87584
|
-
|
|
87885
|
+
address: import_dist$2.Address.parseRaw(address).toString(),
|
|
87886
|
+
decimals
|
|
87585
87887
|
};
|
|
87586
87888
|
} catch {
|
|
87587
87889
|
return {
|
|
87588
|
-
|
|
87589
|
-
|
|
87890
|
+
address,
|
|
87891
|
+
decimals
|
|
87590
87892
|
};
|
|
87591
87893
|
}
|
|
87592
87894
|
};
|
|
@@ -87675,20 +87977,20 @@ var OmnistonSwapProvider = class extends SwapProvider {
|
|
|
87675
87977
|
}
|
|
87676
87978
|
async getQuote(params) {
|
|
87677
87979
|
log.debug("Getting Omniston quote", {
|
|
87678
|
-
fromToken: params.
|
|
87679
|
-
toToken: params.
|
|
87980
|
+
fromToken: params.from,
|
|
87981
|
+
toToken: params.to,
|
|
87680
87982
|
amount: params.amount,
|
|
87681
87983
|
isReverseSwap: params.isReverseSwap
|
|
87682
87984
|
});
|
|
87683
87985
|
try {
|
|
87684
|
-
const bidAssetAddress = tokenToAddress(params.
|
|
87685
|
-
const askAssetAddress = tokenToAddress(params.
|
|
87986
|
+
const bidAssetAddress = tokenToAddress(params.from);
|
|
87987
|
+
const askAssetAddress = tokenToAddress(params.to);
|
|
87686
87988
|
const slippageBps = params.slippageBps ?? this.defaultSlippageBps;
|
|
87687
87989
|
const referrerAddress = params.providerOptions?.referrerAddress ?? this.referrerAddress;
|
|
87688
87990
|
const referrerFeeBps = params.providerOptions?.referrerFeeBps ?? this.referrerFeeBps;
|
|
87689
87991
|
const flexibleReferrerFee = params.providerOptions?.flexibleReferrerFee ?? this.flexibleReferrerFee;
|
|
87690
87992
|
const quoteRequest = {
|
|
87691
|
-
amount: params.isReverseSwap ? { askUnits: params.amount } : { bidUnits: params.amount },
|
|
87993
|
+
amount: params.isReverseSwap ? { askUnits: parseUnits(params.amount, params.to.decimals).toString() } : { bidUnits: parseUnits(params.amount, params.from.decimals).toString() },
|
|
87692
87994
|
settlementMethods: [SettlementMethod.SETTLEMENT_METHOD_SWAP],
|
|
87693
87995
|
bidAssetAddress: toOmnistonAddress(bidAssetAddress, params.network),
|
|
87694
87996
|
askAssetAddress: toOmnistonAddress(askAssetAddress, params.network),
|
|
@@ -87703,7 +88005,7 @@ var OmnistonSwapProvider = class extends SwapProvider {
|
|
|
87703
88005
|
};
|
|
87704
88006
|
const quoteEvent = await new Promise((resolve, reject) => {
|
|
87705
88007
|
let isSettled = false;
|
|
87706
|
-
log.debug("Requesting quote");
|
|
88008
|
+
log.debug("Requesting quote", { quoteRequest });
|
|
87707
88009
|
const timeoutId = setTimeout(() => {
|
|
87708
88010
|
log.debug("Timeout reached");
|
|
87709
88011
|
if (!isSettled) {
|
|
@@ -87821,13 +88123,16 @@ var OmnistonSwapProvider = class extends SwapProvider {
|
|
|
87821
88123
|
token: addressToToken(quote.referrerFeeAsset.address)
|
|
87822
88124
|
});
|
|
87823
88125
|
return {
|
|
88126
|
+
rawFromAmount: quote.bidUnits,
|
|
88127
|
+
rawToAmount: quote.askUnits,
|
|
88128
|
+
rawMinReceived: quote.askUnits,
|
|
88129
|
+
fromAmount: formatUnits(quote.bidUnits, params.from.decimals),
|
|
88130
|
+
toAmount: formatUnits(quote.askUnits, params.to.decimals),
|
|
88131
|
+
minReceived: formatUnits(quote.askUnits, params.to.decimals),
|
|
87824
88132
|
metadata,
|
|
87825
88133
|
providerId: this.providerId,
|
|
87826
|
-
fromToken: params.
|
|
87827
|
-
toToken: params.
|
|
87828
|
-
fromAmount: quote.bidUnits,
|
|
87829
|
-
toAmount: quote.askUnits,
|
|
87830
|
-
minReceived: quote.askUnits,
|
|
88134
|
+
fromToken: params.from,
|
|
88135
|
+
toToken: params.to,
|
|
87831
88136
|
network: params.network,
|
|
87832
88137
|
expiresAt: quote.tradeStartDeadline ? quote.tradeStartDeadline : void 0,
|
|
87833
88138
|
fee: fee?.length ? fee : void 0
|
|
@@ -88051,18 +88356,27 @@ var McpWalletService = class McpWalletService {
|
|
|
88051
88356
|
}
|
|
88052
88357
|
/**
|
|
88053
88358
|
* Get swap quote with transaction params ready to execute
|
|
88359
|
+
* @param fromToken Token to swap from ("TON" or jetton address)
|
|
88360
|
+
* @param toToken Token to swap to ("TON" or jetton address)
|
|
88361
|
+
* @param amount Amount to swap in human-readable format (e.g., "1.5" for 1.5 TON)
|
|
88362
|
+
* @param slippageBps Slippage tolerance in basis points (default 100 = 1%)
|
|
88054
88363
|
*/
|
|
88055
88364
|
async getSwapQuote(fromToken, toToken, amount, slippageBps) {
|
|
88056
88365
|
const network = this.wallet.getNetwork();
|
|
88057
88366
|
const kit = await this.getKit();
|
|
88367
|
+
const getDecimals = async (token) => {
|
|
88368
|
+
if (token === "TON" || token === "ton") return 9;
|
|
88369
|
+
return (await kit.jettons.getJettonInfo(token, network))?.decimals ?? 9;
|
|
88370
|
+
};
|
|
88371
|
+
const [fromDecimals, toDecimals] = await Promise.all([getDecimals(fromToken), getDecimals(toToken)]);
|
|
88058
88372
|
const params = {
|
|
88059
|
-
|
|
88060
|
-
|
|
88061
|
-
|
|
88373
|
+
from: {
|
|
88374
|
+
address: fromToken === "TON" ? "ton" : fromToken,
|
|
88375
|
+
decimals: fromDecimals
|
|
88062
88376
|
},
|
|
88063
|
-
|
|
88064
|
-
|
|
88065
|
-
|
|
88377
|
+
to: {
|
|
88378
|
+
address: toToken === "TON" ? "ton" : toToken,
|
|
88379
|
+
decimals: toDecimals
|
|
88066
88380
|
},
|
|
88067
88381
|
amount,
|
|
88068
88382
|
network,
|
|
@@ -88075,8 +88389,8 @@ var McpWalletService = class McpWalletService {
|
|
|
88075
88389
|
};
|
|
88076
88390
|
const tx = await kit.swap.buildSwapTransaction(swapParams);
|
|
88077
88391
|
return {
|
|
88078
|
-
fromToken: quote.fromToken.
|
|
88079
|
-
toToken: quote.toToken.
|
|
88392
|
+
fromToken: quote.fromToken.address === "ton" ? "TON" : quote.fromToken.address,
|
|
88393
|
+
toToken: quote.toToken.address === "ton" ? "TON" : quote.toToken.address,
|
|
88080
88394
|
fromAmount: quote.fromAmount,
|
|
88081
88395
|
toAmount: quote.toAmount,
|
|
88082
88396
|
minReceived: quote.minReceived,
|
|
@@ -88205,12 +88519,27 @@ var McpWalletService = class McpWalletService {
|
|
|
88205
88519
|
* LICENSE file in the root directory of this source tree.
|
|
88206
88520
|
*
|
|
88207
88521
|
*/
|
|
88522
|
+
const getWalletSchema = z.object({});
|
|
88208
88523
|
const getBalanceSchema = z.object({});
|
|
88209
88524
|
const getJettonBalanceSchema = z.object({ jettonAddress: z.string().min(1).describe("Jetton master contract address") });
|
|
88210
88525
|
const getJettonsSchema = z.object({});
|
|
88211
88526
|
const getTransactionsSchema = z.object({ limit: z.number().min(1).max(100).optional().describe("Maximum number of transactions to return (default: 20, max: 100)") });
|
|
88212
88527
|
function createMcpBalanceTools(service) {
|
|
88213
88528
|
return {
|
|
88529
|
+
get_wallet: {
|
|
88530
|
+
description: "Get current wallet address and network information.",
|
|
88531
|
+
inputSchema: getWalletSchema,
|
|
88532
|
+
handler: async () => {
|
|
88533
|
+
return { content: [{
|
|
88534
|
+
type: "text",
|
|
88535
|
+
text: JSON.stringify({
|
|
88536
|
+
success: true,
|
|
88537
|
+
address: service.getAddress(),
|
|
88538
|
+
network: service.getNetwork()
|
|
88539
|
+
}, null, 2)
|
|
88540
|
+
}] };
|
|
88541
|
+
}
|
|
88542
|
+
},
|
|
88214
88543
|
get_balance: {
|
|
88215
88544
|
description: "Get the TON balance of the wallet. Returns both human-readable and raw (nanoTON) amounts.",
|
|
88216
88545
|
inputSchema: getBalanceSchema,
|
|
@@ -88544,7 +88873,7 @@ function createMcpTransferTools(service) {
|
|
|
88544
88873
|
const getSwapQuoteSchema = z.object({
|
|
88545
88874
|
fromToken: z.string().min(1).describe("Token to swap from (\"TON\" or jetton address)"),
|
|
88546
88875
|
toToken: z.string().min(1).describe("Token to swap to (\"TON\" or jetton address)"),
|
|
88547
|
-
amount: z.string().min(1).describe("Amount to swap in
|
|
88876
|
+
amount: z.string().min(1).describe("Amount to swap in human-readable format (e.g., \"1.5\" for 1.5 TON)"),
|
|
88548
88877
|
slippageBps: z.number().optional().describe("Slippage tolerance in basis points (default 100 = 1%)")
|
|
88549
88878
|
});
|
|
88550
88879
|
function createMcpSwapTools(service) {
|
|
@@ -88938,6 +89267,7 @@ async function createTonWalletMCP(config) {
|
|
|
88938
89267
|
inputSchema: tool.inputSchema
|
|
88939
89268
|
}, tool.handler);
|
|
88940
89269
|
};
|
|
89270
|
+
registerTool("get_wallet", balanceTools.get_wallet);
|
|
88941
89271
|
registerTool("get_balance", balanceTools.get_balance);
|
|
88942
89272
|
registerTool("get_jetton_balance", balanceTools.get_jetton_balance);
|
|
88943
89273
|
registerTool("get_jettons", balanceTools.get_jettons);
|