@layerzerolabs/ton-sdk-tools 3.0.87 → 3.0.89
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/CHANGELOG.md +12 -0
- package/dist/index.cjs +169 -211
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.mjs +159 -213
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var fs = require('fs');
|
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var core = require('@ton/core');
|
|
6
6
|
var crc32 = require('crc-32');
|
|
7
|
+
var ethers = require('ethers');
|
|
7
8
|
var bigintBuffer = require('bigint-buffer');
|
|
8
9
|
var Event = require('@ton/sandbox/dist/event/Event');
|
|
9
10
|
var testUtils = require('@ton/test-utils');
|
|
@@ -34,15 +35,85 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
34
35
|
var crc32__namespace = /*#__PURE__*/_interopNamespace(crc32);
|
|
35
36
|
|
|
36
37
|
// src/sdk-tools.ts
|
|
38
|
+
function to32ByteBuffer(value, maxIntermediateBufferSize = 66) {
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
if (!isValidHex(value)) {
|
|
41
|
+
throw new Error("only hex string is supported");
|
|
42
|
+
}
|
|
43
|
+
let hex = trim0x(value);
|
|
44
|
+
if (hex.length % 2 !== 0) {
|
|
45
|
+
hex = "0" + hex;
|
|
46
|
+
}
|
|
47
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
48
|
+
}
|
|
49
|
+
if (value instanceof Uint8Array) {
|
|
50
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
51
|
+
}
|
|
52
|
+
const bf = bigintBuffer.toBufferBE(BigInt(value), maxIntermediateBufferSize);
|
|
53
|
+
return bf.subarray(-32);
|
|
54
|
+
}
|
|
55
|
+
function trim0x(str2) {
|
|
56
|
+
return str2.replace(/^0x/, "");
|
|
57
|
+
}
|
|
58
|
+
function isValidHex(str2) {
|
|
59
|
+
const hexRegex = /^(0x)?[0-9A-Fa-f]+$/;
|
|
60
|
+
return hexRegex.test(str2);
|
|
61
|
+
}
|
|
62
|
+
function bigintToAddress(value) {
|
|
63
|
+
const buf = to32ByteBuffer(value);
|
|
64
|
+
return core.Address.parse(`0:${buf.toString("hex")}`);
|
|
65
|
+
}
|
|
66
|
+
var parseTonAddress = (address) => {
|
|
67
|
+
if (address instanceof core.Address) {
|
|
68
|
+
return address;
|
|
69
|
+
}
|
|
70
|
+
if (typeof address === "bigint" || typeof address === "number") {
|
|
71
|
+
return bigintToAddress(BigInt(address));
|
|
72
|
+
}
|
|
73
|
+
if (address.startsWith("0x")) {
|
|
74
|
+
return bigintToAddress(BigInt(address));
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
return core.Address.parse(address);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return bigintToAddress(BigInt(`0x${address}`));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var _addressToNotPaddedHex = (address) => {
|
|
83
|
+
return `0x${parseTonAddress(address).hash.toString("hex")}`;
|
|
84
|
+
};
|
|
85
|
+
var bigIntToHex = (bigInt) => {
|
|
86
|
+
return `0x${bigInt.toString(16)}`.toLowerCase();
|
|
87
|
+
};
|
|
88
|
+
var addressToHex = (address) => {
|
|
89
|
+
return `0x${to32ByteBuffer(_addressToNotPaddedHex(address)).toString("hex")}`.toLowerCase();
|
|
90
|
+
};
|
|
91
|
+
var addressToBigInt = (address) => {
|
|
92
|
+
return BigInt(_addressToNotPaddedHex(address));
|
|
93
|
+
};
|
|
94
|
+
var compareAddresses = (addressA, addressB) => {
|
|
95
|
+
return parseTonAddress(addressA).equals(parseTonAddress(addressB));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/utils.ts
|
|
37
99
|
var MASTER_CHAIN_ID = -1;
|
|
38
100
|
var BASE_CHAIN_ID = 0;
|
|
39
101
|
var MASTER_CHAIN_SHARD = "8000000000000000";
|
|
40
102
|
var PUBLIC_KEY_BYTE_LENGTH = 64;
|
|
103
|
+
var SIGNATURE_BYTE_LENGTH = 65;
|
|
104
|
+
var SEED_SIZE = 32;
|
|
41
105
|
function publicKeyToHash(publicKey) {
|
|
42
106
|
const publicKeyCell = core.beginCell().storeBuffer(Buffer.from(publicKey), PUBLIC_KEY_BYTE_LENGTH).endCell();
|
|
43
107
|
const publicKeyHash = BigInt("0x" + publicKeyCell.hash().toString("hex"));
|
|
44
108
|
return publicKeyHash;
|
|
45
109
|
}
|
|
110
|
+
function preprocessPublicKey(publicKey) {
|
|
111
|
+
const publicKeyBuffer = Buffer.from(publicKey.slice(2), "hex");
|
|
112
|
+
return publicKeyBuffer.subarray(1);
|
|
113
|
+
}
|
|
114
|
+
function stringPublicKeyToHash(publicKey) {
|
|
115
|
+
return publicKeyToHash(preprocessPublicKey(publicKey));
|
|
116
|
+
}
|
|
46
117
|
function createVerifierDictSet(verifiers) {
|
|
47
118
|
const verifierDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
48
119
|
for (const verifier of verifiers) {
|
|
@@ -50,6 +121,46 @@ function createVerifierDictSet(verifiers) {
|
|
|
50
121
|
}
|
|
51
122
|
return core.beginCell().storeDictDirect(verifierDict, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
52
123
|
}
|
|
124
|
+
function createVerifierDictSetFromStrings(publicKeys) {
|
|
125
|
+
const publicKeyBuffers = publicKeys.map((key) => preprocessPublicKey(key));
|
|
126
|
+
return createVerifierDictSet(publicKeyBuffers);
|
|
127
|
+
}
|
|
128
|
+
function createVerifierDictSetFromEtherWallets(verifiers) {
|
|
129
|
+
const publicKeys = verifiers.map((key) => key.publicKey);
|
|
130
|
+
return createVerifierDictSetFromStrings(publicKeys);
|
|
131
|
+
}
|
|
132
|
+
function createAdminDictSet(admins) {
|
|
133
|
+
const verifierDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
134
|
+
for (const admin of admins) {
|
|
135
|
+
verifierDict.set(addressToBigInt(admin.address), core.beginCell().endCell());
|
|
136
|
+
}
|
|
137
|
+
return core.beginCell().storeDictDirect(verifierDict, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
138
|
+
}
|
|
139
|
+
function createSignatures(hash, verifiers) {
|
|
140
|
+
const signatures = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
141
|
+
for (const verifier of verifiers) {
|
|
142
|
+
const signature = verifier._signingKey().signDigest(hash);
|
|
143
|
+
const signatureBytes = ethers.ethers.utils.splitSignature(signature);
|
|
144
|
+
const signatureBytesArray = new Uint8Array([
|
|
145
|
+
...ethers.ethers.utils.arrayify(signatureBytes.r),
|
|
146
|
+
...ethers.ethers.utils.arrayify(signatureBytes.s),
|
|
147
|
+
signatureBytes.v
|
|
148
|
+
]);
|
|
149
|
+
signatures.set(
|
|
150
|
+
stringPublicKeyToHash(verifier.publicKey),
|
|
151
|
+
core.beginCell().storeBuffer(Buffer.from(signatureBytesArray), SIGNATURE_BYTE_LENGTH).endCell()
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return core.beginCell().storeDictDirect(signatures, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
155
|
+
}
|
|
156
|
+
function generateRandomVerifierSet(count) {
|
|
157
|
+
const verifiers = [];
|
|
158
|
+
for (let i = 0; i < count; i++) {
|
|
159
|
+
const privateKey = ethers.ethers.utils.randomBytes(SEED_SIZE);
|
|
160
|
+
verifiers.push(new ethers.ethers.Wallet(privateKey));
|
|
161
|
+
}
|
|
162
|
+
return verifiers;
|
|
163
|
+
}
|
|
53
164
|
var getBocStringFromMessage = (message) => {
|
|
54
165
|
return core.beginCell().store(core.storeMessageRelaxed(message)).endCell().toBoc().toString("base64");
|
|
55
166
|
};
|
|
@@ -74,6 +185,16 @@ function findDeepestCell(cell) {
|
|
|
74
185
|
}
|
|
75
186
|
return { subTreeCells: size };
|
|
76
187
|
}
|
|
188
|
+
function addLibToBlockchain(blockchain, newLib) {
|
|
189
|
+
let libsDict;
|
|
190
|
+
if (blockchain.libs) {
|
|
191
|
+
libsDict = blockchain.libs.beginParse().loadDictDirect(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
192
|
+
} else {
|
|
193
|
+
libsDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
194
|
+
}
|
|
195
|
+
libsDict.set(BigInt(`0x${newLib.hash().toString("hex")}`), newLib);
|
|
196
|
+
blockchain.libs = core.beginCell().storeDictDirect(libsDict).endCell();
|
|
197
|
+
}
|
|
77
198
|
|
|
78
199
|
// src/sdk-tools.ts
|
|
79
200
|
var file_signature_header = `////// Generated by sdk/sdk-generator.ts`;
|
|
@@ -345,11 +466,11 @@ function saveBaseEventHandler(directory, opcodesImportPath = "../constants", all
|
|
|
345
466
|
import { Cell, Transaction, TransactionComputeVm, TransactionDescriptionGeneric, beginCell } from '@ton/core'
|
|
346
467
|
import { BlockchainTransaction, EventMessageSent, SendMessageResult } from '@ton/sandbox'
|
|
347
468
|
import { flattenTransaction } from '@ton/test-utils'
|
|
348
|
-
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
469
|
+
import { ExtendedContract, getLzDict } from '${baseWrapperImportPath}'
|
|
349
470
|
|
|
350
471
|
import { OPCODES } from '${opcodesImportPath}'
|
|
351
472
|
|
|
352
|
-
import {
|
|
473
|
+
import {
|
|
353
474
|
${allTypes.map((type) => " " + type + ",\n").join("")}} from '${allTypesImportPath}'
|
|
354
475
|
|
|
355
476
|
import { TonObjectUnwrapper } from '${tonObjectUnwrapperImportPath}'
|
|
@@ -546,40 +667,7 @@ import { Cell, OpenedContract, beginCell } from '@ton/core'
|
|
|
546
667
|
import { SandboxContract } from '@ton/sandbox'
|
|
547
668
|
|
|
548
669
|
import { TonContractWrapper } from '${tonContractWrapperImportPath}'
|
|
549
|
-
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
550
|
-
|
|
551
|
-
export class LzDict {
|
|
552
|
-
_cell: Cell
|
|
553
|
-
|
|
554
|
-
constructor(data: Cell) {
|
|
555
|
-
this._cell = data
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
static empty(): LzDict {
|
|
559
|
-
return new LzDict(beginCell().endCell())
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
async getCell(key: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<Cell> {
|
|
563
|
-
return wrapper.getDictCellItem(this._cell, key)
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
async getBigInt(key: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<bigint> {
|
|
567
|
-
return wrapper.getDictUint256Item(this._cell, key)
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
async set(key: bigint, value: Cell, wrapper: ExtendedContract<TonContractWrapper>): Promise<void> {
|
|
571
|
-
this._cell = await wrapper.getSetDictItem(this._cell, key, value)
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
asCell(): Cell {
|
|
575
|
-
return this._cell
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
export async function getLzDict(obj: Cell, fieldName: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<LzDict> {
|
|
580
|
-
const dictCell = await wrapper.getClDict(obj, fieldName)
|
|
581
|
-
return new LzDict(dictCell)
|
|
582
|
-
}
|
|
670
|
+
import { ExtendedContract, LzDict, getLzDict } from '${baseWrapperImportPath}'
|
|
583
671
|
|
|
584
672
|
export interface Md {}
|
|
585
673
|
|
|
@@ -722,7 +810,6 @@ export class LzGasTracker {
|
|
|
722
810
|
function saveTonObjectUnwrapper(tonObjects, directory, allTypesImportPath = "./allTypes", tonContractWrapperImportPath = "./TonContractWrapper", classlibWrapperImportPath = "@layerzerolabs/ton-sdk-tools", baseWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
|
|
723
811
|
const allTypes = [
|
|
724
812
|
...Object.values(tonObjects).map((obj) => obj.tsTypeName).filter((name) => name !== void 0),
|
|
725
|
-
"LzDict",
|
|
726
813
|
"Md",
|
|
727
814
|
"nameMap"
|
|
728
815
|
].sort();
|
|
@@ -734,11 +821,11 @@ import { Cell, Transaction, TransactionComputeVm, TransactionDescriptionGeneric,
|
|
|
734
821
|
import { BlockchainTransaction, EventMessageSent, SendMessageResult } from '@ton/sandbox'
|
|
735
822
|
import { flattenTransaction } from '@ton/test-utils'
|
|
736
823
|
|
|
737
|
-
import {
|
|
824
|
+
import {
|
|
738
825
|
${allTypes.map((type) => " " + type + ",\n").join("")}} from '${allTypesImportPath}'
|
|
739
826
|
import { TonContractWrapper } from '${tonContractWrapperImportPath}'
|
|
740
827
|
import { ClasslibWrapper } from '${classlibWrapperImportPath}'
|
|
741
|
-
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
828
|
+
import { ExtendedContract, LzDict, getLzDict } from '${baseWrapperImportPath}'
|
|
742
829
|
|
|
743
830
|
export class TonObjectUnwrapper {
|
|
744
831
|
${Array.from(
|
|
@@ -1147,65 +1234,6 @@ function saveViewFunctions(viewFunctions, directory, filename) {
|
|
|
1147
1234
|
}
|
|
1148
1235
|
fs__namespace.writeFileSync(path__namespace.join(directory, filename), generated.join("\n"));
|
|
1149
1236
|
}
|
|
1150
|
-
function to32ByteBuffer(value, maxIntermediateBufferSize = 66) {
|
|
1151
|
-
if (typeof value === "string") {
|
|
1152
|
-
if (!isValidHex(value)) {
|
|
1153
|
-
throw new Error("only hex string is supported");
|
|
1154
|
-
}
|
|
1155
|
-
let hex = trim0x(value);
|
|
1156
|
-
if (hex.length % 2 !== 0) {
|
|
1157
|
-
hex = "0" + hex;
|
|
1158
|
-
}
|
|
1159
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
1160
|
-
}
|
|
1161
|
-
if (value instanceof Uint8Array) {
|
|
1162
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
1163
|
-
}
|
|
1164
|
-
const bf = bigintBuffer.toBufferBE(BigInt(value), maxIntermediateBufferSize);
|
|
1165
|
-
return bf.subarray(-32);
|
|
1166
|
-
}
|
|
1167
|
-
function trim0x(str2) {
|
|
1168
|
-
return str2.replace(/^0x/, "");
|
|
1169
|
-
}
|
|
1170
|
-
function isValidHex(str2) {
|
|
1171
|
-
const hexRegex = /^(0x)?[0-9A-Fa-f]+$/;
|
|
1172
|
-
return hexRegex.test(str2);
|
|
1173
|
-
}
|
|
1174
|
-
function bigintToAddress(value) {
|
|
1175
|
-
const buf = to32ByteBuffer(value);
|
|
1176
|
-
return core.Address.parse(`0:${buf.toString("hex")}`);
|
|
1177
|
-
}
|
|
1178
|
-
var parseTonAddress = (address) => {
|
|
1179
|
-
if (address instanceof core.Address) {
|
|
1180
|
-
return address;
|
|
1181
|
-
}
|
|
1182
|
-
if (typeof address === "bigint" || typeof address === "number") {
|
|
1183
|
-
return bigintToAddress(BigInt(address));
|
|
1184
|
-
}
|
|
1185
|
-
if (address.startsWith("0x")) {
|
|
1186
|
-
return bigintToAddress(BigInt(address));
|
|
1187
|
-
}
|
|
1188
|
-
try {
|
|
1189
|
-
return core.Address.parse(address);
|
|
1190
|
-
} catch (e) {
|
|
1191
|
-
return bigintToAddress(BigInt(`0x${address}`));
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
var _addressToNotPaddedHex = (address) => {
|
|
1195
|
-
return `0x${parseTonAddress(address).hash.toString("hex")}`;
|
|
1196
|
-
};
|
|
1197
|
-
var bigIntToHex = (bigInt) => {
|
|
1198
|
-
return `0x${bigInt.toString(16)}`.toLowerCase();
|
|
1199
|
-
};
|
|
1200
|
-
var addressToHex = (address) => {
|
|
1201
|
-
return `0x${to32ByteBuffer(_addressToNotPaddedHex(address)).toString("hex")}`.toLowerCase();
|
|
1202
|
-
};
|
|
1203
|
-
var addressToBigInt = (address) => {
|
|
1204
|
-
return BigInt(_addressToNotPaddedHex(address));
|
|
1205
|
-
};
|
|
1206
|
-
var compareAddresses = (addressA, addressB) => {
|
|
1207
|
-
return parseTonAddress(addressA).equals(parseTonAddress(addressB));
|
|
1208
|
-
};
|
|
1209
1237
|
var BaseWrapper = class {
|
|
1210
1238
|
constructor(address, init) {
|
|
1211
1239
|
this.address = address;
|
|
@@ -1410,11 +1438,12 @@ import {
|
|
|
1410
1438
|
ExtendedContract,
|
|
1411
1439
|
sendMessageViaMultisigAndExpect,
|
|
1412
1440
|
sendInternalMessageAndExpect,
|
|
1413
|
-
|
|
1441
|
+
LzDict,
|
|
1442
|
+
toHaveTransactions,
|
|
1443
|
+
addLibToBlockchain
|
|
1414
1444
|
} from '@layerzerolabs/ton-sdk-tools'
|
|
1415
1445
|
|
|
1416
1446
|
import {
|
|
1417
|
-
LzDict,
|
|
1418
1447
|
LzEventHandler,
|
|
1419
1448
|
MdPacketSent,
|
|
1420
1449
|
OPCODES,
|
|
@@ -1451,10 +1480,6 @@ export const newTonObjectsContainer: { items: { [key: string]: unknown } } = {
|
|
|
1451
1480
|
items: {},
|
|
1452
1481
|
}
|
|
1453
1482
|
|
|
1454
|
-
export const PUBLIC_KEY_BYTE_LENGTH = 64
|
|
1455
|
-
export const SIGNATURE_BYTE_LENGTH = 65
|
|
1456
|
-
const SEED_SIZE = 32
|
|
1457
|
-
|
|
1458
1483
|
// ==============================PROTOCOL SETUP GAS==============================
|
|
1459
1484
|
|
|
1460
1485
|
// todo update these to be accurate when ready. To fragile now during development
|
|
@@ -1488,40 +1513,6 @@ export const OAppFlowGas = {
|
|
|
1488
1513
|
|
|
1489
1514
|
export const emptyObject = beginCell().storeUint(0, 1).endCell()
|
|
1490
1515
|
|
|
1491
|
-
// ===============================INTERFACES===============================
|
|
1492
|
-
|
|
1493
|
-
export function publicKeyToHash(publicKey: string): bigint {
|
|
1494
|
-
// Remove '0x' prefix and convert to Buffer
|
|
1495
|
-
const publicKeyBuffer = Buffer.from(publicKey.slice(2), 'hex')
|
|
1496
|
-
// skip the first byte (h) as it's always 4
|
|
1497
|
-
const publicKeyWithoutH = publicKeyBuffer.subarray(1)
|
|
1498
|
-
const publicKeyCell = beginCell().storeBuffer(publicKeyWithoutH, PUBLIC_KEY_BYTE_LENGTH).endCell()
|
|
1499
|
-
const publicKeyHash = BigInt('0x' + publicKeyCell.hash().toString('hex'))
|
|
1500
|
-
return publicKeyHash
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
// ==============================VERIFIER SET==============================
|
|
1504
|
-
|
|
1505
|
-
export function generateRandomVerifierSet(count: number): ethers.Wallet[] {
|
|
1506
|
-
const verifiers: ethers.Wallet[] = []
|
|
1507
|
-
for (let i = 0; i < count; i++) {
|
|
1508
|
-
const privateKey = ethers.utils.randomBytes(SEED_SIZE)
|
|
1509
|
-
verifiers.push(new ethers.Wallet(privateKey))
|
|
1510
|
-
}
|
|
1511
|
-
return verifiers
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
export async function createVerifierDictSet(
|
|
1515
|
-
verifiers: ethers.Wallet[],
|
|
1516
|
-
wrapper: ExtendedContract<TonContractWrapper>
|
|
1517
|
-
): Promise<Cell> {
|
|
1518
|
-
const verifierDict = LzDict.empty()
|
|
1519
|
-
for (const verifier of verifiers) {
|
|
1520
|
-
await verifierDict.set(publicKeyToHash(verifier.publicKey), beginCell().endCell(), wrapper)
|
|
1521
|
-
}
|
|
1522
|
-
return verifierDict.asCell()
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
1516
|
export function serializeAddressList(admins: SandboxContract<TreasuryContract | TonContractWrapper>[]): Cell {
|
|
1526
1517
|
const addressList = admins.map((admin) => addressToBigInt(admin.address))
|
|
1527
1518
|
|
|
@@ -2013,17 +2004,6 @@ export async function getExecutionStatus(
|
|
|
2013
2004
|
return (await contract.getViewFunction('_viewExecutionStatus', args)).readBigNumber()
|
|
2014
2005
|
}
|
|
2015
2006
|
|
|
2016
|
-
export function addLibToBlockchain(blockchain: Blockchain, newLib: Cell): void {
|
|
2017
|
-
let libsDict: Dictionary<bigint, Cell>
|
|
2018
|
-
if (blockchain.libs) {
|
|
2019
|
-
libsDict = blockchain.libs.beginParse().loadDictDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell())
|
|
2020
|
-
} else {
|
|
2021
|
-
libsDict = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell())
|
|
2022
|
-
}
|
|
2023
|
-
libsDict.set(BigInt(\`0x\${newLib.hash().toString('hex')}\`), newLib)
|
|
2024
|
-
blockchain.libs = beginCell().storeDictDirect(libsDict).endCell()
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
2007
|
// ===============================DEPLOYING CONTRACTS===============================
|
|
2028
2008
|
|
|
2029
2009
|
export async function openAndDeployControllerViaMultiSig(
|
|
@@ -3160,7 +3140,7 @@ import ProxyArtifact from '@layerzerolabs/layerzero-v2-ton/build/Proxy.compiled.
|
|
|
3160
3140
|
import UlnArtifact from '@layerzerolabs/layerzero-v2-ton/build/Uln.compiled.json'
|
|
3161
3141
|
import UlnConnectionArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnConnection.compiled.json'
|
|
3162
3142
|
import UlnManagerArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnManager.compiled.json'
|
|
3163
|
-
import { BlueprintArtfiact, ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, } from '@layerzerolabs/ton-sdk-tools'
|
|
3143
|
+
import { BlueprintArtfiact, ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, LzDict, createSignatures, createVerifierDictSetFromEtherWallets, generateRandomVerifierSet } from '@layerzerolabs/ton-sdk-tools'
|
|
3164
3144
|
|
|
3165
3145
|
import {
|
|
3166
3146
|
OAppFixture,
|
|
@@ -3169,9 +3149,7 @@ import {
|
|
|
3169
3149
|
SIGNATURE_BYTE_LENGTH,
|
|
3170
3150
|
addMsgLibToController,
|
|
3171
3151
|
createLzPacketFromPacketEncoded,
|
|
3172
|
-
createVerifierDictSet,
|
|
3173
3152
|
emptyObject,
|
|
3174
|
-
generateRandomVerifierSet,
|
|
3175
3153
|
protocolSetupGas,
|
|
3176
3154
|
publicKeyToHash,
|
|
3177
3155
|
requireDefined,
|
|
@@ -3181,7 +3159,6 @@ import {
|
|
|
3181
3159
|
} from './auto-utils-common'
|
|
3182
3160
|
|
|
3183
3161
|
import {
|
|
3184
|
-
LzDict,
|
|
3185
3162
|
LzEventHandler,
|
|
3186
3163
|
MdPacketSent,
|
|
3187
3164
|
OPCODES,
|
|
@@ -3764,7 +3741,7 @@ export async function openAndDeployDvnAndProxy(
|
|
|
3764
3741
|
admins: serializeAddressList(adminSet),
|
|
3765
3742
|
version: version,
|
|
3766
3743
|
quorum: 1n,
|
|
3767
|
-
verifiers:
|
|
3744
|
+
verifiers: createVerifierDictSetFromEtherWallets(verifierSet),
|
|
3768
3745
|
})
|
|
3769
3746
|
)
|
|
3770
3747
|
)
|
|
@@ -4833,61 +4810,6 @@ export const dvnSetupGas = {
|
|
|
4833
4810
|
'Dvn.SEND_SIGNED_REQUEST': toNano('10'), // 0.235917
|
|
4834
4811
|
}
|
|
4835
4812
|
|
|
4836
|
-
export async function createAdminDictSet(
|
|
4837
|
-
admins: SandboxContract<TreasuryContract | TonContractWrapper>[],
|
|
4838
|
-
wrapper: ExtendedContract<TonContractWrapper>
|
|
4839
|
-
): Promise<Cell> {
|
|
4840
|
-
const adminDict = LzDict.empty()
|
|
4841
|
-
for (const admin of admins) {
|
|
4842
|
-
await adminDict.set(addressToBigInt(admin.address), beginCell().endCell(), wrapper)
|
|
4843
|
-
}
|
|
4844
|
-
return adminDict.asCell()
|
|
4845
|
-
}
|
|
4846
|
-
|
|
4847
|
-
export async function createSignatures(
|
|
4848
|
-
hash: Buffer,
|
|
4849
|
-
verifiers: ethers.Wallet[],
|
|
4850
|
-
wrapper: ExtendedContract<TonContractWrapper>
|
|
4851
|
-
): Promise<Cell> {
|
|
4852
|
-
const signatures = LzDict.empty()
|
|
4853
|
-
for (const verifier of verifiers) {
|
|
4854
|
-
// doing this one insted of .signMessage() to not sign with the "Ethereum" prefix
|
|
4855
|
-
const signature = verifier._signingKey().signDigest(hash)
|
|
4856
|
-
const signatureBytes = ethers.utils.splitSignature(signature)
|
|
4857
|
-
const signatureBytesArray = new Uint8Array([
|
|
4858
|
-
...ethers.utils.arrayify(signatureBytes.r),
|
|
4859
|
-
...ethers.utils.arrayify(signatureBytes.s),
|
|
4860
|
-
signatureBytes.v,
|
|
4861
|
-
])
|
|
4862
|
-
|
|
4863
|
-
await signatures.set(
|
|
4864
|
-
publicKeyToHash(verifier.publicKey),
|
|
4865
|
-
beginCell().storeBuffer(Buffer.from(signatureBytesArray), SIGNATURE_BYTE_LENGTH).endCell(),
|
|
4866
|
-
wrapper
|
|
4867
|
-
)
|
|
4868
|
-
|
|
4869
|
-
// Sanity Check: Attempt to recover the public key from the signature
|
|
4870
|
-
// const messageHash = ethers.utils.arrayify(hash)
|
|
4871
|
-
// try {
|
|
4872
|
-
// const recoveredPublicKey = ethers.utils.recoverPublicKey(messageHash, signatureBytes)
|
|
4873
|
-
// const originalPublicKey = verifier.publicKey
|
|
4874
|
-
|
|
4875
|
-
// console.log(\`Verifier:\`)
|
|
4876
|
-
// console.log(\`Original public key: \${originalPublicKey}\`)
|
|
4877
|
-
// console.log(\`Recovered public key: \${recoveredPublicKey}\`)
|
|
4878
|
-
|
|
4879
|
-
// if (recoveredPublicKey.toLowerCase() === originalPublicKey.toLowerCase()) {
|
|
4880
|
-
// console.log('Public key successfully recovered!')
|
|
4881
|
-
// } else {
|
|
4882
|
-
// console.log('Public key recovery failed.')
|
|
4883
|
-
// }
|
|
4884
|
-
// } catch (error) {
|
|
4885
|
-
// console.error(\`Error recovering public key for verifier:\`, error)
|
|
4886
|
-
// }
|
|
4887
|
-
}
|
|
4888
|
-
return signatures.asCell()
|
|
4889
|
-
}
|
|
4890
|
-
|
|
4891
4813
|
// ================================DVN: SEND REQUEST================================
|
|
4892
4814
|
|
|
4893
4815
|
interface SignAndSendRequestToDvnParams {
|
|
@@ -4911,7 +4833,7 @@ export async function signAndSendRequestToDvn({
|
|
|
4911
4833
|
}: SignAndSendRequestToDvnParams): Promise<SendMessageResult> {
|
|
4912
4834
|
const signedRequest = await allStorages.getNewMdSignedRequest({
|
|
4913
4835
|
request,
|
|
4914
|
-
signatures:
|
|
4836
|
+
signatures: createSignatures(request.hash(), verifierSet),
|
|
4915
4837
|
})
|
|
4916
4838
|
|
|
4917
4839
|
return sendInternalMessageAndExpect({
|
|
@@ -5178,7 +5100,7 @@ export async function ulnVerifyAndExpect(
|
|
|
5178
5100
|
opCode: OPCODES.Dvn_OP_VERIFY,
|
|
5179
5101
|
md: await allStorages.getNewMdSignedRequest({
|
|
5180
5102
|
request: requestMd,
|
|
5181
|
-
signatures:
|
|
5103
|
+
signatures: createSignatures(requestMd.hash(), verifiers),
|
|
5182
5104
|
}),
|
|
5183
5105
|
expectedTransactions: [
|
|
5184
5106
|
{
|
|
@@ -7015,6 +6937,30 @@ var printDeepDiff = (decodeClass, cellA, cellB) => {
|
|
|
7015
6937
|
)
|
|
7016
6938
|
);
|
|
7017
6939
|
};
|
|
6940
|
+
var LzDict = class _LzDict {
|
|
6941
|
+
constructor(data) {
|
|
6942
|
+
this._cell = data;
|
|
6943
|
+
}
|
|
6944
|
+
static empty() {
|
|
6945
|
+
return new _LzDict(core.beginCell().endCell());
|
|
6946
|
+
}
|
|
6947
|
+
async getCell(key, wrapper) {
|
|
6948
|
+
return wrapper.getDictCellItem(this._cell, key);
|
|
6949
|
+
}
|
|
6950
|
+
async getBigInt(key, wrapper) {
|
|
6951
|
+
return wrapper.getDictUint256Item(this._cell, key);
|
|
6952
|
+
}
|
|
6953
|
+
async set(key, value, wrapper) {
|
|
6954
|
+
this._cell = await wrapper.getSetDictItem(this._cell, key, value);
|
|
6955
|
+
}
|
|
6956
|
+
asCell() {
|
|
6957
|
+
return this._cell;
|
|
6958
|
+
}
|
|
6959
|
+
};
|
|
6960
|
+
async function getLzDict(obj, fieldName, wrapper) {
|
|
6961
|
+
const dictCell = await wrapper.getClDict(obj, fieldName);
|
|
6962
|
+
return new LzDict(dictCell);
|
|
6963
|
+
}
|
|
7018
6964
|
|
|
7019
6965
|
exports.BASE_CHAIN_ID = BASE_CHAIN_ID;
|
|
7020
6966
|
exports.BaseWrapper = BaseWrapper;
|
|
@@ -7022,6 +6968,7 @@ exports.ClasslibWrapper = ClasslibWrapper;
|
|
|
7022
6968
|
exports.Errors = Errors;
|
|
7023
6969
|
exports.JettonMinter = JettonMinter;
|
|
7024
6970
|
exports.JettonWallet = JettonWallet;
|
|
6971
|
+
exports.LzDict = LzDict;
|
|
7025
6972
|
exports.MASTER_CHAIN_ID = MASTER_CHAIN_ID;
|
|
7026
6973
|
exports.MASTER_CHAIN_SHARD = MASTER_CHAIN_SHARD;
|
|
7027
6974
|
exports.MAX_CELL_BITS = MAX_CELL_BITS;
|
|
@@ -7033,8 +6980,11 @@ exports.NAME_WIDTH = NAME_WIDTH;
|
|
|
7033
6980
|
exports.Op = Op;
|
|
7034
6981
|
exports.Order = Order;
|
|
7035
6982
|
exports.PUBLIC_KEY_BYTE_LENGTH = PUBLIC_KEY_BYTE_LENGTH;
|
|
6983
|
+
exports.SEED_SIZE = SEED_SIZE;
|
|
6984
|
+
exports.SIGNATURE_BYTE_LENGTH = SIGNATURE_BYTE_LENGTH;
|
|
7036
6985
|
exports.Txiterator = Txiterator;
|
|
7037
6986
|
exports._getTypeWidth = _getTypeWidth;
|
|
6987
|
+
exports.addLibToBlockchain = addLibToBlockchain;
|
|
7038
6988
|
exports.addressToBigInt = addressToBigInt;
|
|
7039
6989
|
exports.addressToHex = addressToHex;
|
|
7040
6990
|
exports.asciiStringToBigint = asciiStringToBigint2;
|
|
@@ -7054,7 +7004,11 @@ exports.clGetCellRef = clGetCellRef;
|
|
|
7054
7004
|
exports.clGetUint = clGetUint;
|
|
7055
7005
|
exports.compareAddresses = compareAddresses;
|
|
7056
7006
|
exports.computedGeneric = computedGeneric;
|
|
7007
|
+
exports.createAdminDictSet = createAdminDictSet;
|
|
7008
|
+
exports.createSignatures = createSignatures;
|
|
7057
7009
|
exports.createVerifierDictSet = createVerifierDictSet;
|
|
7010
|
+
exports.createVerifierDictSetFromEtherWallets = createVerifierDictSetFromEtherWallets;
|
|
7011
|
+
exports.createVerifierDictSetFromStrings = createVerifierDictSetFromStrings;
|
|
7058
7012
|
exports.deepDecode = deepDecode;
|
|
7059
7013
|
exports.deepDiff = deepDiff;
|
|
7060
7014
|
exports.deserializeAddressList = deserializeAddressList;
|
|
@@ -7081,6 +7035,7 @@ exports.generateConstructorCode = generateConstructorCode;
|
|
|
7081
7035
|
exports.generateDecodeClass = generateDecodeClass;
|
|
7082
7036
|
exports.generateDeconstructorCode = generateDeconstructorCode;
|
|
7083
7037
|
exports.generateEncodeClass = generateEncodeClass;
|
|
7038
|
+
exports.generateRandomVerifierSet = generateRandomVerifierSet;
|
|
7084
7039
|
exports.generateSmlTestUtils = generateSmlTestUtils;
|
|
7085
7040
|
exports.generateTonClassType = generateTonClassType;
|
|
7086
7041
|
exports.generateUlnTestUtils = generateUlnTestUtils;
|
|
@@ -7088,6 +7043,7 @@ exports.getBocStringFromMessage = getBocStringFromMessage;
|
|
|
7088
7043
|
exports.getCellName = getCellName;
|
|
7089
7044
|
exports.getCellNameNumber = getCellNameNumber;
|
|
7090
7045
|
exports.getClosestByteAlignedBits = getClosestByteAlignedBits;
|
|
7046
|
+
exports.getLzDict = getLzDict;
|
|
7091
7047
|
exports.getMessageFromBocString = getMessageFromBocString;
|
|
7092
7048
|
exports.getMsgPrices = getMsgPrices;
|
|
7093
7049
|
exports.getOpcodeCRC = getOpcodeCRC;
|
|
@@ -7112,6 +7068,7 @@ exports.openAndDeployAllStoragesTemplate = openAndDeployAllStoragesTemplate;
|
|
|
7112
7068
|
exports.orderConfigToCell = orderConfigToCell;
|
|
7113
7069
|
exports.parseDirectory = parseDirectory;
|
|
7114
7070
|
exports.parseTonAddress = parseTonAddress;
|
|
7071
|
+
exports.preprocessPublicKey = preprocessPublicKey;
|
|
7115
7072
|
exports.printDeepDecode = printDeepDecode;
|
|
7116
7073
|
exports.printDeepDiff = printDeepDiff;
|
|
7117
7074
|
exports.printTransactionTrace = printTransactionTrace;
|
|
@@ -7133,6 +7090,7 @@ exports.serializePayees = serializePayees;
|
|
|
7133
7090
|
exports.setLzTonSdkSaveToJson = setLzTonSdkSaveToJson;
|
|
7134
7091
|
exports.setLzTonSdkWriteToConsole = setLzTonSdkWriteToConsole;
|
|
7135
7092
|
exports.storageCollected = storageCollected;
|
|
7093
|
+
exports.stringPublicKeyToHash = stringPublicKeyToHash;
|
|
7136
7094
|
exports.to32ByteBuffer = to32ByteBuffer;
|
|
7137
7095
|
exports.toHaveTransactions = toHaveTransactions;
|
|
7138
7096
|
exports.toPathArray = toPathArray;
|