@layerzerolabs/ton-sdk-tools 3.0.80 → 3.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -345,8 +345,8 @@ function parseClasses(strInput) {
345
345
  }
346
346
  return results;
347
347
  }
348
- function saveBaseEventHandler(directory, opcodesImportPath = "../constants", allTypesImportPath = "./allTypes", tonObjectUnwrapperImportPath = "./TonObjectUnwrapper", tonContractWrapperImportPath = "./TonContractWrapper") {
349
- const allTypes = ["ExtendedContract", "ActionEvent", "Md", "nameMap"].sort();
348
+ function saveBaseEventHandler(directory, opcodesImportPath = "../constants", allTypesImportPath = "./allTypes", tonObjectUnwrapperImportPath = "./TonObjectUnwrapper", tonContractWrapperImportPath = "./TonContractWrapper", baseWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
349
+ const allTypes = ["ActionEvent", "Md", "nameMap"].sort();
350
350
  const savedCode = `${file_signature_header}
351
351
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
352
352
  /* eslint-disable @typescript-eslint/no-unnecessary-condition */
@@ -354,6 +354,7 @@ function saveBaseEventHandler(directory, opcodesImportPath = "../constants", all
354
354
  import { Cell, Transaction, TransactionComputeVm, TransactionDescriptionGeneric, beginCell } from '@ton/core'
355
355
  import { BlockchainTransaction, EventMessageSent, SendMessageResult } from '@ton/sandbox'
356
356
  import { flattenTransaction } from '@ton/test-utils'
357
+ import { ExtendedContract } from '${baseWrapperImportPath}'
357
358
 
358
359
  import { OPCODES } from '${opcodesImportPath}'
359
360
 
@@ -385,14 +386,14 @@ export class LzEvent {
385
386
  async load(wrapper: ExtendedContract<TonContractWrapper>): Promise<boolean> {
386
387
  this._event = await this._eventPromise
387
388
  this.topic = TonContractWrapper.bigintToAsciiString(this._event.topic)
388
- this.bodyName = await TonObjectUnwrapper.getTypeOf(wrapper, this._event.body)
389
+ this.bodyName = await wrapper.getTypeOf(this._event.body)
389
390
  const tsCasterName = 'get' + nameMap[this.bodyName] + 'ToTS'
390
391
 
391
392
  const method = TonObjectUnwrapper[tsCasterName as keyof typeof TonObjectUnwrapper]
392
393
  if (typeof method === 'function') {
393
394
  this.body = await method(wrapper, this._event.body)
394
395
  } else {
395
- console.log('Method' + tsCasterName + 'does not exist.')
396
+ console.log('Method' + tsCasterName + ' does not exist.')
396
397
  }
397
398
 
398
399
  this.initialStorage = this._event.initialStorage
@@ -494,172 +495,7 @@ export class LzEventHandler extends BaseEventHandler {
494
495
  `;
495
496
  fs__namespace.writeFileSync(path__namespace.join(directory, "LzEventHandler.ts"), savedCode);
496
497
  }
497
- function saveClasslibWrapper(directory, baseWrapper) {
498
- if (baseWrapper === void 0) {
499
- baseWrapper = `import { BaseWrapper, SendRequestOptions } from '@layerzerolabs/ton-sdk-tools'`;
500
- }
501
- const savedCode = `${file_signature_header}
502
-
503
- import {
504
- Address,
505
- Cell,
506
- ContractProvider,
507
- ContractState,
508
- Sender,
509
- SenderArguments,
510
- TupleItem,
511
- TupleReader,
512
- contractAddress,
513
- beginCell,
514
- } from '@ton/core'
515
-
516
- ${baseWrapper}
517
-
518
- export type GetIntFnNames =
519
- | 'cl::get<uint8>'
520
- | 'cl::get<uint16>'
521
- | 'cl::get<uint32>'
522
- | 'cl::get<uint64>'
523
- | 'cl::get<uint256>'
524
- | 'cl::get<coins>'
525
- | 'cl::get<bool>'
526
- | 'cl::get<address>'
527
-
528
- export class ClasslibWrapper extends BaseWrapper {
529
- static create(code: Cell, data: Cell, workchain = 0): ClasslibWrapper {
530
- const init = { code, data }
531
- return new ClasslibWrapper(contractAddress(workchain, init), init)
532
- }
533
-
534
- buildRequest(
535
- opCode: bigint,
536
- data: Cell,
537
- opts: SendRequestOptions,
538
- balanceRefill = 0n,
539
- queryId?: number | bigint
540
- ): SenderArguments {
541
- const body = this.beginMessage(opCode, queryId).storeCoins(balanceRefill).storeRef(data).endCell()
542
- return this.buildSenderArguments(body, opts)
543
- }
544
-
545
- async sendTonPayment(
546
- provider: ContractProvider,
547
- via: Sender,
548
- opts: SendRequestOptions,
549
- ): Promise<void> {
550
- if (via.address === undefined) {
551
- throw new Error('Sender address is not defined')
552
- }
553
- const request = this.buildSenderArguments(beginCell().endCell(), opts)
554
- return this.sendRequest(provider, via, request)
555
- }
556
-
557
- async sendInternalMessage(
558
- provider: ContractProvider,
559
- via: Sender,
560
- opCode: bigint,
561
- md: Cell,
562
- opts: SendRequestOptions,
563
- balanceRefill = 0n,
564
- queryId?: number | bigint
565
- ): Promise<void> {
566
- if (via.address === undefined) {
567
- throw new Error('Sender address is not defined')
568
- }
569
- const request = this.buildRequest(opCode, md, opts, balanceRefill, queryId)
570
- return this.sendRequest(provider, via, request)
571
- }
572
-
573
- async getFieldStack(
574
- provider: ContractProvider,
575
- method: string,
576
- cell: Cell,
577
- fieldName: bigint
578
- ): Promise<TupleReader> {
579
- const args: TupleItem[] = [
580
- { type: 'cell', cell: cell },
581
- { type: 'int', value: fieldName },
582
- ]
583
- const ret = await provider.get(method, args)
584
- return ret.stack
585
- }
586
-
587
- async getState(provider: ContractProvider): Promise<ContractState> {
588
- return provider.getState()
589
- }
590
-
591
- async getContractBalanceView(provider: ContractProvider, futureSeconds: bigint): Promise<bigint> {
592
- const getResult = await provider.get('getContractBalanceView', [{ type: 'int', value: futureSeconds }])
593
- return getResult.stack.readBigNumber()
594
- }
595
-
596
- async getCurrentStorageCell(provider: ContractProvider): Promise<Cell> {
597
- const getResult = await provider.get('getContractStorage', [])
598
- return getResult.stack.readCell()
599
- }
600
-
601
- async getViewFunction(provider: ContractProvider, method: string, args: TupleItem[]): Promise<TupleReader> {
602
- const ret = await provider.get(method, args)
603
- return ret.stack
604
- }
605
-
606
- async getClInt(provider: ContractProvider, method: GetIntFnNames, cell: Cell, fieldName: bigint): Promise<bigint> {
607
- return (await this.getFieldStack(provider, method, cell, fieldName)).readBigNumber()
608
- }
609
-
610
- async getClAddress(provider: ContractProvider, cell: Cell, fieldName: bigint): Promise<Address> {
611
- return (await this.getFieldStack(provider, 'cl::get<address>', cell, fieldName)).readAddress()
612
- }
613
-
614
- async getClCell(provider: ContractProvider, cell: Cell, fieldName: bigint): Promise<Cell> {
615
- return (await this.getFieldStack(provider, 'cl::get<cellRef>', cell, fieldName)).readCell()
616
- }
617
-
618
- async getClObj(provider: ContractProvider, cell: Cell, fieldName: bigint): Promise<Cell> {
619
- return (await this.getFieldStack(provider, 'cl::get<objRef>', cell, fieldName)).readCell()
620
- }
621
-
622
- async getClDict(provider: ContractProvider, cell: Cell, fieldName: bigint): Promise<Cell> {
623
- return (await this.getFieldStack(provider, 'cl::get<dict256>', cell, fieldName)).readCell()
624
- }
625
-
626
- async getObject(provider: ContractProvider, method: string, args: TupleItem[]): Promise<Cell> {
627
- const ret = await provider.get(method, args)
628
- return ret.stack.readCell()
629
- }
630
-
631
- async getDictCellItem(provider: ContractProvider, dict_cell: Cell, key: bigint): Promise<Cell> {
632
- const args: TupleItem[] = [
633
- { type: 'cell', cell: dict_cell },
634
- { type: 'int', value: key },
635
- ]
636
- const ret = await provider.get('cl::dict256::get<cellRef>', args)
637
- return ret.stack.readCell()
638
- }
639
-
640
- async getDictUint256Item(provider: ContractProvider, dict_cell: Cell, key: bigint): Promise<bigint> {
641
- const args: TupleItem[] = [
642
- { type: 'cell', cell: dict_cell },
643
- { type: 'int', value: key },
644
- ]
645
- const ret = await provider.get('cl::dict256::get<uint256>', args)
646
- return ret.stack.readBigNumber()
647
- }
648
-
649
- async getSetDictItem(provider: ContractProvider, dict_cell: Cell, key: bigint, value: Cell): Promise<Cell> {
650
- const args: TupleItem[] = [
651
- { type: 'cell', cell: dict_cell },
652
- { type: 'int', value: key },
653
- { type: 'cell', cell: value },
654
- ]
655
- const ret = await provider.get('cl::dict256::setRef', args)
656
- return ret.stack.readCell()
657
- }
658
- }
659
- `;
660
- fs__namespace.writeFileSync(path__namespace.join(directory, "ClasslibWrapper.ts"), savedCode);
661
- }
662
- function saveTonContractWrapper(tonObjects, directory, classlibWrapperImportPath = "./ClasslibWrapper") {
498
+ function saveTonContractWrapper(tonObjects, directory, classlibWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
663
499
  const generatedMethods = Object.entries(tonObjects).map(([_, tonObject]) => tonObject.constructorCode ?? "").join("\n");
664
500
  const savedCode = `${file_signature_header}
665
501
 
@@ -684,22 +520,12 @@ export class TonContractWrapper extends ClasslibWrapper {
684
520
  return new TonContractWrapper(contractAddress(workchain, init), init)
685
521
  }
686
522
 
687
- static bigintToAsciiString(num: bigint): string {
688
- let result = ''
689
- while (num > 0n) {
690
- const charCode = Number(num & 255n)
691
- result = String.fromCharCode(charCode) + result
692
- num = num >> 8n
693
- }
694
- return result
695
- }
696
-
697
523
  ${generatedMethods}
698
524
  }
699
525
  `;
700
526
  fs__namespace.writeFileSync(path__namespace.join(directory, "TonContractWrapper.ts"), savedCode);
701
527
  }
702
- function saveAllTypes(tonObjects, directory, tonContractWrapperImportPath = "./TonContractWrapper") {
528
+ function saveAllTypes(tonObjects, directory, tonContractWrapperImportPath = "./TonContractWrapper", baseWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
703
529
  const generatedTypes = Object.entries(tonObjects).filter(([_, tonObject]) => tonObject.attributes.length > 0).map(([_, tonObject]) => "export " + (tonObject.tsTypeCode ?? "")).join("");
704
530
  const mapping = {};
705
531
  const keyMapping = {};
@@ -729,8 +555,7 @@ import { Cell, OpenedContract, beginCell } from '@ton/core'
729
555
  import { SandboxContract } from '@ton/sandbox'
730
556
 
731
557
  import { TonContractWrapper } from '${tonContractWrapperImportPath}'
732
-
733
- export type ExtendedContract<T> = SandboxContract<T> | OpenedContract<T>
558
+ import { ExtendedContract } from '${baseWrapperImportPath}'
734
559
 
735
560
  export class LzDict {
736
561
  _cell: Cell
@@ -903,10 +728,9 @@ export class LzGasTracker {
903
728
  }`;
904
729
  fs__namespace.writeFileSync(path__namespace.join(directory, "LzGasTracker.ts"), savedCode);
905
730
  }
906
- function saveTonObjectUnwrapper(tonObjects, directory, allTypesImportPath = "./allTypes", tonContractWrapperImportPath = "./TonContractWrapper") {
731
+ function saveTonObjectUnwrapper(tonObjects, directory, allTypesImportPath = "./allTypes", tonContractWrapperImportPath = "./TonContractWrapper", classlibWrapperImportPath = "@layerzerolabs/ton-sdk-tools", baseWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
907
732
  const allTypes = [
908
733
  ...Object.values(tonObjects).map((obj) => obj.tsTypeName).filter((name) => name !== void 0),
909
- "ExtendedContract",
910
734
  "LzDict",
911
735
  "Md",
912
736
  "nameMap"
@@ -922,12 +746,10 @@ import { flattenTransaction } from '@ton/test-utils'
922
746
  import { getLzDict,
923
747
  ${allTypes.map((type) => " " + type + ",\n").join("")}} from '${allTypesImportPath}'
924
748
  import { TonContractWrapper } from '${tonContractWrapperImportPath}'
749
+ import { ClasslibWrapper } from '${classlibWrapperImportPath}'
750
+ import { ExtendedContract } from '${baseWrapperImportPath}'
925
751
 
926
752
  export class TonObjectUnwrapper {
927
- static async getTypeOf(provider: ExtendedContract<TonContractWrapper>, obj_cell: Cell): Promise<string> {
928
- const ret = await provider.getViewFunction('cl::typeof', [{ type: 'cell', cell: obj_cell }])
929
- return TonContractWrapper.bigintToAsciiString(ret.readBigNumber())
930
- }
931
753
  ${Array.from(
932
754
  new Map(
933
755
  Object.entries(tonObjects).filter(([_, constructor]) => constructor.deconstructorCode).map(([_, constructor]) => [constructor.tonName, constructor.deconstructorCode])
@@ -1372,6 +1194,110 @@ var BaseWrapper = class {
1372
1194
  return core.beginCell().storeUint(opcode, 32).storeUint(queryId ?? randomQueryId, 64);
1373
1195
  }
1374
1196
  };
1197
+ var ClasslibWrapper = class _ClasslibWrapper extends BaseWrapper {
1198
+ static create(code, data, workchain = 0) {
1199
+ const init = { code, data };
1200
+ return new _ClasslibWrapper(core.contractAddress(workchain, init), init);
1201
+ }
1202
+ buildRequest(opCode, data, opts, balanceRefill = 0n, queryId) {
1203
+ const body = this.beginMessage(opCode, queryId).storeCoins(balanceRefill).storeRef(data).endCell();
1204
+ return this.buildSenderArguments(body, opts);
1205
+ }
1206
+ async sendTonPayment(provider, via, opts) {
1207
+ if (via.address === void 0) {
1208
+ throw new Error("Sender address is not defined");
1209
+ }
1210
+ const request = this.buildSenderArguments(core.beginCell().endCell(), opts);
1211
+ return this.sendRequest(provider, via, request);
1212
+ }
1213
+ async sendInternalMessage(provider, via, opCode, md, opts, balanceRefill = 0n, queryId) {
1214
+ if (via.address === void 0) {
1215
+ throw new Error("Sender address is not defined");
1216
+ }
1217
+ const request = this.buildRequest(opCode, md, opts, balanceRefill, queryId);
1218
+ return this.sendRequest(provider, via, request);
1219
+ }
1220
+ async getFieldStack(provider, method, cell, fieldName) {
1221
+ const args = [
1222
+ { type: "cell", cell },
1223
+ { type: "int", value: fieldName }
1224
+ ];
1225
+ const ret = await provider.get(method, args);
1226
+ return ret.stack;
1227
+ }
1228
+ async getState(provider) {
1229
+ return provider.getState();
1230
+ }
1231
+ async getContractBalanceView(provider, futureSeconds) {
1232
+ const getResult = await provider.get("getContractBalanceView", [{ type: "int", value: futureSeconds }]);
1233
+ return getResult.stack.readBigNumber();
1234
+ }
1235
+ async getCurrentStorageCell(provider) {
1236
+ const getResult = await provider.get("getContractStorage", []);
1237
+ return getResult.stack.readCell();
1238
+ }
1239
+ async getViewFunction(provider, method, args) {
1240
+ const ret = await provider.get(method, args);
1241
+ return ret.stack;
1242
+ }
1243
+ async getClInt(provider, method, cell, fieldName) {
1244
+ return (await this.getFieldStack(provider, method, cell, fieldName)).readBigNumber();
1245
+ }
1246
+ async getClAddress(provider, cell, fieldName) {
1247
+ return (await this.getFieldStack(provider, "cl::get<address>", cell, fieldName)).readAddress();
1248
+ }
1249
+ async getClCell(provider, cell, fieldName) {
1250
+ return (await this.getFieldStack(provider, "cl::get<cellRef>", cell, fieldName)).readCell();
1251
+ }
1252
+ async getClObj(provider, cell, fieldName) {
1253
+ return (await this.getFieldStack(provider, "cl::get<objRef>", cell, fieldName)).readCell();
1254
+ }
1255
+ async getClDict(provider, cell, fieldName) {
1256
+ return (await this.getFieldStack(provider, "cl::get<dict256>", cell, fieldName)).readCell();
1257
+ }
1258
+ async getObject(provider, method, args) {
1259
+ const ret = await provider.get(method, args);
1260
+ return ret.stack.readCell();
1261
+ }
1262
+ async getTypeOf(provider, cell) {
1263
+ const ret = await provider.get("cl::typeof", [{ type: "cell", cell }]);
1264
+ return _ClasslibWrapper.bigintToAsciiString(ret.stack.readBigNumber());
1265
+ }
1266
+ async getDictCellItem(provider, dict_cell, key) {
1267
+ const args = [
1268
+ { type: "cell", cell: dict_cell },
1269
+ { type: "int", value: key }
1270
+ ];
1271
+ const ret = await provider.get("cl::dict256::get<cellRef>", args);
1272
+ return ret.stack.readCell();
1273
+ }
1274
+ async getDictUint256Item(provider, dict_cell, key) {
1275
+ const args = [
1276
+ { type: "cell", cell: dict_cell },
1277
+ { type: "int", value: key }
1278
+ ];
1279
+ const ret = await provider.get("cl::dict256::get<uint256>", args);
1280
+ return ret.stack.readBigNumber();
1281
+ }
1282
+ async getSetDictItem(provider, dict_cell, key, value) {
1283
+ const args = [
1284
+ { type: "cell", cell: dict_cell },
1285
+ { type: "int", value: key },
1286
+ { type: "cell", cell: value }
1287
+ ];
1288
+ const ret = await provider.get("cl::dict256::setRef", args);
1289
+ return ret.stack.readCell();
1290
+ }
1291
+ static bigintToAsciiString(num) {
1292
+ let result = "";
1293
+ while (num > 0n) {
1294
+ const charCode = Number(num & 255n);
1295
+ result = String.fromCharCode(charCode) + result;
1296
+ num = num >> 8n;
1297
+ }
1298
+ return result;
1299
+ }
1300
+ };
1375
1301
  function getSharedOptions(input) {
1376
1302
  const ret = {
1377
1303
  relativeSrcPath: "../../src",
@@ -1430,10 +1356,13 @@ import {
1430
1356
  cellFromArtifact,
1431
1357
  getRandomInt,
1432
1358
  printTransactionTrace,
1359
+ ExtendedContract,
1360
+ sendMessageViaMultisigAndExpect,
1361
+ sendInternalMessageAndExpect,
1362
+ toHaveTransactions
1433
1363
  } from '@layerzerolabs/ton-sdk-tools'
1434
1364
 
1435
1365
  import {
1436
- ExtendedContract,
1437
1366
  LzDict,
1438
1367
  LzEventHandler,
1439
1368
  MdPacketSent,
@@ -1597,30 +1526,6 @@ export interface LzReceiveExpectArgs {
1597
1526
  gasValue?: bigint
1598
1527
  }
1599
1528
 
1600
- export interface SendInternalMessageAndExpectArgs {
1601
- sender: Treasury
1602
- contract: SandboxContract<TonContractWrapper>
1603
- expectedTransactions: FlatTransactionComparable[]
1604
- opCode: bigint
1605
- md: Cell
1606
- value: bigint
1607
- balanceRefill?: bigint
1608
- queryId?: bigint
1609
- profile?: Profile
1610
- recursiveDecode?: boolean
1611
- }
1612
-
1613
- export interface SendMessageViaMultisigAndExpectArgs {
1614
- blockchain: Blockchain
1615
- multiSigContract: SandboxContract<Multisig>
1616
- messageBody: Cell
1617
- signers: SandboxContract<TreasuryContract>[]
1618
- targetContract: SandboxContract<TonContractWrapper | JettonMinter>
1619
- deploy: boolean
1620
- expectedTransactions: FlatTransactionComparable[]
1621
- recursiveDecode?: boolean
1622
- }
1623
-
1624
1529
  export interface OutOfOrder {
1625
1530
  actions: Action[]
1626
1531
  }
@@ -1846,170 +1751,6 @@ export function readJsonFile(filePath: string): unknown {
1846
1751
  }
1847
1752
  }
1848
1753
 
1849
- export async function openAndDeployAllStorages(
1850
- blockchain: Blockchain,
1851
- multiSigOwner1: SandboxContract<TreasuryContract>
1852
- ): Promise<SandboxContract<TonContractWrapper>> {
1853
- // ===================================open allStorages=====================================
1854
-
1855
- const allStorages = blockchain.openContract(
1856
- TonContractWrapper.create(cellFromArtifact(AllStoragesArtifact), beginCell().endCell())
1857
- )
1858
-
1859
- // ===================================deploy allStorages=====================================
1860
-
1861
- await sendInternalMessageAndExpect({
1862
- value: protocolSetupGas['AllStorages.INITIALIZE'],
1863
- sender: multiSigOwner1.getSender(),
1864
- contract: allStorages,
1865
- expectedTransactions: [
1866
- {
1867
- from: multiSigOwner1.address,
1868
- to: allStorages.address,
1869
- deploy: true,
1870
- success: true,
1871
- },
1872
- ],
1873
- opCode: OPCODES.BaseInterface_OP_INITIALIZE,
1874
- md: emptyObject,
1875
- balanceRefill: toNano('1'),
1876
- })
1877
-
1878
- return allStorages
1879
- }
1880
-
1881
- export async function sendMessageViaMultisigAndExpect({
1882
- blockchain,
1883
- multiSigContract,
1884
- messageBody,
1885
- signers,
1886
- targetContract,
1887
- deploy,
1888
- expectedTransactions = [],
1889
- recursiveDecode = RECURSIVE_DECODE,
1890
- }: SendMessageViaMultisigAndExpectArgs): Promise<SendMessageResult> {
1891
- const curTime = (): number => blockchain.now ?? Math.floor(Date.now() / 1000)
1892
-
1893
- const initialSeqno = (await multiSigContract.getMultisigData()).nextOrderSeqno
1894
- const orderAddress = await multiSigContract.getOrderAddress(initialSeqno)
1895
-
1896
- const rawMessageBuilder = beginCell().storeUint(0x18, 6).storeAddress(targetContract.address).storeCoins(0)
1897
-
1898
- let rawMessageCell: Cell
1899
-
1900
- if (targetContract.init === undefined) {
1901
- throw new Error('targetContract.init is undefined')
1902
- }
1903
-
1904
- if (deploy) {
1905
- const targetContractStateInit = beginCell()
1906
- .storeUint(6, 5)
1907
- .storeRef(targetContract.init.code)
1908
- .storeRef(targetContract.init.data)
1909
- .endCell()
1910
-
1911
- rawMessageCell = rawMessageBuilder
1912
- .storeUint(7, 108)
1913
- .storeRef(targetContractStateInit)
1914
- .storeRef(messageBody)
1915
- .endCell()
1916
- } else {
1917
- rawMessageCell = rawMessageBuilder.storeUint(1, 107).storeRef(messageBody).endCell()
1918
- }
1919
-
1920
- const orderMsg: TransferRequest = {
1921
- type: 'transfer',
1922
- sendMode: SendMode.CARRY_ALL_REMAINING_BALANCE,
1923
- message: rawMessageCell,
1924
- }
1925
-
1926
- // one of the signers proposes deploying the controller
1927
- let internalMsgResults = await multiSigContract.sendNewOrder(signers[0].getSender(), [orderMsg], curTime() + 100)
1928
-
1929
- expect(internalMsgResults.transactions).toHaveTransaction({
1930
- from: multiSigContract.address,
1931
- to: orderAddress,
1932
- deploy: true,
1933
- success: true,
1934
- })
1935
-
1936
- // that makes sure that the target contract is a sandbox<TonContractWrapper>
1937
- if (recursiveDecode && 'getCurrentStorageCell' in targetContract) {
1938
- await txDecoder(targetContract, internalMsgResults)
1939
- }
1940
-
1941
- const orderContract = blockchain.openContract(Order.createFromAddress(orderAddress))
1942
- const orderDataBefore = await orderContract.getOrderData()
1943
-
1944
- // proposal by a signer is considered automatically approved
1945
- expect(orderDataBefore.approvals_num).toBe(1)
1946
- expect(orderDataBefore.executed).toBe(false)
1947
-
1948
- // approve it by the other 2 signers
1949
- await orderContract.sendApprove(signers[1].getSender(), 1)
1950
- internalMsgResults = await orderContract.sendApprove(signers[2].getSender(), 2)
1951
-
1952
- // the order should send tell the multisig to execute the order
1953
- expect(internalMsgResults.transactions).toHaveTransaction({
1954
- from: orderAddress,
1955
- to: multiSigContract.address,
1956
- op: MultiSigOpCodes.multisig.execute,
1957
- success: true,
1958
- })
1959
-
1960
- // the multisig should deliver the message to the target contract
1961
- expect(internalMsgResults.transactions).toHaveTransaction({
1962
- from: multiSigContract.address,
1963
- to: targetContract.address,
1964
- // deploy,
1965
- success: true,
1966
- })
1967
-
1968
- toHaveTransactions(internalMsgResults.transactions, expectedTransactions)
1969
-
1970
- if (recursiveDecode && 'getCurrentStorageCell' in targetContract) {
1971
- await txDecoder(targetContract, internalMsgResults)
1972
- }
1973
-
1974
- return internalMsgResults
1975
- }
1976
-
1977
- export async function sendInternalMessageAndExpect({
1978
- sender,
1979
- contract,
1980
- opCode,
1981
- md,
1982
- expectedTransactions,
1983
- value,
1984
- balanceRefill = BigInt(0),
1985
- queryId = BigInt(1),
1986
- profile,
1987
- recursiveDecode = RECURSIVE_DECODE,
1988
- }: SendInternalMessageAndExpectArgs): Promise<SendMessageResult> {
1989
- const internalMsgResults = await contract.sendInternalMessage(sender, opCode, md, { value }, balanceRefill, queryId)
1990
-
1991
- if (profile?.profileGas ?? false) {
1992
- const { stack } = new Error()
1993
- printTransactionTrace(internalMsgResults.transactions, invertedOpcodes, stack, profile)
1994
- }
1995
-
1996
- if (recursiveDecode) {
1997
- await txDecoder(contract, internalMsgResults)
1998
- }
1999
-
2000
- toHaveTransactions(internalMsgResults.transactions, expectedTransactions)
2001
- return internalMsgResults
2002
- }
2003
-
2004
- export function toHaveTransactions(
2005
- actualTransactions: BlockchainTransaction[],
2006
- expectedTransactions: FlatTransactionComparable[]
2007
- ): void {
2008
- expectedTransactions.forEach((tx) => {
2009
- expect(actualTransactions).toHaveTransaction(tx)
2010
- })
2011
- }
2012
-
2013
1754
  export async function lzReceiveAndExpect({
2014
1755
  lzReceivePrepareMd,
2015
1756
  oAppFixture,
@@ -2929,7 +2670,7 @@ export async function txDecoder(
2929
2670
  export async function runtimeDecoder(contract: SandboxContract<TonContractWrapper>, obj: Cell): Promise<void> {
2930
2671
  const { tonObjects } = require('${options.relativeSrcPath}/offchain-helpers/allObjects') as { [key: string]: { [key: string]: any } }
2931
2672
 
2932
- const typeName = await TonObjectUnwrapper.getTypeOf(contract, obj)
2673
+ const typeName = await contract.getTypeOf(obj)
2933
2674
 
2934
2675
  const tonObjectDefKey = keyMap[typeName] ?? ('' as any)
2935
2676
  // if key not found, return early
@@ -2963,7 +2704,7 @@ export async function runtimeDecoder(contract: SandboxContract<TonContractWrappe
2963
2704
 
2964
2705
  // If field is an objRef, try to decode the corresponding decoded value
2965
2706
  if (jsonField.fieldType === 'cl::t::objRef' && field instanceof Cell) {
2966
- let newCellFieldType = await TonObjectUnwrapper.getTypeOf(contract, field)
2707
+ let newCellFieldType = await contract.getTypeOf(field)
2967
2708
  if (newCellFieldType === 'NULL') {
2968
2709
  newCellFieldType = 'cl::t::cellRef'
2969
2710
  } else {
@@ -2998,7 +2739,7 @@ import ChannelArtifact from '@layerzerolabs/layerzero-v2-ton/build/Channel.compi
2998
2739
  import EndpointArtifact from '@layerzerolabs/layerzero-v2-ton/build/Endpoint.compiled.json'
2999
2740
  import SmlConnectionArtifact from '@layerzerolabs/layerzero-v2-ton/build/SmlConnection.compiled.json'
3000
2741
  import SmlManagerArtifact from '@layerzerolabs/layerzero-v2-ton/build/SmlManager.compiled.json'
3001
- import { Profile, addressToBigInt, cellFromArtifact } from '@layerzerolabs/ton-sdk-tools'
2742
+ import { Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, } from '@layerzerolabs/ton-sdk-tools'
3002
2743
 
3003
2744
  import {
3004
2745
  OAppFixture,
@@ -3006,7 +2747,6 @@ import {
3006
2747
  addMsgLibToController,
3007
2748
  emptyObject,
3008
2749
  protocolSetupGas,
3009
- sendInternalMessageAndExpect,
3010
2750
  setDefaultEndpointConfig,
3011
2751
  wireChannels,
3012
2752
  } from './auto-utils-common'
@@ -3370,7 +3110,7 @@ import ProxyArtifact from '@layerzerolabs/layerzero-v2-ton/build/Proxy.compiled.
3370
3110
  import UlnArtifact from '@layerzerolabs/layerzero-v2-ton/build/Uln.compiled.json'
3371
3111
  import UlnConnectionArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnConnection.compiled.json'
3372
3112
  import UlnManagerArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnManager.compiled.json'
3373
- import { Profile, addressToBigInt, cellFromArtifact } from '@layerzerolabs/ton-sdk-tools'
3113
+ import { ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, } from '@layerzerolabs/ton-sdk-tools'
3374
3114
 
3375
3115
  import {
3376
3116
  OAppFixture,
@@ -3385,14 +3125,12 @@ import {
3385
3125
  protocolSetupGas,
3386
3126
  publicKeyToHash,
3387
3127
  requireDefined,
3388
- sendInternalMessageAndExpect,
3389
- sendMessageViaMultisigAndExpect,
3390
3128
  serializeAddressList,
3391
3129
  setDefaultEndpointConfig,
3392
3130
  wireChannels,
3393
3131
  } from './auto-utils-common'
3132
+
3394
3133
  import {
3395
- ExtendedContract,
3396
3134
  LzDict,
3397
3135
  LzEventHandler,
3398
3136
  MdPacketSent,
@@ -6346,9 +6084,126 @@ function printTransactionTrace(transactions, opcodeInfo, callerStack, profile) {
6346
6084
  );
6347
6085
  if (profile?.profileGas) sortAndSave(filePath, gasInfo);
6348
6086
  }
6087
+ async function sendMessageViaMultisigAndExpect({
6088
+ blockchain,
6089
+ multiSigContract,
6090
+ messageBody,
6091
+ signers,
6092
+ targetContract,
6093
+ deploy,
6094
+ expectedTransactions = [],
6095
+ recursiveDecode = false,
6096
+ txDecoder
6097
+ }) {
6098
+ const curTime = () => blockchain.now ?? Math.floor(Date.now() / 1e3);
6099
+ const initialSeqno = (await multiSigContract.getMultisigData()).nextOrderSeqno;
6100
+ const orderAddress = await multiSigContract.getOrderAddress(initialSeqno);
6101
+ const rawMessageBuilder = core.beginCell().storeUint(24, 6).storeAddress(targetContract.address).storeCoins(0);
6102
+ let rawMessageCell;
6103
+ if (targetContract.init === void 0) {
6104
+ throw new Error("targetContract.init is undefined");
6105
+ }
6106
+ if (deploy) {
6107
+ const targetContractStateInit = core.beginCell().storeUint(6, 5).storeRef(targetContract.init.code ?? core.beginCell().endCell()).storeRef(targetContract.init.data ?? core.beginCell().endCell()).endCell();
6108
+ rawMessageCell = rawMessageBuilder.storeUint(7, 108).storeRef(targetContractStateInit).storeRef(messageBody).endCell();
6109
+ } else {
6110
+ rawMessageCell = rawMessageBuilder.storeUint(1, 107).storeRef(messageBody).endCell();
6111
+ }
6112
+ const orderMsg = {
6113
+ type: "transfer",
6114
+ sendMode: core.SendMode.CARRY_ALL_REMAINING_BALANCE,
6115
+ message: rawMessageCell
6116
+ };
6117
+ let internalMsgResults = await multiSigContract.sendNewOrder(signers[0].getSender(), [orderMsg], curTime() + 100);
6118
+ expect(internalMsgResults.transactions).toHaveTransaction({
6119
+ from: multiSigContract.address,
6120
+ to: orderAddress,
6121
+ deploy: true,
6122
+ success: true
6123
+ });
6124
+ if (recursiveDecode && "getCurrentStorageCell" in targetContract && txDecoder) {
6125
+ await txDecoder(targetContract, internalMsgResults);
6126
+ }
6127
+ const orderContract = blockchain.openContract(Order.createFromAddress(orderAddress));
6128
+ const orderDataBefore = await orderContract.getOrderData();
6129
+ expect(orderDataBefore.approvals_num).toBe(1);
6130
+ expect(orderDataBefore.executed).toBe(false);
6131
+ await orderContract.sendApprove(signers[1].getSender(), 1);
6132
+ internalMsgResults = await orderContract.sendApprove(signers[2].getSender(), 2);
6133
+ expect(internalMsgResults.transactions).toHaveTransaction({
6134
+ from: orderAddress,
6135
+ to: multiSigContract.address,
6136
+ op: MultiSigOpCodes.multisig.execute,
6137
+ success: true
6138
+ });
6139
+ expect(internalMsgResults.transactions).toHaveTransaction({
6140
+ from: multiSigContract.address,
6141
+ to: targetContract.address,
6142
+ // deploy,
6143
+ success: true
6144
+ });
6145
+ toHaveTransactions(internalMsgResults.transactions, expectedTransactions);
6146
+ if (recursiveDecode && "getCurrentStorageCell" in targetContract && txDecoder) {
6147
+ await txDecoder(targetContract, internalMsgResults);
6148
+ }
6149
+ return internalMsgResults;
6150
+ }
6151
+ async function sendInternalMessageAndExpect({
6152
+ sender,
6153
+ contract,
6154
+ opCode,
6155
+ md,
6156
+ expectedTransactions,
6157
+ value,
6158
+ balanceRefill = BigInt(0),
6159
+ queryId = BigInt(1),
6160
+ profile,
6161
+ recursiveDecode = false,
6162
+ txDecoder,
6163
+ invertedOpcodes
6164
+ }) {
6165
+ const internalMsgResults = await contract.sendInternalMessage(sender, opCode, md, { value }, balanceRefill, queryId);
6166
+ if (profile?.profileGas ?? false) {
6167
+ const { stack } = new Error();
6168
+ printTransactionTrace(internalMsgResults.transactions, invertedOpcodes ?? {}, stack, profile);
6169
+ }
6170
+ if (recursiveDecode && txDecoder) {
6171
+ await txDecoder(contract, internalMsgResults);
6172
+ }
6173
+ toHaveTransactions(internalMsgResults.transactions, expectedTransactions);
6174
+ return internalMsgResults;
6175
+ }
6176
+ function toHaveTransactions(actualTransactions, expectedTransactions) {
6177
+ expectedTransactions.forEach((tx) => {
6178
+ expect(actualTransactions).toHaveTransaction(tx);
6179
+ });
6180
+ }
6181
+ async function openAndDeployAllStoragesTemplate(blockchain, deployer, artifact, gasValue, opCode, md) {
6182
+ const allStorages = blockchain.openContract(
6183
+ ClasslibWrapper.create(cellFromArtifact(artifact), core.beginCell().endCell())
6184
+ );
6185
+ await sendInternalMessageAndExpect({
6186
+ value: gasValue,
6187
+ sender: deployer.getSender(),
6188
+ contract: allStorages,
6189
+ expectedTransactions: [
6190
+ {
6191
+ from: deployer.address,
6192
+ to: allStorages.address,
6193
+ deploy: true,
6194
+ success: true
6195
+ }
6196
+ ],
6197
+ opCode,
6198
+ md,
6199
+ balanceRefill: core.toNano("1")
6200
+ });
6201
+ return allStorages;
6202
+ }
6349
6203
 
6350
6204
  exports.BASE_CHAIN_ID = BASE_CHAIN_ID;
6351
6205
  exports.BaseWrapper = BaseWrapper;
6206
+ exports.ClasslibWrapper = ClasslibWrapper;
6352
6207
  exports.Errors = Errors;
6353
6208
  exports.JettonMinter = JettonMinter;
6354
6209
  exports.JettonWallet = JettonWallet;
@@ -6396,12 +6251,12 @@ exports.jettonWalletConfigToCell = jettonWalletConfigToCell;
6396
6251
  exports.makeSnakeCell = makeSnakeCell;
6397
6252
  exports.mergeConstructorDicts = mergeConstructorDicts;
6398
6253
  exports.multisigConfigToCell = multisigConfigToCell;
6254
+ exports.openAndDeployAllStoragesTemplate = openAndDeployAllStoragesTemplate;
6399
6255
  exports.orderConfigToCell = orderConfigToCell;
6400
6256
  exports.parseDirectory = parseDirectory;
6401
6257
  exports.printTransactionTrace = printTransactionTrace;
6402
6258
  exports.saveAllTypes = saveAllTypes;
6403
6259
  exports.saveBaseEventHandler = saveBaseEventHandler;
6404
- exports.saveClasslibWrapper = saveClasslibWrapper;
6405
6260
  exports.saveConstantsFile = saveConstantsFile;
6406
6261
  exports.saveEventsFile = saveEventsFile;
6407
6262
  exports.saveLzEventHandler = saveLzEventHandler;
@@ -6410,7 +6265,10 @@ exports.saveObjectsAsTS = saveObjectsAsTS;
6410
6265
  exports.saveTonContractWrapper = saveTonContractWrapper;
6411
6266
  exports.saveTonObjectUnwrapper = saveTonObjectUnwrapper;
6412
6267
  exports.saveViewFunctions = saveViewFunctions;
6268
+ exports.sendInternalMessageAndExpect = sendInternalMessageAndExpect;
6269
+ exports.sendMessageViaMultisigAndExpect = sendMessageViaMultisigAndExpect;
6413
6270
  exports.storageCollected = storageCollected;
6414
6271
  exports.to32ByteBuffer = to32ByteBuffer;
6272
+ exports.toHaveTransactions = toHaveTransactions;
6415
6273
  //# sourceMappingURL=index.cjs.map
6416
6274
  //# sourceMappingURL=index.cjs.map