wan-ton-sdk 0.0.7 → 0.0.9

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.
Files changed (247) hide show
  1. package/dist/Bridge.compile.d.ts +2 -0
  2. package/dist/Bridge.compile.js +9 -0
  3. package/dist/Bridge.d.ts +208 -0
  4. package/dist/Bridge.js +468 -0
  5. package/dist/Fake.compile.d.ts +2 -0
  6. package/dist/Fake.compile.js +9 -0
  7. package/dist/GroupApprove.compile.d.ts +2 -0
  8. package/dist/GroupApprove.compile.js +7 -0
  9. package/dist/GroupApprove.d.ts +124 -0
  10. package/dist/GroupApprove.js +181 -0
  11. package/dist/JettonMinter.compile.d.ts +2 -0
  12. package/dist/JettonMinter.compile.js +6 -0
  13. package/dist/JettonMinter.d.ts +45 -0
  14. package/dist/JettonMinter.js +124 -0
  15. package/dist/JettonWallet.compile.d.ts +2 -0
  16. package/dist/JettonWallet.compile.js +6 -0
  17. package/dist/JettonWallet.d.ts +26 -0
  18. package/dist/JettonWallet.js +103 -0
  19. package/dist/Signature.compile.d.ts +2 -0
  20. package/dist/Signature.compile.js +7 -0
  21. package/dist/Signature.d.ts +44 -0
  22. package/dist/Signature.js +106 -0
  23. package/dist/address.compile.d.ts +2 -0
  24. package/dist/address.compile.js +9 -0
  25. package/dist/client/client-interface.d.ts +35 -0
  26. package/dist/client/client-interface.js +9 -0
  27. package/dist/client/client.d.ts +22 -0
  28. package/dist/client/client.js +86 -0
  29. package/dist/client/tonapi-client.d.ts +4630 -0
  30. package/dist/client/tonapi-client.js +5376 -0
  31. package/dist/code/encode-decode.d.ts +132 -0
  32. package/dist/code/encode-decode.js +645 -0
  33. package/dist/code/userLock.d.ts +39 -0
  34. package/dist/code/userLock.js +284 -0
  35. package/dist/common.d.ts +9 -0
  36. package/dist/common.js +45 -0
  37. package/dist/config/config-ex.d.ts +7 -0
  38. package/dist/config/config-ex.js +73 -0
  39. package/dist/const/const-value.d.ts +21 -0
  40. package/dist/const/const-value.js +26 -0
  41. package/dist/contractAccess/bridgeAccess.d.ts +10 -0
  42. package/dist/contractAccess/bridgeAccess.js +55 -0
  43. package/dist/contractAccess/groupApproveAccess.d.ts +10 -0
  44. package/dist/contractAccess/groupApproveAccess.js +54 -0
  45. package/dist/db/Db.d.ts +24 -0
  46. package/dist/db/Db.js +739 -0
  47. package/dist/db/DbAccess.d.ts +24 -0
  48. package/dist/db/DbAccess.js +211 -0
  49. package/dist/db/common.d.ts +5 -0
  50. package/dist/db/common.js +114 -0
  51. package/dist/event/getEvents.d.ts +17 -0
  52. package/dist/event/getEvents.js +387 -0
  53. package/dist/example/db/createDb-ex.d.ts +1 -0
  54. package/{example/createDb-ex.ts → dist/example/db/createDb-ex.js} +3 -4
  55. package/dist/example/db/dbFeedTrans-ex.d.ts +1 -0
  56. package/{example/dbFeedTrans-ex.ts → dist/example/db/dbFeedTrans-ex.js} +9 -11
  57. package/dist/example/event/getAllEvents-ex.d.ts +1 -0
  58. package/dist/example/event/getAllEvents-ex.js +70 -0
  59. package/dist/example/event/getEventByHash-ex.d.ts +1 -0
  60. package/{example/getEventByHash-ex.ts → dist/example/event/getEventByHash-ex.js} +21 -25
  61. package/dist/example/event/getEventsByRange-ex.d.ts +1 -0
  62. package/dist/example/event/getEventsByRange-ex.js +58 -0
  63. package/dist/example/getAllTrans.d.ts +1 -0
  64. package/dist/example/getAllTrans.js +30 -0
  65. package/dist/example/jetton/getJettonInfo-ex.d.ts +1 -0
  66. package/dist/example/jetton/getJettonInfo-ex.js +32 -0
  67. package/dist/example/lock-release/smgRelease-ex.d.ts +1 -0
  68. package/dist/example/lock-release/smgRelease-ex.js +134 -0
  69. package/dist/example/lock-release/userLock-ex.d.ts +1 -0
  70. package/dist/example/lock-release/userLock-ex.js +69 -0
  71. package/dist/example/manage/addSmg-ex.d.ts +1 -0
  72. package/dist/example/manage/addSmg-ex.js +59 -0
  73. package/dist/example/manage/compileContract-ex.d.ts +1 -0
  74. package/dist/example/manage/compileContract-ex.js +11 -0
  75. package/dist/example/manage/deploy-ex.d.ts +1 -0
  76. package/dist/example/manage/deploy-ex.js +58 -0
  77. package/dist/example/manage/setFee-ex.d.ts +1 -0
  78. package/dist/example/manage/setFee-ex.js +61 -0
  79. package/dist/example/manage/setFeeProxy.d.ts +1 -0
  80. package/dist/example/manage/setFeeProxy.js +47 -0
  81. package/dist/example/manage/upgradeBridgeSc-ex.d.ts +1 -0
  82. package/dist/example/manage/upgradeBridgeSc-ex.js +44 -0
  83. package/dist/example/token/AddToken-ex.d.ts +1 -0
  84. package/dist/example/token/AddToken-ex.js +113 -0
  85. package/dist/example/token/addTokenPair-ex.d.ts +1 -0
  86. package/dist/example/token/addTokenPair-ex.js +59 -0
  87. package/dist/example/token/delTokenPair-ex.d.ts +1 -0
  88. package/dist/example/token/delTokenPair-ex.js +49 -0
  89. package/dist/example/token/getTokenPair-ex.d.ts +1 -0
  90. package/dist/example/token/getTokenPair-ex.js +39 -0
  91. package/dist/example/token/mintToken-ex.d.ts +1 -0
  92. package/dist/example/token/mintToken-ex.js +56 -0
  93. package/dist/example/tran/converTranToTonTran.d.ts +1 -0
  94. package/dist/example/tran/converTranToTonTran.js +32 -0
  95. package/dist/example/tran/getTransByRange-ex.d.ts +1 -0
  96. package/{example/getTransByRange-ex.ts → dist/example/tran/getTransByRange-ex.js} +26 -40
  97. package/dist/example/tran/getTransaction-ex.d.ts +1 -0
  98. package/dist/example/tran/getTransaction-ex.js +47 -0
  99. package/dist/example/tran/isTranSuccess-ex.d.ts +1 -0
  100. package/dist/example/tran/isTranSuccess-ex.js +27 -0
  101. package/dist/fee/fee.d.ts +12 -0
  102. package/dist/fee/fee.js +21 -0
  103. package/dist/index.d.ts +15 -0
  104. package/dist/index.js +95 -0
  105. package/dist/jest.config.d.ts +3 -0
  106. package/dist/jest.config.js +8 -0
  107. package/dist/opcodes.d.ts +55 -0
  108. package/dist/opcodes.js +59 -0
  109. package/dist/sign/buildHash.d.ts +6 -0
  110. package/dist/sign/buildHash.js +39 -0
  111. package/dist/sign/rawTrans.d.ts +36 -0
  112. package/dist/sign/rawTrans.js +89 -0
  113. package/dist/sign/tools-secp256k1.d.ts +21 -0
  114. package/{sign → dist/sign}/tools-secp256k1.js +18 -44
  115. package/dist/testData/JettonMinter.compile.func.d.ts +2 -0
  116. package/dist/testData/JettonMinter.compile.func.js +13 -0
  117. package/dist/testData/JettonWallet.compile.func.d.ts +2 -0
  118. package/dist/testData/JettonWallet.compile.func.js +13 -0
  119. package/dist/testData/bridge.compile.func.d.ts +2 -0
  120. package/dist/testData/bridge.compile.func.js +13 -0
  121. package/dist/transResult/transResult.d.ts +29 -0
  122. package/dist/transResult/transResult.js +528 -0
  123. package/dist/utils/compileContract.d.ts +13 -0
  124. package/dist/utils/compileContract.js +54 -0
  125. package/dist/utils/logger.d.ts +16 -0
  126. package/dist/utils/logger.js +94 -0
  127. package/dist/utils/utils.d.ts +26 -0
  128. package/dist/utils/utils.js +330 -0
  129. package/dist/wallet/balance.d.ts +5 -0
  130. package/dist/wallet/balance.js +29 -0
  131. package/dist/wallet/jetton.d.ts +16 -0
  132. package/dist/wallet/jetton.js +171 -0
  133. package/dist/wallet/walletContract.d.ts +31 -0
  134. package/dist/wallet/walletContract.js +106 -0
  135. package/package.json +8 -6
  136. package/Bridge.compile.ts +0 -8
  137. package/Bridge.ts +0 -645
  138. package/Bridge.ts.org +0 -647
  139. package/Fake.compile.ts +0 -8
  140. package/GroupApprove.compile.ts +0 -6
  141. package/GroupApprove.ts +0 -274
  142. package/JettonMinter.compile.ts +0 -5
  143. package/JettonMinter.ts +0 -135
  144. package/JettonWallet.compile.ts +0 -5
  145. package/JettonWallet.ts +0 -127
  146. package/Signature.compile.ts +0 -6
  147. package/Signature.ts +0 -105
  148. package/address.compile.ts +0 -8
  149. package/client/1.json +0 -1730
  150. package/client/client.ts +0 -73
  151. package/client/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
  152. package/code/decode.spec.ts +0 -81
  153. package/code/encode-decode.ts +0 -622
  154. package/code/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
  155. package/code/log/wan-ton-sdk.out.2025-01-20 +0 -0
  156. package/code/userLock.ts +0 -291
  157. package/common.ts +0 -62
  158. package/config/config-ex.ts +0 -25
  159. package/config/config.ts +0 -1
  160. package/const/const-value.ts +0 -33
  161. package/contractAccess/bridgeAccess.ts +0 -60
  162. package/contractAccess/groupApproveAccess.ts +0 -59
  163. package/data/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs.json +0 -7348
  164. package/db/Db.spec.ts +0 -193
  165. package/db/Db.ts +0 -736
  166. package/db/DbAccess.spec.ts +0 -23
  167. package/db/DbAccess.ts +0 -186
  168. package/db/common.ts +0 -94
  169. package/db/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
  170. package/db/log/wan-ton-sdk.out.2025-04-21 +0 -0
  171. package/event/getEvents.ts +0 -441
  172. package/event/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
  173. package/event/log/wan-ton-sdk.out.2024-12-19 +0 -0
  174. package/example/0:1.txt +0 -1
  175. package/example/AddToken-ex.ts +0 -148
  176. package/example/README.md +0 -21
  177. package/example/addSmg-ex.ts +0 -78
  178. package/example/addTokenPair-ex.ts +0 -73
  179. package/example/compileContract-ex.ts +0 -10
  180. package/example/converTranToTonTran.ts +0 -43
  181. package/example/delTokenPair-ex.ts +0 -63
  182. package/example/deploy-ex.ts +0 -68
  183. package/example/getAllEvents-ex.ts +0 -61
  184. package/example/getAllTrans.ts +0 -32
  185. package/example/getContractState-ex.ts +0 -33
  186. package/example/getEvents-ex.ts +0 -55
  187. package/example/getJettonInfo-ex.ts +0 -44
  188. package/example/getTokenPair-ex.ts +0 -47
  189. package/example/getTransaction-ex.ts +0 -62
  190. package/example/isTranSuccess-ex.ts +0 -33
  191. package/example/locateTx-ex.ts +0 -44
  192. package/example/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -55
  193. package/example/log/wan-ton-sdk.out.2025-04-21 +0 -447
  194. package/example/log/wan-ton-sdk.out.2025-04-22 +0 -1918
  195. package/example/log/wan-ton-sdk.out.2025-04-23 +0 -4216
  196. package/example/log/wan-ton-sdk.out.2025-04-24.gz +0 -0
  197. package/example/log/wan-ton-sdk.out.2025-04-25 +0 -46814
  198. package/example/log/wan-ton-sdk.out.2025-04-27.gz +0 -0
  199. package/example/log/wan-ton-sdk.out.2025-04-28 +0 -4966
  200. package/example/log/wan-ton-sdk.out.2025-04-29 +0 -1328
  201. package/example/log/wan-ton-sdk.out.2025-04-30 +0 -9
  202. package/example/mintToken-ex.ts +0 -82
  203. package/example/setFee-ex.ts +0 -82
  204. package/example/setFeeProxy.ts +0 -70
  205. package/example/smgRelease-ex.ts +0 -173
  206. package/example/upgradeBridgeSc-ex.ts +0 -49
  207. package/example/userLock-ex.ts +0 -78
  208. package/fee/fee.ts +0 -23
  209. package/index.ts +0 -76
  210. package/jest.config.ts +0 -9
  211. package/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
  212. package/log/wan-ton-sdk.out.2025-04-21 +0 -0
  213. package/log/wan-ton-sdk.out.2025-04-30 +0 -10
  214. package/opcodes.ts +0 -58
  215. package/publish.sh +0 -78
  216. package/sign/buildHash.ts +0 -47
  217. package/sign/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
  218. package/sign/log/wan-ton-sdk.out.2025-04-14 +0 -3
  219. package/sign/rawTrans.spec.ts +0 -117
  220. package/sign/rawTrans.ts +0 -122
  221. package/testData/JettonMinter.compile.func.ts +0 -8
  222. package/testData/JettonWallet.compile.func.ts +0 -8
  223. package/testData/addressList.json +0 -6
  224. package/testData/bridge.compile.func.ts +0 -8
  225. package/testData/bridge.compiled.json +0 -1
  226. package/testData/contractAddress.json +0 -7
  227. package/testData/jettonTokenInfo.json +0 -14
  228. package/testData/prvlist.json +0 -6
  229. package/testData/smg.json +0 -5
  230. package/testData/tokenInfo.json +0 -23
  231. package/transResult/transResult.ts +0 -608
  232. package/tsconfig.json +0 -19
  233. package/utils/.compiled.json +0 -1
  234. package/utils/compileContract.ts +0 -60
  235. package/utils/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
  236. package/utils/log/wan-ton-sdk.out.2025-01-08 +0 -0
  237. package/utils/logger.spec.ts +0 -14
  238. package/utils/logger.ts +0 -96
  239. package/utils/utils.spec.ts +0 -21
  240. package/utils/utils.ts +0 -295
  241. package/wallet/balance.ts +0 -29
  242. package/wallet/jetton.spec.ts +0 -27
  243. package/wallet/jetton.ts +0 -159
  244. package/wallet/walletContract.spec.ts +0 -111
  245. package/wallet/walletContract.ts +0 -105
  246. /package/{client/log/wan-ton-sdk.out.2024-12-19 → dist/config/config.d.ts} +0 -0
  247. /package/{code/log/wan-ton-sdk.out.2025-01-15 → dist/config/config.js} +0 -0
