@tonappchain/sdk 0.7.0-rc12 → 0.7.0-rc14
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/adapters/contractOpener.js +33 -4
- package/dist/sdk/Configuration.js +15 -10
- package/dist/sdk/LiteSequencerClient.js +2 -0
- package/dist/sdk/Utils.d.ts +1 -0
- package/dist/sdk/Utils.js +6 -0
- package/dist/structs/InternalStruct.d.ts +1 -0
- package/dist/structs/Struct.d.ts +1 -0
- package/dist/wrappers/Settings.d.ts +5 -1
- package/dist/wrappers/Settings.js +17 -0
- package/package.json +1 -1
|
@@ -8,7 +8,38 @@ const ton_access_1 = require("@orbs-network/ton-access");
|
|
|
8
8
|
const ton_1 = require("@ton/ton");
|
|
9
9
|
const artifacts_1 = require("@tonappchain/artifacts");
|
|
10
10
|
const ton_lite_client_1 = require("@tonappchain/ton-lite-client");
|
|
11
|
+
const Utils_1 = require("../sdk/Utils");
|
|
11
12
|
const Struct_1 = require("../structs/Struct");
|
|
13
|
+
async function getHttpEndpointWithRetry(network, maxRetries = 5, delay = 1000) {
|
|
14
|
+
let lastError;
|
|
15
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
16
|
+
try {
|
|
17
|
+
return await (0, ton_access_1.getHttpEndpoint)({ network });
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
lastError = error;
|
|
21
|
+
if (attempt <= maxRetries) {
|
|
22
|
+
await (0, Utils_1.sleep)(delay);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
throw lastError || new Error('Failed to get HTTP endpoint after retries');
|
|
27
|
+
}
|
|
28
|
+
async function getHttpV4EndpointWithRetry(network, maxRetries = 5, delay = 1000) {
|
|
29
|
+
let lastError;
|
|
30
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
31
|
+
try {
|
|
32
|
+
return await (0, ton_access_1.getHttpV4Endpoint)({ network });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
lastError = error;
|
|
36
|
+
if (attempt <= maxRetries) {
|
|
37
|
+
await (0, Utils_1.sleep)(delay);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw lastError || new Error('Failed to get HTTP V4 endpoint after retries');
|
|
42
|
+
}
|
|
12
43
|
function intToIP(int) {
|
|
13
44
|
const part1 = int & 255;
|
|
14
45
|
const part2 = (int >> 8) & 255;
|
|
@@ -67,13 +98,11 @@ function sandboxOpener(blockchain) {
|
|
|
67
98
|
};
|
|
68
99
|
}
|
|
69
100
|
async function orbsOpener(network) {
|
|
70
|
-
const endpoint = await (
|
|
71
|
-
network,
|
|
72
|
-
});
|
|
101
|
+
const endpoint = await getHttpEndpointWithRetry(network);
|
|
73
102
|
return new ton_1.TonClient({ endpoint });
|
|
74
103
|
}
|
|
75
104
|
async function orbsOpener4(network, timeout = 10000) {
|
|
76
|
-
const endpoint = await (
|
|
105
|
+
const endpoint = await getHttpV4EndpointWithRetry(network);
|
|
77
106
|
const client4 = new ton_1.TonClient4({ endpoint, timeout });
|
|
78
107
|
return {
|
|
79
108
|
open: (contract) => client4.open(contract),
|
|
@@ -7,6 +7,7 @@ const ethers_1 = require("ethers");
|
|
|
7
7
|
const retryableContractOpener_1 = require("../adapters/retryableContractOpener");
|
|
8
8
|
const Struct_1 = require("../structs/Struct");
|
|
9
9
|
const Settings_1 = require("../wrappers/Settings");
|
|
10
|
+
const Utils_1 = require("./Utils");
|
|
10
11
|
const Validator_1 = require("./Validator");
|
|
11
12
|
class Configuration {
|
|
12
13
|
constructor(network, artifacts, TONParams, TACParams, liteSequencerEndpoints) {
|
|
@@ -17,8 +18,10 @@ class Configuration {
|
|
|
17
18
|
this.liteSequencerEndpoints = liteSequencerEndpoints;
|
|
18
19
|
}
|
|
19
20
|
static async create(network, artifacts, TONParams, TACParams, customLiteSequencerEndpoints, delay) {
|
|
20
|
-
const internalTONParams = await
|
|
21
|
-
|
|
21
|
+
const [internalTONParams, internalTACParams] = await Promise.all([
|
|
22
|
+
this.prepareTONParams(artifacts, TONParams, delay),
|
|
23
|
+
this.prepareTACParams(artifacts, TACParams),
|
|
24
|
+
]);
|
|
22
25
|
const liteSequencerEndpoints = customLiteSequencerEndpoints ??
|
|
23
26
|
(network === Struct_1.Network.TESTNET
|
|
24
27
|
? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
|
|
@@ -28,14 +31,16 @@ class Configuration {
|
|
|
28
31
|
static async prepareTONParams(artifacts, TONParams, delay) {
|
|
29
32
|
const contractOpener = TONParams?.contractOpener ?? (await (0, retryableContractOpener_1.createDefaultRetryableOpener)(artifacts, 3, delay));
|
|
30
33
|
const settingsAddress = TONParams?.settingsAddress ?? artifacts.TON_SETTINGS_ADDRESS;
|
|
31
|
-
const settings = contractOpener.open(
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const nftProxyAddress =
|
|
37
|
-
const
|
|
38
|
-
const
|
|
34
|
+
const settings = contractOpener.open(Settings_1.Settings.create(ton_1.Address.parse(settingsAddress)));
|
|
35
|
+
const allSettingsSlice = (await settings.getAll()).beginParse();
|
|
36
|
+
const allSettings = allSettingsSlice.loadDictDirect(ton_1.Dictionary.Keys.BigUint(256), ton_1.Dictionary.Values.Cell());
|
|
37
|
+
const crossChainLayerAddress = (0, Settings_1.getAddressString)(allSettings.get((0, Utils_1.sha256toBigInt)('CrossChainLayerAddress')));
|
|
38
|
+
const jettonProxyAddress = (0, Settings_1.getAddressString)(allSettings.get((0, Utils_1.sha256toBigInt)('JettonProxyAddress')));
|
|
39
|
+
const nftProxyAddress = (0, Settings_1.getAddressString)(allSettings.get((0, Utils_1.sha256toBigInt)('NFTProxyAddress')));
|
|
40
|
+
const jettonWalletCode = allSettings.get((0, Utils_1.sha256toBigInt)('JettonWalletCode'));
|
|
41
|
+
const jettonMinterCode = allSettings.get((0, Utils_1.sha256toBigInt)('JettonMinterCode'));
|
|
42
|
+
const nftItemCode = allSettings.get((0, Utils_1.sha256toBigInt)('NFTItemCode'));
|
|
43
|
+
const nftCollectionCode = allSettings.get((0, Utils_1.sha256toBigInt)('NFTCollectionCode'));
|
|
39
44
|
return {
|
|
40
45
|
contractOpener,
|
|
41
46
|
jettonProxyAddress,
|
|
@@ -131,10 +131,12 @@ class LiteSequencerClient {
|
|
|
131
131
|
tacPrice: {
|
|
132
132
|
spot: BigInt(raw.tacPrice.spot),
|
|
133
133
|
ema: BigInt(raw.tacPrice.ema),
|
|
134
|
+
decimals: raw.tacPrice.decimals,
|
|
134
135
|
},
|
|
135
136
|
tonPrice: {
|
|
136
137
|
spot: BigInt(raw.tonPrice.spot),
|
|
137
138
|
ema: BigInt(raw.tonPrice.ema),
|
|
139
|
+
decimals: raw.tonPrice.decimals,
|
|
138
140
|
},
|
|
139
141
|
};
|
|
140
142
|
}
|
package/dist/sdk/Utils.d.ts
CHANGED
package/dist/sdk/Utils.js
CHANGED
|
@@ -11,8 +11,10 @@ exports.calculateEVMTokenAddress = calculateEVMTokenAddress;
|
|
|
11
11
|
exports.waitUntilSuccess = waitUntilSuccess;
|
|
12
12
|
exports.formatObjectForLogging = formatObjectForLogging;
|
|
13
13
|
exports.aggregateTokens = aggregateTokens;
|
|
14
|
+
exports.sha256toBigInt = sha256toBigInt;
|
|
14
15
|
const ton_1 = require("@ton/ton");
|
|
15
16
|
const ethers_1 = require("ethers");
|
|
17
|
+
const ton_crypto_1 = require("ton-crypto");
|
|
16
18
|
const errors_1 = require("../errors");
|
|
17
19
|
const Struct_1 = require("../structs/Struct");
|
|
18
20
|
const Consts_1 = require("./Consts");
|
|
@@ -206,3 +208,7 @@ async function aggregateTokens(assets) {
|
|
|
206
208
|
ton,
|
|
207
209
|
};
|
|
208
210
|
}
|
|
211
|
+
function sha256toBigInt(ContractName) {
|
|
212
|
+
const hash = (0, ton_crypto_1.sha256_sync)(ContractName);
|
|
213
|
+
return BigInt('0x' + hash.toString('hex'));
|
|
214
|
+
}
|
package/dist/structs/Struct.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Cell, Contract, ContractProvider } from '@ton/ton';
|
|
2
2
|
import { Address } from '@ton/ton';
|
|
3
3
|
export declare class Settings implements Contract {
|
|
4
4
|
static create(address: Address): Settings;
|
|
@@ -7,4 +7,8 @@ export declare class Settings implements Contract {
|
|
|
7
7
|
getKeyFromString(ContractName: string): bigint;
|
|
8
8
|
getAddressSetting(provider: ContractProvider, ContractName: string): Promise<string>;
|
|
9
9
|
getCellSetting(provider: ContractProvider, setting: string): Promise<Cell>;
|
|
10
|
+
getAll(provider: ContractProvider): Promise<Cell>;
|
|
10
11
|
}
|
|
12
|
+
export declare function getAddressString(cell?: Cell): string;
|
|
13
|
+
export declare function getNumber(len: number, cell?: Cell): number;
|
|
14
|
+
export declare function getString(cell?: Cell): string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Settings = void 0;
|
|
4
|
+
exports.getAddressString = getAddressString;
|
|
5
|
+
exports.getNumber = getNumber;
|
|
6
|
+
exports.getString = getString;
|
|
7
|
+
const ton_1 = require("@ton/ton");
|
|
4
8
|
const ethers_1 = require("ethers");
|
|
5
9
|
const errors_1 = require("../errors");
|
|
6
10
|
class Settings {
|
|
@@ -34,5 +38,18 @@ class Settings {
|
|
|
34
38
|
}
|
|
35
39
|
return cell;
|
|
36
40
|
}
|
|
41
|
+
async getAll(provider) {
|
|
42
|
+
const { stack } = await provider.get('get_all', []);
|
|
43
|
+
return stack.readCellOpt() ?? (0, ton_1.beginCell)().endCell();
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
46
|
exports.Settings = Settings;
|
|
47
|
+
function getAddressString(cell) {
|
|
48
|
+
return cell?.beginParse().loadAddress().toString({ bounceable: true, testOnly: false }) ?? '';
|
|
49
|
+
}
|
|
50
|
+
function getNumber(len, cell) {
|
|
51
|
+
return cell?.beginParse().loadUint(len) ?? 0;
|
|
52
|
+
}
|
|
53
|
+
function getString(cell) {
|
|
54
|
+
return cell?.beginParse().loadStringTail() ?? '';
|
|
55
|
+
}
|