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