@@ -0,0 +1,44 @@
1
+ import { Address, Cell, Contract, ContractProvider, Sender } from '@ton/core';
2
+ export type SignatureConfig = {
3
+ id: number;
4
+ counter: number;
5
+ };
6
+ export declare function signatureConfigToCell(config: SignatureConfig): Cell;
7
+ export declare const Opcodes: {
8
+ verify: number;
9
+ verifyEcdsa: number;
10
+ };
11
+ export declare class Signature implements Contract {
12
+ readonly address: Address;
13
+ readonly init?: {
14
+ code: Cell;
15
+ data: Cell;
16
+ };
17
+ constructor(address: Address, init?: {
18
+ code: Cell;
19
+ data: Cell;
20
+ });
21
+ static createFromAddress(address: Address): Signature;
22
+ static createFromConfig(config: SignatureConfig, code: Cell, workchain?: number): Signature;
23
+ sendDeploy(provider: ContractProvider, via: Sender, value: bigint): Promise<void>;
24
+ sendVerify(provider: ContractProvider, via: Sender, opts: {
25
+ s: bigint;
26
+ gpk_x: bigint;
27
+ gpk_y: bigint;
28
+ e: bigint;
29
+ p: bigint;
30
+ msg: bigint;
31
+ value: bigint;
32
+ queryID?: number;
33
+ }): Promise<void>;
34
+ sendVerifyEcdsa(provider: ContractProvider, via: Sender, opts: {
35
+ s: bigint;
36
+ gpk_x: bigint;
37
+ gpk_y: bigint;
38
+ e: bigint;
39
+ p: bigint;
40
+ msg: bigint;
41
+ value: bigint;
42
+ queryID?: number;
43
+ }): Promise<void>;
44
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Signature = exports.Opcodes = void 0;
37
+ exports.signatureConfigToCell = signatureConfigToCell;
38
+ const core_1 = require("@ton/core");
39
+ const opcodes = __importStar(require("./opcodes"));
40
+ function signatureConfigToCell(config) {
41
+ return (0, core_1.beginCell)().endCell();
42
+ }
43
+ exports.Opcodes = {
44
+ verify: 0x7e8764ef, //todo should update verify
45
+ verifyEcdsa: 0x7e8764ee,
46
+ };
47
+ class Signature {
48
+ constructor(address, init) {
49
+ this.address = address;
50
+ this.init = init;
51
+ }
52
+ static createFromAddress(address) {
53
+ return new Signature(address);
54
+ }
55
+ static createFromConfig(config, code, workchain = 0) {
56
+ const data = signatureConfigToCell(config);
57
+ const init = { code, data };
58
+ return new Signature((0, core_1.contractAddress)(workchain, init), init);
59
+ }
60
+ async sendDeploy(provider, via, value) {
61
+ await provider.internal(via, {
62
+ value,
63
+ sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
64
+ body: (0, core_1.beginCell)().endCell(),
65
+ });
66
+ }
67
+ async sendVerify(provider, via, opts) {
68
+ let extraCell = (0, core_1.beginCell)()
69
+ .storeUint(opts.e, 256)
70
+ .storeUint(opts.p, 256)
71
+ .storeUint(opts.msg, 256)
72
+ .endCell();
73
+ await provider.internal(via, {
74
+ value: opts.value,
75
+ sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
76
+ body: (0, core_1.beginCell)()
77
+ .storeUint(opcodes.OP_SIG_Verify, 32)
78
+ .storeUint(opts.queryID ?? 0, 64)
79
+ .storeUint(opts.s, 256)
80
+ .storeUint(opts.gpk_x, 256)
81
+ .storeUint(opts.gpk_y, 256)
82
+ .storeRef(extraCell)
83
+ .endCell(),
84
+ });
85
+ }
86
+ async sendVerifyEcdsa(provider, via, opts) {
87
+ let extraCell = (0, core_1.beginCell)()
88
+ .storeUint(opts.e, 256)
89
+ .storeUint(opts.p, 256)
90
+ .storeUint(opts.msg, 256)
91
+ .endCell();
92
+ await provider.internal(via, {
93
+ value: opts.value,
94
+ sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
95
+ body: (0, core_1.beginCell)()
96
+ .storeUint(opcodes.OP_SIG_VerifyEcdsa, 32)
97
+ .storeUint(opts.queryID ?? 0, 64)
98
+ .storeUint(opts.s, 256)
99
+ .storeUint(opts.gpk_x, 256)
100
+ .storeUint(opts.gpk_y, 256)
101
+ .storeRef(extraCell)
102
+ .endCell(),
103
+ });
104
+ }
105
+ }
106
+ exports.Signature = Signature;
@@ -0,0 +1,2 @@
1
+ import { CompilerConfig } from '@ton/blueprint';
2
+ export declare const compile: CompilerConfig;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compile = void 0;
4
+ exports.compile = {
5
+ lang: 'func',
6
+ targets: [
7
+ 'contracts/address.fc',
8
+ ],
9
+ };
@@ -0,0 +1,35 @@
1
+ import { Address, Contract, ContractProvider, OpenedContract, StateInit, Transaction } from "@ton/core";
2
+ export interface WanTonClient {
3
+ getBalance(address: Address): Promise<bigint>;
4
+ getTransactions(address: Address, opts: {
5
+ limit: number;
6
+ lt?: string;
7
+ hash?: string;
8
+ to_lt?: string;
9
+ inclusive?: boolean;
10
+ archival?: boolean;
11
+ }): Promise<Transaction[]>;
12
+ /**
13
+ * Get transaction by it's id
14
+ * @param address address
15
+ * @param lt logical time
16
+ * @param hash transaction hash
17
+ * @returns transaction or null if not exist
18
+ */
19
+ getTransaction(address: Address, lt: string, hash: string): Promise<Transaction | null>;
20
+ isContractDeployed(address: Address): Promise<boolean>;
21
+ /**
22
+ * Open contract
23
+ * @param src source contract
24
+ * @returns contract
25
+ */
26
+ open<T extends Contract>(src: T): OpenedContract<T>;
27
+ /**
28
+ * Create a provider
29
+ * @param address address
30
+ * @param init optional init
31
+ * @returns provider
32
+ */
33
+ provider(address: Address, init?: StateInit | null): ContractProvider;
34
+ }
35
+ export declare function IsWanTonClient(obj: any): obj is WanTonClient;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsWanTonClient = IsWanTonClient;
4
+ function IsWanTonClient(obj) {
5
+ return (typeof obj === 'object' &&
6
+ obj !== null &&
7
+ 'provider' in obj &&
8
+ typeof obj.provider === 'function' && !('treasury' in obj));
9
+ }
@@ -0,0 +1,22 @@
1
+ import { Network } from "@orbs-network/ton-access";
2
+ import { WanTonClient } from "./client-interface";
3
+ export interface TonClientConfig {
4
+ network: Network;
5
+ tonClientTimeout?: number;
6
+ }
7
+ export interface TonUrlConfig {
8
+ url?: string;
9
+ apiKey?: string;
10
+ vendor?: string;
11
+ }
12
+ export interface TonConfig {
13
+ network: TonClientConfig;
14
+ urls?: TonUrlConfig[];
15
+ usingDbCache?: boolean;
16
+ scanTrans?: boolean;
17
+ }
18
+ export declare function getGlobalTonConfig(): TonConfig;
19
+ export declare function isTestnet(): boolean;
20
+ export declare function getDBDataDir(): string;
21
+ export declare function wanTonSdkInit(tcf: TonConfig): Promise<void>;
22
+ export declare function getClient(): Promise<WanTonClient>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getGlobalTonConfig = getGlobalTonConfig;
7
+ exports.isTestnet = isTestnet;
8
+ exports.getDBDataDir = getDBDataDir;
9
+ exports.wanTonSdkInit = wanTonSdkInit;
10
+ exports.getClient = getClient;
11
+ const ton_1 = require("@ton/ton");
12
+ const ton_access_1 = require("@orbs-network/ton-access");
13
+ const crypto_1 = require("@ton/crypto");
14
+ const logger_1 = require("../utils/logger");
15
+ const const_value_1 = require("../const/const-value");
16
+ const DbAccess_1 = require("../db/DbAccess");
17
+ const path_1 = __importDefault(require("path"));
18
+ const tonapi_client_1 = require("./tonapi-client");
19
+ const formatUtil = require('util');
20
+ let g_tonConfig;
21
+ function getGlobalTonConfig() {
22
+ return g_tonConfig;
23
+ }
24
+ function isTestnet() {
25
+ if (!g_tonConfig) {
26
+ return false; // default mainnet
27
+ }
28
+ return g_tonConfig.network?.network == 'testnet';
29
+ }
30
+ let DBDataDir;
31
+ let buildDBDataDir = () => {
32
+ if (isTestnet()) {
33
+ DBDataDir = path_1.default.join(...[__dirname, "/../data/testnet/"]);
34
+ }
35
+ else {
36
+ DBDataDir = path_1.default.join(...[__dirname, "/../data/mainnet/"]);
37
+ }
38
+ logger_1.logger.info("__dirname", __dirname);
39
+ logger_1.logger.info("DBDataDir", DBDataDir);
40
+ };
41
+ function getDBDataDir() {
42
+ return DBDataDir;
43
+ }
44
+ async function wanTonSdkInit(tcf) {
45
+ if (tcf == null) {
46
+ throw new Error(`invalid ton config ${tcf}`);
47
+ }
48
+ g_tonConfig = tcf;
49
+ buildDBDataDir();
50
+ let dbAccess = await DbAccess_1.DBAccess.getDBAccess();
51
+ if (dbAccess) {
52
+ await dbAccess.init(g_tonConfig.scanTrans);
53
+ }
54
+ }
55
+ const toncenter_testnet_apikey = "73ee18f6b52a360e9db390f146a8c6af161549495d6e9794ae3efd2e412fa7a2";
56
+ const toncenter_apikey = "16f38715eb1a0984abf42148d5ed042589f8bf11768141ecb944feae8102913a";
57
+ const default_test_url = "https://testnet.toncenter.com/api/v2/jsonRPC";
58
+ const default_url = "https://toncenter.com/api/v2/jsonRPC";
59
+ async function getClient() {
60
+ logger_1.logger.info(formatUtil.format("getClient config %s", JSON.stringify(g_tonConfig)));
61
+ // get client by url
62
+ if (g_tonConfig.urls?.length) {
63
+ let urls = g_tonConfig.urls;
64
+ const totalUrls = urls.length;
65
+ const indexUsed = await (0, crypto_1.getSecureRandomNumber)(0, totalUrls);
66
+ if (urls[indexUsed].vendor?.toLowerCase() == 'tonapi') {
67
+ return new tonapi_client_1.TonApiClient({
68
+ baseUrl: urls[indexUsed].url
69
+ });
70
+ }
71
+ else {
72
+ return new ton_1.TonClient({ endpoint: urls[indexUsed].url ?? (g_tonConfig.network.network === 'mainnet' ? default_url : default_test_url),
73
+ timeout: g_tonConfig.network.tonClientTimeout ?? const_value_1.TONCLINET_TIMEOUT,
74
+ apiKey: urls[indexUsed].apiKey ?? (g_tonConfig.network.network === 'mainnet' ? toncenter_apikey : toncenter_testnet_apikey) });
75
+ }
76
+ }
77
+ // get client by orbs access
78
+ const endpoints = await (0, ton_access_1.getHttpEndpoints)({ network: g_tonConfig.network.network });
79
+ const total = endpoints.length;
80
+ if (!total) {
81
+ throw new Error("no http endpoint found!");
82
+ }
83
+ const indexUsed = await (0, crypto_1.getSecureRandomNumber)(0, total);
84
+ logger_1.logger.info(formatUtil.format("(orbos)http endpoint is =>", endpoints[indexUsed]));
85
+ return new ton_1.TonClient({ endpoint: endpoints[indexUsed], timeout: g_tonConfig.network.tonClientTimeout ?? const_value_1.TONCLINET_TIMEOUT });
86
+ }