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.
- package/dist/Bridge.compile.d.ts +2 -0
- package/dist/Bridge.compile.js +9 -0
- package/dist/Bridge.d.ts +208 -0
- package/dist/Bridge.js +468 -0
- package/dist/Fake.compile.d.ts +2 -0
- package/dist/Fake.compile.js +9 -0
- package/dist/GroupApprove.compile.d.ts +2 -0
- package/dist/GroupApprove.compile.js +7 -0
- package/dist/GroupApprove.d.ts +124 -0
- package/dist/GroupApprove.js +181 -0
- package/dist/JettonMinter.compile.d.ts +2 -0
- package/dist/JettonMinter.compile.js +6 -0
- package/dist/JettonMinter.d.ts +45 -0
- package/dist/JettonMinter.js +124 -0
- package/dist/JettonWallet.compile.d.ts +2 -0
- package/dist/JettonWallet.compile.js +6 -0
- package/dist/JettonWallet.d.ts +26 -0
- package/dist/JettonWallet.js +103 -0
- package/dist/Signature.compile.d.ts +2 -0
- package/dist/Signature.compile.js +7 -0
- package/dist/Signature.d.ts +44 -0
- package/dist/Signature.js +106 -0
- package/dist/address.compile.d.ts +2 -0
- package/dist/address.compile.js +9 -0
- package/dist/client/client-interface.d.ts +35 -0
- package/dist/client/client-interface.js +9 -0
- package/dist/client/client.d.ts +22 -0
- package/dist/client/client.js +86 -0
- package/dist/client/tonapi-client.d.ts +4630 -0
- package/dist/client/tonapi-client.js +5376 -0
- package/dist/code/encode-decode.d.ts +132 -0
- package/dist/code/encode-decode.js +645 -0
- package/dist/code/userLock.d.ts +39 -0
- package/dist/code/userLock.js +284 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +45 -0
- package/dist/config/config-ex.d.ts +7 -0
- package/dist/config/config-ex.js +73 -0
- package/dist/const/const-value.d.ts +21 -0
- package/dist/const/const-value.js +26 -0
- package/dist/contractAccess/bridgeAccess.d.ts +10 -0
- package/dist/contractAccess/bridgeAccess.js +55 -0
- package/dist/contractAccess/groupApproveAccess.d.ts +10 -0
- package/dist/contractAccess/groupApproveAccess.js +54 -0
- package/dist/db/Db.d.ts +24 -0
- package/dist/db/Db.js +739 -0
- package/dist/db/DbAccess.d.ts +24 -0
- package/dist/db/DbAccess.js +211 -0
- package/dist/db/common.d.ts +5 -0
- package/dist/db/common.js +114 -0
- package/dist/event/getEvents.d.ts +17 -0
- package/dist/event/getEvents.js +387 -0
- package/dist/example/db/createDb-ex.d.ts +1 -0
- package/{example/createDb-ex.ts → dist/example/db/createDb-ex.js} +3 -4
- package/dist/example/db/dbFeedTrans-ex.d.ts +1 -0
- package/{example/dbFeedTrans-ex.ts → dist/example/db/dbFeedTrans-ex.js} +9 -11
- package/dist/example/event/getAllEvents-ex.d.ts +1 -0
- package/dist/example/event/getAllEvents-ex.js +70 -0
- package/dist/example/event/getEventByHash-ex.d.ts +1 -0
- package/{example/getEventByHash-ex.ts → dist/example/event/getEventByHash-ex.js} +21 -25
- package/dist/example/event/getEventsByRange-ex.d.ts +1 -0
- package/dist/example/event/getEventsByRange-ex.js +58 -0
- package/dist/example/getAllTrans.d.ts +1 -0
- package/dist/example/getAllTrans.js +30 -0
- package/dist/example/jetton/getJettonInfo-ex.d.ts +1 -0
- package/dist/example/jetton/getJettonInfo-ex.js +32 -0
- package/dist/example/lock-release/smgRelease-ex.d.ts +1 -0
- package/dist/example/lock-release/smgRelease-ex.js +134 -0
- package/dist/example/lock-release/userLock-ex.d.ts +1 -0
- package/dist/example/lock-release/userLock-ex.js +69 -0
- package/dist/example/manage/addSmg-ex.d.ts +1 -0
- package/dist/example/manage/addSmg-ex.js +59 -0
- package/dist/example/manage/compileContract-ex.d.ts +1 -0
- package/dist/example/manage/compileContract-ex.js +11 -0
- package/dist/example/manage/deploy-ex.d.ts +1 -0
- package/dist/example/manage/deploy-ex.js +58 -0
- package/dist/example/manage/setFee-ex.d.ts +1 -0
- package/dist/example/manage/setFee-ex.js +61 -0
- package/dist/example/manage/setFeeProxy.d.ts +1 -0
- package/dist/example/manage/setFeeProxy.js +47 -0
- package/dist/example/manage/upgradeBridgeSc-ex.d.ts +1 -0
- package/dist/example/manage/upgradeBridgeSc-ex.js +44 -0
- package/dist/example/token/AddToken-ex.d.ts +1 -0
- package/dist/example/token/AddToken-ex.js +113 -0
- package/dist/example/token/addTokenPair-ex.d.ts +1 -0
- package/dist/example/token/addTokenPair-ex.js +59 -0
- package/dist/example/token/delTokenPair-ex.d.ts +1 -0
- package/dist/example/token/delTokenPair-ex.js +49 -0
- package/dist/example/token/getTokenPair-ex.d.ts +1 -0
- package/dist/example/token/getTokenPair-ex.js +39 -0
- package/dist/example/token/mintToken-ex.d.ts +1 -0
- package/dist/example/token/mintToken-ex.js +56 -0
- package/dist/example/tran/converTranToTonTran.d.ts +1 -0
- package/dist/example/tran/converTranToTonTran.js +32 -0
- package/dist/example/tran/getTransByRange-ex.d.ts +1 -0
- package/{example/getTransByRange-ex.ts → dist/example/tran/getTransByRange-ex.js} +26 -40
- package/dist/example/tran/getTransaction-ex.d.ts +1 -0
- package/dist/example/tran/getTransaction-ex.js +47 -0
- package/dist/example/tran/isTranSuccess-ex.d.ts +1 -0
- package/dist/example/tran/isTranSuccess-ex.js +27 -0
- package/dist/fee/fee.d.ts +12 -0
- package/dist/fee/fee.js +21 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +95 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +8 -0
- package/dist/opcodes.d.ts +55 -0
- package/dist/opcodes.js +59 -0
- package/dist/sign/buildHash.d.ts +6 -0
- package/dist/sign/buildHash.js +39 -0
- package/dist/sign/rawTrans.d.ts +36 -0
- package/dist/sign/rawTrans.js +89 -0
- package/dist/sign/tools-secp256k1.d.ts +21 -0
- package/{sign → dist/sign}/tools-secp256k1.js +18 -44
- package/dist/testData/JettonMinter.compile.func.d.ts +2 -0
- package/dist/testData/JettonMinter.compile.func.js +13 -0
- package/dist/testData/JettonWallet.compile.func.d.ts +2 -0
- package/dist/testData/JettonWallet.compile.func.js +13 -0
- package/dist/testData/bridge.compile.func.d.ts +2 -0
- package/dist/testData/bridge.compile.func.js +13 -0
- package/dist/transResult/transResult.d.ts +29 -0
- package/dist/transResult/transResult.js +528 -0
- package/dist/utils/compileContract.d.ts +13 -0
- package/dist/utils/compileContract.js +54 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +94 -0
- package/dist/utils/utils.d.ts +26 -0
- package/dist/utils/utils.js +330 -0
- package/dist/wallet/balance.d.ts +5 -0
- package/dist/wallet/balance.js +29 -0
- package/dist/wallet/jetton.d.ts +16 -0
- package/dist/wallet/jetton.js +171 -0
- package/dist/wallet/walletContract.d.ts +31 -0
- package/dist/wallet/walletContract.js +106 -0
- package/package.json +8 -6
- package/Bridge.compile.ts +0 -8
- package/Bridge.ts +0 -645
- package/Bridge.ts.org +0 -647
- package/Fake.compile.ts +0 -8
- package/GroupApprove.compile.ts +0 -6
- package/GroupApprove.ts +0 -274
- package/JettonMinter.compile.ts +0 -5
- package/JettonMinter.ts +0 -135
- package/JettonWallet.compile.ts +0 -5
- package/JettonWallet.ts +0 -127
- package/Signature.compile.ts +0 -6
- package/Signature.ts +0 -105
- package/address.compile.ts +0 -8
- package/client/1.json +0 -1730
- package/client/client.ts +0 -73
- package/client/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/code/decode.spec.ts +0 -81
- package/code/encode-decode.ts +0 -622
- package/code/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/code/log/wan-ton-sdk.out.2025-01-20 +0 -0
- package/code/userLock.ts +0 -291
- package/common.ts +0 -62
- package/config/config-ex.ts +0 -25
- package/config/config.ts +0 -1
- package/const/const-value.ts +0 -33
- package/contractAccess/bridgeAccess.ts +0 -60
- package/contractAccess/groupApproveAccess.ts +0 -59
- package/data/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs.json +0 -7348
- package/db/Db.spec.ts +0 -193
- package/db/Db.ts +0 -736
- package/db/DbAccess.spec.ts +0 -23
- package/db/DbAccess.ts +0 -186
- package/db/common.ts +0 -94
- package/db/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/db/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/event/getEvents.ts +0 -441
- package/event/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/event/log/wan-ton-sdk.out.2024-12-19 +0 -0
- package/example/0:1.txt +0 -1
- package/example/AddToken-ex.ts +0 -148
- package/example/README.md +0 -21
- package/example/addSmg-ex.ts +0 -78
- package/example/addTokenPair-ex.ts +0 -73
- package/example/compileContract-ex.ts +0 -10
- package/example/converTranToTonTran.ts +0 -43
- package/example/delTokenPair-ex.ts +0 -63
- package/example/deploy-ex.ts +0 -68
- package/example/getAllEvents-ex.ts +0 -61
- package/example/getAllTrans.ts +0 -32
- package/example/getContractState-ex.ts +0 -33
- package/example/getEvents-ex.ts +0 -55
- package/example/getJettonInfo-ex.ts +0 -44
- package/example/getTokenPair-ex.ts +0 -47
- package/example/getTransaction-ex.ts +0 -62
- package/example/isTranSuccess-ex.ts +0 -33
- package/example/locateTx-ex.ts +0 -44
- package/example/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -55
- package/example/log/wan-ton-sdk.out.2025-04-21 +0 -447
- package/example/log/wan-ton-sdk.out.2025-04-22 +0 -1918
- package/example/log/wan-ton-sdk.out.2025-04-23 +0 -4216
- package/example/log/wan-ton-sdk.out.2025-04-24.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-25 +0 -46814
- package/example/log/wan-ton-sdk.out.2025-04-27.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-28 +0 -4966
- package/example/log/wan-ton-sdk.out.2025-04-29 +0 -1328
- package/example/log/wan-ton-sdk.out.2025-04-30 +0 -9
- package/example/mintToken-ex.ts +0 -82
- package/example/setFee-ex.ts +0 -82
- package/example/setFeeProxy.ts +0 -70
- package/example/smgRelease-ex.ts +0 -173
- package/example/upgradeBridgeSc-ex.ts +0 -49
- package/example/userLock-ex.ts +0 -78
- package/fee/fee.ts +0 -23
- package/index.ts +0 -76
- package/jest.config.ts +0 -9
- package/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/log/wan-ton-sdk.out.2025-04-30 +0 -10
- package/opcodes.ts +0 -58
- package/publish.sh +0 -78
- package/sign/buildHash.ts +0 -47
- package/sign/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/sign/log/wan-ton-sdk.out.2025-04-14 +0 -3
- package/sign/rawTrans.spec.ts +0 -117
- package/sign/rawTrans.ts +0 -122
- package/testData/JettonMinter.compile.func.ts +0 -8
- package/testData/JettonWallet.compile.func.ts +0 -8
- package/testData/addressList.json +0 -6
- package/testData/bridge.compile.func.ts +0 -8
- package/testData/bridge.compiled.json +0 -1
- package/testData/contractAddress.json +0 -7
- package/testData/jettonTokenInfo.json +0 -14
- package/testData/prvlist.json +0 -6
- package/testData/smg.json +0 -5
- package/testData/tokenInfo.json +0 -23
- package/transResult/transResult.ts +0 -608
- package/tsconfig.json +0 -19
- package/utils/.compiled.json +0 -1
- package/utils/compileContract.ts +0 -60
- package/utils/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/utils/log/wan-ton-sdk.out.2025-01-08 +0 -0
- package/utils/logger.spec.ts +0 -14
- package/utils/logger.ts +0 -96
- package/utils/utils.spec.ts +0 -21
- package/utils/utils.ts +0 -295
- package/wallet/balance.ts +0 -29
- package/wallet/jetton.spec.ts +0 -27
- package/wallet/jetton.ts +0 -159
- package/wallet/walletContract.spec.ts +0 -111
- package/wallet/walletContract.ts +0 -105
- /package/{client/log/wan-ton-sdk.out.2024-12-19 → dist/config/config.d.ts} +0 -0
- /package/{code/log/wan-ton-sdk.out.2025-01-15 → dist/config/config.js} +0 -0
package/event/getEvents.ts
DELETED
@@ -1,441 +0,0 @@
|
|
1
|
-
import {Address, Cell, loadTransaction, openContract, Transaction} from "@ton/core";
|
2
|
-
import {TonClient} from "@ton/ton";
|
3
|
-
import {codeTable} from "../code/encode-decode";
|
4
|
-
|
5
|
-
|
6
|
-
import {logger} from '../utils/logger'
|
7
|
-
import {getTranResultByTran, getTranResultByTxHash, TranResult} from "../transResult/transResult";
|
8
|
-
import {ZERO_ACCOUNT_STR} from "../const/const-value";
|
9
|
-
const formatUtil = require('util');
|
10
|
-
import * as opcodes from "../opcodes";
|
11
|
-
import {OP_TRANSFER_NOTIFICATION} from "../opcodes";
|
12
|
-
import {getJettonAddress} from "../wallet/jetton";
|
13
|
-
import {getTokenPairInfo} from "../code/userLock";
|
14
|
-
import {
|
15
|
-
bigIntReplacer,
|
16
|
-
bigIntToBytes32,
|
17
|
-
formatError,
|
18
|
-
isAddressEqual,
|
19
|
-
isValidHexString,
|
20
|
-
sleep,
|
21
|
-
toBase64
|
22
|
-
} from "../utils/utils";
|
23
|
-
|
24
|
-
import {MAX_LIMIT,MAX_RETRY} from "../const/const-value";
|
25
|
-
import {DBAccess} from "../db/DbAccess";
|
26
|
-
/*
|
27
|
-
example of ret:
|
28
|
-
|
29
|
-
[{
|
30
|
-
eventName: 'AddTokenPair',
|
31
|
-
id: 3,
|
32
|
-
fromChainID: 4660,
|
33
|
-
fromAccount: 833589FCD6EDB6E08F4C7C32D4F71B54BDA02913,
|
34
|
-
toChainID: 17767,
|
35
|
-
toAccount: 0000000000000000000000000000000000000000000000000000000000000000,
|
36
|
-
txHashBase64: 'rqSZE1h0tWjn2EqI5awDLIDB4sLhUEwSdW+5fRUMmQE=',
|
37
|
-
txHash: 'aea499135874b568e7d84a88e5ac032c80c1e2c2e1504c12756fb97d150c9901',
|
38
|
-
lt: 29170426000001n
|
39
|
-
}]
|
40
|
-
|
41
|
-
*/
|
42
|
-
|
43
|
-
//todo block number (seq)
|
44
|
-
//todo from (first layer user, origin user.), and first layer hash.
|
45
|
-
//todo gas used (accumuted, summary.)
|
46
|
-
//todo in send Message, message body-> txhash.
|
47
|
-
|
48
|
-
|
49
|
-
export async function getEvents(client: TonClient,scAddress:string,limit:number,lt?:string,to_lt?:string,eventName?:string):Promise<any> {
|
50
|
-
|
51
|
-
console.log("scAddress:%s,limit:%s,lt:%s,to_lt:%s,eventName:%s",scAddress,limit,lt,to_lt,eventName);
|
52
|
-
if (!client){
|
53
|
-
throw new Error("client does not exist");
|
54
|
-
}
|
55
|
-
if (!Address.isAddress(Address.parse(scAddress))){
|
56
|
-
throw new Error("scAddress is invalid");
|
57
|
-
}
|
58
|
-
if(limit>MAX_LIMIT){
|
59
|
-
throw new Error("limit is more than MAX_LIMIT(1000)");
|
60
|
-
}
|
61
|
-
|
62
|
-
let events = [];
|
63
|
-
let trans = [];
|
64
|
-
|
65
|
-
while(true){
|
66
|
-
try {
|
67
|
-
trans = await getAllTransactions(client, scAddress, limit, MAX_RETRY);
|
68
|
-
break;
|
69
|
-
}catch(e){
|
70
|
-
console.error(formatError(e));
|
71
|
-
await sleep(5000);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
for(let tran of trans){
|
76
|
-
logger.info(formatUtil.format("tran=>",tran.hash().toString('base64')));
|
77
|
-
let event = await getEventFromTran(client,tran,scAddress);
|
78
|
-
if(event != null){
|
79
|
-
console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!==found event==!!!!!!!!!!!!!!!!!!!!!!!!!!!",event);
|
80
|
-
if(eventName && event.eventName.toLowerCase() != eventName.toLowerCase()){
|
81
|
-
continue;
|
82
|
-
}
|
83
|
-
events.push(event);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return events;
|
87
|
-
}
|
88
|
-
|
89
|
-
export async function getTransactions(client:TonClient,scAddress:string,opts:{
|
90
|
-
limit: number;
|
91
|
-
lt?: string;
|
92
|
-
hash?: string;
|
93
|
-
to_lt?: string;
|
94
|
-
inclusive?: boolean;
|
95
|
-
archival?: boolean;
|
96
|
-
}):Promise<any> {
|
97
|
-
console.log("getTransactions opts = %s",opts);
|
98
|
-
let scAddr = Address.parse(scAddress);
|
99
|
-
logger.info(formatUtil.format("contractAddr=>",scAddress));
|
100
|
-
let ret;
|
101
|
-
try{
|
102
|
-
//todo check change back
|
103
|
-
ret = await client.getTransactions(scAddr,opts)
|
104
|
-
//ret = await client.getTransactions(scAddr,{limit:3})
|
105
|
-
}catch(err){
|
106
|
-
logger.error(formatError(err));
|
107
|
-
}
|
108
|
-
return ret;
|
109
|
-
}
|
110
|
-
|
111
|
-
export async function getAllTransactions(client:TonClient,scAddress:string,limit:number, retry:number){
|
112
|
-
let trans = [];
|
113
|
-
let transCount = limit;
|
114
|
-
let opts: {
|
115
|
-
limit: number;
|
116
|
-
lt?: string;
|
117
|
-
hash?: string;
|
118
|
-
to_lt?: string;
|
119
|
-
inclusive?: boolean;
|
120
|
-
archival?: boolean;
|
121
|
-
} = {
|
122
|
-
limit,
|
123
|
-
archival:true,
|
124
|
-
}
|
125
|
-
let maxRetry = retry;
|
126
|
-
while(transCount){
|
127
|
-
let getSuccess = false
|
128
|
-
while(maxRetry-- >0 && (!getSuccess)){
|
129
|
-
try{
|
130
|
-
console.log("maxRetry = %s, getSuccess = %s, transCount = %s, scAddress = %s opts = %s",maxRetry,getSuccess,transCount,scAddress,JSON.stringify(opts,bigIntReplacer));
|
131
|
-
let ret = await client.getTransactions(Address.parse(scAddress),opts)
|
132
|
-
transCount = ret.length;
|
133
|
-
console.log("getTransactions success","opts",JSON.stringify(opts,bigIntReplacer),"len of getTransactions",transCount);
|
134
|
-
for(let tran of ret){
|
135
|
-
console.log("=====> tranHash = %s lt = %s",tran.hash().toString('base64'),tran.lt.toString(10));
|
136
|
-
trans.push(tran);
|
137
|
-
}
|
138
|
-
if(ret.length){
|
139
|
-
opts.lt = ret[ret.length-1].lt.toString(10);
|
140
|
-
opts.hash = ret[ret.length-1].hash().toString('base64');
|
141
|
-
}
|
142
|
-
getSuccess = true;
|
143
|
-
maxRetry = retry;
|
144
|
-
}catch(e){
|
145
|
-
console.error("err ",formatError(e));
|
146
|
-
await sleep(2000);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
if(maxRetry == 0){
|
150
|
-
throw(new Error(formatUtil("getTransactions failed after %d retry. opts is %s",retry,JSON.stringify(opts))));
|
151
|
-
}
|
152
|
-
|
153
|
-
await sleep(2000);
|
154
|
-
}
|
155
|
-
console.log("getAllTransactions success");
|
156
|
-
return trans;
|
157
|
-
}
|
158
|
-
|
159
|
-
export async function getEventFromTran(client:TonClient,tran:Transaction, scAddress:string){
|
160
|
-
let bodyCell = tran.inMessage?.body;
|
161
|
-
if(!bodyCell){
|
162
|
-
console.error("body is empty","tran",tran.hash().toString("base64"));
|
163
|
-
return null;
|
164
|
-
}
|
165
|
-
try{
|
166
|
-
let opCode = await getOpCodeFromCell(bodyCell);
|
167
|
-
logger.info(formatUtil.format("opCode=>",opCode.toString(16)));
|
168
|
-
logger.info(formatUtil.format("codeTable[opCode]=>",codeTable[opCode]));
|
169
|
-
if(!codeTable[opCode]){
|
170
|
-
console.error("opCode is empty","tran","opCode",opCode.toString(16));
|
171
|
-
return null;
|
172
|
-
}
|
173
|
-
console.log("before decode bodyCell");
|
174
|
-
let decoded = await codeTable[opCode]["deCode"](bodyCell);
|
175
|
-
console.log("after decode bodyCell");
|
176
|
-
decoded.txHashBase64 = tran.hash().toString("base64");
|
177
|
-
decoded.txHash = tran.hash().toString("hex");
|
178
|
-
|
179
|
-
decoded.lt = tran.lt;
|
180
|
-
decoded.prevTransactionHash = tran.prevTransactionHash
|
181
|
-
decoded.prevTransactionLt = tran.prevTransactionLt
|
182
|
-
|
183
|
-
// handle userLock
|
184
|
-
if(opCode == opcodes.OP_CROSS_UserLock){
|
185
|
-
logger.info(formatUtil.format("getEventFromTran OP_CROSS_UserLock"));
|
186
|
-
|
187
|
-
let handleResult = await handleUserLockEvent(client,Address.parse(scAddress),tran)
|
188
|
-
if (!handleResult.valid){
|
189
|
-
logger.error(formatUtil.format("handleResult OP_CROSS_UserLock is not valid"));
|
190
|
-
return null;
|
191
|
-
}
|
192
|
-
decoded.origin = handleResult.origin;
|
193
|
-
}else{
|
194
|
-
let handleResult = await handleCommonEvent(client,Address.parse(scAddress),
|
195
|
-
tran)
|
196
|
-
if (!handleResult.valid){
|
197
|
-
logger.error(formatUtil.format("handleResult handleCommonEvent is not valid"));
|
198
|
-
return null;
|
199
|
-
}
|
200
|
-
decoded.origin = handleResult.origin;
|
201
|
-
}
|
202
|
-
|
203
|
-
return await codeTable[opCode]["emitEvent"](decoded);
|
204
|
-
}catch(err){
|
205
|
-
logger.error(formatUtil.format("getEventFromTran err",formatError(err)));
|
206
|
-
return null;
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
210
|
-
export async function getTransaction(client:TonClient,scAddress:string,lt:string,tranHash:string){
|
211
|
-
// todo should add below code
|
212
|
-
console.log("Entering getTransaction","scAddress",scAddress,"lt",lt,"hash",tranHash,"hash(base64)",toBase64(tranHash));
|
213
|
-
let retTranFromDb = await getTransactionFromDb(client,scAddress,lt,toBase64(tranHash));
|
214
|
-
console.log("getTransaction","getTransactionFromDb","retTranFromDb",retTranFromDb);
|
215
|
-
if(retTranFromDb){
|
216
|
-
return retTranFromDb;
|
217
|
-
}
|
218
|
-
|
219
|
-
let tran:Transaction;
|
220
|
-
let trans:Transaction[] = [];
|
221
|
-
let retry = 2
|
222
|
-
let status = false;
|
223
|
-
let foundTran = false;
|
224
|
-
|
225
|
-
let maxTrans = 1000;
|
226
|
-
let transChecked = 0;
|
227
|
-
|
228
|
-
while(retry-- > 0){
|
229
|
-
try{
|
230
|
-
console.log("before client.getTransaction","scAddress",scAddress,"lt",lt,"hash",tranHash,"hash(base64)",toBase64(tranHash));
|
231
|
-
tran = await client.getTransaction(Address.parse(scAddress),lt,toBase64(tranHash)); // cannot compute block with specified transaction: cannot find block (0,e56031f43e6493da) lt=33028010000003: lt not in db'
|
232
|
-
console.log("tran = >",tran);
|
233
|
-
return tran;
|
234
|
-
}catch(err){
|
235
|
-
console.error("getTransaction","client.getTransaction error",formatError(err),"scAddress",scAddress,"lt",lt,"hash",tranHash,"hash(base64)",toBase64(tranHash));
|
236
|
-
await sleep(2000);
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
retry = MAX_RETRY;
|
241
|
-
let opts:{
|
242
|
-
limit: number;
|
243
|
-
lt?: string;
|
244
|
-
hash?: string;
|
245
|
-
to_lt?: string;
|
246
|
-
inclusive?: boolean;
|
247
|
-
archival?: boolean;
|
248
|
-
} = {
|
249
|
-
limit: MAX_LIMIT,
|
250
|
-
archival:true,
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
while(transChecked<maxTrans && !foundTran){
|
255
|
-
status = false;
|
256
|
-
while(--retry > 0 && !status){
|
257
|
-
try{
|
258
|
-
|
259
|
-
console.log("getTransactions","scAddress",scAddress,"opts",opts);
|
260
|
-
trans = await client.getTransactions(Address.parse(scAddress),opts);
|
261
|
-
status = true;
|
262
|
-
retry = MAX_RETRY;
|
263
|
-
}catch(err){
|
264
|
-
//console.error(err.message,err.response?.data?.error,err);
|
265
|
-
console.error(formatError(err))
|
266
|
-
await sleep(2000);
|
267
|
-
}
|
268
|
-
}
|
269
|
-
if(retry == 0){
|
270
|
-
throw(new Error(formatUtil.format("getTransactions ","scAddress",scAddress,"opts",opts)))
|
271
|
-
}
|
272
|
-
if(trans.length == 0){
|
273
|
-
break;
|
274
|
-
}
|
275
|
-
for (let i=0; i<trans.length; i++) {
|
276
|
-
let tx = trans[i]
|
277
|
-
if(i == trans.length-1) {
|
278
|
-
opts.lt = tx.lt.toString(10);
|
279
|
-
opts.hash = tx.hash().toString('base64');
|
280
|
-
}
|
281
|
-
console.log("getTransactions from rpc","i",i,"txHash",tx.hash().toString("base64"));
|
282
|
-
if(tx.hash().toString('base64') == toBase64(tranHash)){
|
283
|
-
tran = tx;
|
284
|
-
foundTran = true;
|
285
|
-
break;
|
286
|
-
}
|
287
|
-
}
|
288
|
-
|
289
|
-
await sleep(2000);
|
290
|
-
transChecked += trans.length;
|
291
|
-
}
|
292
|
-
if(foundTran){
|
293
|
-
return tran;
|
294
|
-
}
|
295
|
-
throw(new Error(formatUtil.format("can not getTransactions ","scAddress",scAddress,"opts",opts)),"hash",tranHash,"hash(bse64)",toBase64(tranHash));
|
296
|
-
}
|
297
|
-
// tranHash: base64
|
298
|
-
export async function getTransactionFromDb(client:TonClient,scAddress:string,lt:string,tranHash:string){
|
299
|
-
console.log("Entering getTransactionFromDb","scAddress",scAddress,"lt",lt,"tranHash",tranHash);
|
300
|
-
let dbAccess = await DBAccess.getDBAccess();
|
301
|
-
if(!dbAccess){
|
302
|
-
console.error("not using db cache");
|
303
|
-
return null;
|
304
|
-
}
|
305
|
-
let retTx = null;
|
306
|
-
let retry = MAX_RETRY;
|
307
|
-
while(retry-- > 0 && !retTx){
|
308
|
-
try{
|
309
|
-
if(!dbAccess?.has(scAddress)){
|
310
|
-
await dbAccess.addDbByName(scAddress);
|
311
|
-
}
|
312
|
-
retTx = await dbAccess?.getTxByHashLt(scAddress,tranHash,lt)
|
313
|
-
}catch(err){
|
314
|
-
console.error("getTxByHashLt err",formatError(err),"retry",retry,"dbName","scAddress",scAddress,"hash",tranHash)
|
315
|
-
}
|
316
|
-
await sleep(10000);
|
317
|
-
}
|
318
|
-
console.log("getTransactionFromDb success","scAddress",scAddress,"lt",lt,"tranHash",tranHash,"retTx",retTx);
|
319
|
-
return retTx
|
320
|
-
}
|
321
|
-
|
322
|
-
export async function getEventByTranHash(client:TonClient, scAddress:string, lt:string, tranHash:string){
|
323
|
-
let tran = await getTransaction(client,scAddress,lt,tranHash);
|
324
|
-
console.log("getEventByTranHash getTransaction success",tran, "tranHash ",tran.hash().toString('hex'));
|
325
|
-
return await getEventFromTran(client,tran,scAddress);
|
326
|
-
}
|
327
|
-
|
328
|
-
export async function getOpCodeFromCell(cell:Cell){
|
329
|
-
if(cell.equals(Cell.EMPTY)){
|
330
|
-
throw new Error("empty cell");
|
331
|
-
}
|
332
|
-
let slice = cell.beginParse();
|
333
|
-
try{
|
334
|
-
return slice.preloadUint(32);
|
335
|
-
}catch(err){
|
336
|
-
logger.error(formatUtil.format("getOpCodeFromCell(err)=>",formatError(err)));
|
337
|
-
throw new Error("no opCode find");
|
338
|
-
}
|
339
|
-
}
|
340
|
-
/*
|
341
|
-
{
|
342
|
-
valid: true|false, // used the trans tree is valid
|
343
|
-
origin: Address, // from address, who trigger the lock event.
|
344
|
-
}
|
345
|
-
*/
|
346
|
-
|
347
|
-
async function handleUserLockEvent(client:TonClient, scAddr:Address,tran:Transaction){
|
348
|
-
|
349
|
-
logger.info(formatUtil.format("Entering handleUserLockEvent"));
|
350
|
-
|
351
|
-
let transResult = await getTransResult(client,scAddr,tran);
|
352
|
-
if (!transResult.success){
|
353
|
-
logger.error("the trans tree is not success")
|
354
|
-
return {
|
355
|
-
valid:false,
|
356
|
-
origin:transResult.originAddr.toString()
|
357
|
-
}
|
358
|
-
}
|
359
|
-
|
360
|
-
let bodyCellLock = tran.inMessage.body
|
361
|
-
let decodedResult = await decodeUserLock(bodyCellLock);
|
362
|
-
console.log("decodeResult of decodeUserLock", decodedResult);
|
363
|
-
|
364
|
-
//handle bridge->bridge(userLock)
|
365
|
-
// get parent trans
|
366
|
-
let preTx = await getTransaction(client,scAddr.toString(),tran.prevTransactionLt.toString(10),bigIntToBytes32(tran.prevTransactionHash).toString('base64'));
|
367
|
-
let bodyCell = preTx.inMessage.body
|
368
|
-
let bodySlice = bodyCell.beginParse();
|
369
|
-
let op = bodySlice.loadUint(32);
|
370
|
-
if(op == opcodes.OP_TRANSFER_NOTIFICATION){
|
371
|
-
let fromAddrHead = preTx.inMessage.info.src
|
372
|
-
let ret = await getTokenPairInfo(client,scAddr,decodedResult.tokenPairID)
|
373
|
-
// 1. check tokenAccount content with the one get by tokenPairId
|
374
|
-
if(!isAddressEqual(decodedResult.addrTokenAccount,ret.tokenAccount)){
|
375
|
-
throw Error("invalid tokenpairid or tokenAccount");
|
376
|
-
}
|
377
|
-
// 2. check from address is content with the one computed by getJettonAddress
|
378
|
-
// build jettonAddress
|
379
|
-
let jwAddr = await getJettonAddress(client,Address.parse(ret.tokenAccount),scAddr)
|
380
|
-
console.log("======jwAddr",jwAddr.toString(),"preTx.inMessage.info.src",(preTx.inMessage.info.src as unknown as Address ).toString());
|
381
|
-
if(!isAddressEqual(jwAddr,(preTx.inMessage.info.src as unknown as Address ))){
|
382
|
-
throw Error("invalid from address of transfer notification");
|
383
|
-
}
|
384
|
-
}
|
385
|
-
return {
|
386
|
-
valid:true,
|
387
|
-
origin:transResult.originAddr.toString()
|
388
|
-
}
|
389
|
-
}
|
390
|
-
|
391
|
-
async function handleCommonEvent(client:TonClient, scAddr:Address,tran:Transaction){
|
392
|
-
|
393
|
-
logger.info(formatUtil.format("Entering handleCommonEvent"));
|
394
|
-
|
395
|
-
let transResult = await getTransResult(client,scAddr,tran);
|
396
|
-
if (!transResult.success){
|
397
|
-
logger.error("the trans tree is not success")
|
398
|
-
return {
|
399
|
-
valid:false,
|
400
|
-
origin:transResult.originAddr.toString()
|
401
|
-
}
|
402
|
-
}
|
403
|
-
return {
|
404
|
-
valid:true,
|
405
|
-
origin:transResult.originAddr.toString()
|
406
|
-
}
|
407
|
-
}
|
408
|
-
|
409
|
-
async function decodeUserLock(bodyCell:Cell){
|
410
|
-
let bodySlice = bodyCell.asSlice();
|
411
|
-
let queryId,dstUserAccount,addrTokenAccount,jwAddrSrc,jwAddrBridgeSc,opCode,smgID,tokenPairID,crossValue;
|
412
|
-
opCode = bodySlice.loadUint(32)
|
413
|
-
queryId = bodySlice.loadUint(64)
|
414
|
-
smgID = bodySlice.loadUintBig(256)
|
415
|
-
tokenPairID = bodySlice.loadUint(32)
|
416
|
-
crossValue = bodySlice.loadUintBig(256)
|
417
|
-
let dstUserAccountBufferLen = bodySlice.loadUint(8)
|
418
|
-
let dstUserAccountBuffer = bodySlice.loadBuffer(dstUserAccountBufferLen)
|
419
|
-
|
420
|
-
let extraSlice = bodySlice.loadRef().beginParse()
|
421
|
-
addrTokenAccount = extraSlice.loadAddress()
|
422
|
-
jwAddrSrc = extraSlice.loadAddress()
|
423
|
-
jwAddrBridgeSc = extraSlice.loadAddress()
|
424
|
-
extraSlice.endParse()
|
425
|
-
dstUserAccount = "0x"+dstUserAccountBuffer.toString('hex')
|
426
|
-
return{
|
427
|
-
opCode,
|
428
|
-
queryId,
|
429
|
-
smgID,
|
430
|
-
tokenPairID,
|
431
|
-
crossValue,
|
432
|
-
dstUserAccount,
|
433
|
-
addrTokenAccount,
|
434
|
-
jwAddrSrc,
|
435
|
-
jwAddrBridgeSc
|
436
|
-
}
|
437
|
-
}
|
438
|
-
|
439
|
-
async function getTransResult(client:TonClient, scAddr:Address,tran:Transaction){
|
440
|
-
return await getTranResultByTran(client,scAddr,tran);
|
441
|
-
}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"keep": {
|
3
|
-
"days": true,
|
4
|
-
"amount": 10
|
5
|
-
},
|
6
|
-
"auditLog": "log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json",
|
7
|
-
"files": [
|
8
|
-
{
|
9
|
-
"date": 1734594448578,
|
10
|
-
"name": "log/wan-ton-sdk.out.2024-12-19",
|
11
|
-
"hash": "8f7021c2aa135883a47cb5b704140258be3fbeb8b2a46849cc4bca83465c6191"
|
12
|
-
}
|
13
|
-
],
|
14
|
-
"hashType": "sha256"
|
15
|
-
}
|
File without changes
|
package/example/0:1.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
xxx
|
package/example/AddToken-ex.ts
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
import {TonClient} from "@ton/ton";
|
2
|
-
const fs = require("fs");
|
3
|
-
|
4
|
-
let jettonTokenInfo = require('../testData/jettonTokenInfo.json')
|
5
|
-
const jettonTokenInfoPath = "../testData/jettonTokenInfo.json";
|
6
|
-
|
7
|
-
let tokenInfo = require('../testData/tokenInfo.json')
|
8
|
-
const tokenInfoPath = "../testData/tokenInfo.json";
|
9
|
-
|
10
|
-
import {configTestnet,configMainnet} from "../config/config-ex";
|
11
|
-
|
12
|
-
import {Address, toNano, Sender} from '@ton/core';
|
13
|
-
import {
|
14
|
-
getJettonDataContent,
|
15
|
-
getJettonData,
|
16
|
-
buildWrappedJettonContent,
|
17
|
-
parseWrappedJettonContent, getJettonBalance, getJettonAddress
|
18
|
-
} from "../wallet/jetton";
|
19
|
-
import {doCompile} from "../utils/compileContract";
|
20
|
-
import {JettonMinter} from "../JettonMinter";
|
21
|
-
|
22
|
-
let args = process.argv.slice(2);
|
23
|
-
let jettonName = args[0];
|
24
|
-
|
25
|
-
const JettonCofig = jettonTokenInfo[jettonName]
|
26
|
-
|
27
|
-
import {getSenderByPrvKey, getWalletByPrvKey} from "../wallet/walletContract";
|
28
|
-
import {getClient, TonClientConfig, wanTonSdkInit} from "../client/client";
|
29
|
-
import {conf as JettonMinterCompilerConfig} from "../testData/JettonMinter.compile.func"
|
30
|
-
import {conf as JettonWalletCompilerConfig} from "../testData/JettonWallet.compile.func"
|
31
|
-
|
32
|
-
const prvList = require('../testData/prvlist')
|
33
|
-
|
34
|
-
let deployer =null,smgFeeProxy=null,oracleAdmin = null,robotAdmin = null;
|
35
|
-
let nonDeployer = null;
|
36
|
-
let client = null;
|
37
|
-
let via;
|
38
|
-
|
39
|
-
async function writeJettonTokenInfo(path:string,jettonTokenInfo:any){
|
40
|
-
fs.writeFileSync(path,jettonTokenInfo);
|
41
|
-
}
|
42
|
-
|
43
|
-
async function writeTokenInfo(path:string,jettonTokenInfo:any,jettonName:string){
|
44
|
-
console.log("tokenInfo=>",tokenInfo);
|
45
|
-
tokenInfo[jettonName].dstTokenAcc = jettonTokenInfo[jettonName].tokenAddress;
|
46
|
-
fs.writeFileSync(path,JSON.stringify(tokenInfo,null,2));
|
47
|
-
}
|
48
|
-
|
49
|
-
async function init(){
|
50
|
-
await wanTonSdkInit(configMainnet);
|
51
|
-
await wanTonSdkInit(configTestnet);
|
52
|
-
client = await getClient();
|
53
|
-
deployer = await getWalletByPrvKey(Buffer.from(prvList[0],'hex'));
|
54
|
-
nonDeployer = await getWalletByPrvKey(Buffer.from(prvList[1],'hex'));
|
55
|
-
via = await getSenderByPrvKey(client,Buffer.from(prvList[0],'hex'));
|
56
|
-
smgFeeProxy = deployer;
|
57
|
-
oracleAdmin = deployer;
|
58
|
-
robotAdmin = deployer;
|
59
|
-
|
60
|
-
}
|
61
|
-
|
62
|
-
import {isAddrDepolyed} from "../wallet/walletContract";
|
63
|
-
import {sleep} from "../utils/utils";
|
64
|
-
import {TON_FEE} from "../fee/fee";
|
65
|
-
|
66
|
-
async function DisplayJettonInfo(client:TonClient,addr:Address){
|
67
|
-
let ret = await getJettonData(client,addr);
|
68
|
-
console.log("getJettonData=>",ret)
|
69
|
-
|
70
|
-
let retJettonContent = await getJettonDataContent(client,addr);
|
71
|
-
console.log("getJettonDataContent=>",await parseWrappedJettonContent(retJettonContent));
|
72
|
-
}
|
73
|
-
|
74
|
-
const fwdAmount = TON_FEE.FWD_FEE_MINT_JETTON;
|
75
|
-
const totalAmount = TON_FEE.TOTAL_FEE_MINT_JETTON;
|
76
|
-
|
77
|
-
async function Mint(client:TonClient,via:Sender,jettonMasterAddr:Address,addr:Address, amount:bigint){
|
78
|
-
let jettMasterSc = await JettonMinter.createFromAddress(jettonMasterAddr);
|
79
|
-
let jettMasterScOpened = await client.open(jettMasterSc)
|
80
|
-
let ret = await jettMasterScOpened.sendMint(via,addr,amount,fwdAmount,totalAmount);
|
81
|
-
}
|
82
|
-
|
83
|
-
async function main() {
|
84
|
-
console.log("Entering main function");
|
85
|
-
await init();
|
86
|
-
let jettonContent = await buildWrappedJettonContent(JettonCofig);
|
87
|
-
|
88
|
-
let retMinter = await doCompile(JettonMinterCompilerConfig)
|
89
|
-
let retWallet = await doCompile(JettonWalletCompilerConfig)
|
90
|
-
|
91
|
-
let jettonMinterOpened = await client.open(
|
92
|
-
JettonMinter.createFromConfig(
|
93
|
-
{
|
94
|
-
admin: deployer.address, // set admin and deploy token in one step.
|
95
|
-
content: jettonContent,
|
96
|
-
wallet_code: retWallet.codeCell,
|
97
|
-
},
|
98
|
-
retMinter.codeCell));
|
99
|
-
|
100
|
-
jettonTokenInfo[jettonName].tokenAddress =jettonMinterOpened.address.toString();
|
101
|
-
await writeJettonTokenInfo(jettonTokenInfoPath,JSON.stringify(jettonTokenInfo,null,2));
|
102
|
-
await writeTokenInfo(tokenInfoPath,jettonTokenInfo,jettonName);
|
103
|
-
|
104
|
-
if(await isAddrDepolyed(client,jettonMinterOpened.address.toString())){
|
105
|
-
console.log("jettonMinter address :",jettonMinterOpened.address.toString(),"has already deployed");
|
106
|
-
return;
|
107
|
-
}else{
|
108
|
-
let retDeploy = await jettonMinterOpened.sendDeploy(via, TON_FEE.TRANS_FEE_NORMAL)
|
109
|
-
console.log("jettonMinter address :",jettonMinterOpened.address.toString());
|
110
|
-
console.log(retDeploy);
|
111
|
-
}
|
112
|
-
|
113
|
-
let jwAddrDeployer = await getJettonAddress(client,jettonMinterOpened.address,deployer.address);
|
114
|
-
console.log("deployer.jettonAddress=>",jwAddrDeployer.toString());
|
115
|
-
let b = await getJettonBalance(client,jettonMinterOpened.address,deployer.address);
|
116
|
-
console.log("Before mint balance = %s",b.toString(10));
|
117
|
-
console.log("Begin Mint.....");
|
118
|
-
await Mint(client,via,jettonMinterOpened.address,deployer.address,toNano('2'))
|
119
|
-
console.log("End Mint.....");
|
120
|
-
|
121
|
-
await sleep(5000)
|
122
|
-
await DisplayJettonInfo(client,jettonMinterOpened.address);
|
123
|
-
|
124
|
-
b = await getJettonBalance(client,jettonMinterOpened.address,deployer.address);
|
125
|
-
console.log("After mint balance = %s",b.toString(10));
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
let jwAddrNonDeployer = await getJettonAddress(client,jettonMinterOpened.address,nonDeployer.address);
|
130
|
-
console.log("nonDeployer.address=>",nonDeployer.address.toString());
|
131
|
-
console.log("nonDeployer.jettonAddress=>",jwAddrNonDeployer.toString());
|
132
|
-
b = await getJettonBalance(client,jettonMinterOpened.address,nonDeployer.address);
|
133
|
-
console.log("nonDeployer Before mint balance = %s",b.toString(10));
|
134
|
-
console.log("Begin Mint to nonDeployer.....");
|
135
|
-
await Mint(client,via,jettonMinterOpened.address,nonDeployer.address,toNano('3'))
|
136
|
-
console.log("End Mint to nonDeployer.....");
|
137
|
-
|
138
|
-
await sleep(5000)
|
139
|
-
await DisplayJettonInfo(client,jettonMinterOpened.address);
|
140
|
-
|
141
|
-
b = await getJettonBalance(client,jettonMinterOpened.address,nonDeployer.address);
|
142
|
-
console.log("nonDeployer After mint balance = %s",b.toString(10));
|
143
|
-
// await DisplayJettonInfo(client, Address.parse('EQCsALeDy_a3dzj21ZGMz-tuG9KIZVLmNUapfNtqGia8oqLk'));
|
144
|
-
}
|
145
|
-
|
146
|
-
main();
|
147
|
-
// ts-node AddToken-ex.ts tokenWrapped
|
148
|
-
// ts-node AddToken-ex.ts tokenOrg
|
package/example/README.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
for all test
|
2
|
-
# deploy contract
|
3
|
-
file: deploy-ex.ts
|
4
|
-
|
5
|
-
# Add token (Token on ton blockchaain)
|
6
|
-
file: AAddToken-ex.ts
|
7
|
-
|
8
|
-
# Add token pair
|
9
|
-
addTokenPair-ex.ts
|
10
|
-
|
11
|
-
# Add smg (oralce)
|
12
|
-
addSmg-ex.ts
|
13
|
-
|
14
|
-
# set fee
|
15
|
-
setFee-ex.ts
|
16
|
-
|
17
|
-
# userLock.ts
|
18
|
-
userLock-ex.ts
|
19
|
-
|
20
|
-
# smgRelease
|
21
|
-
smgRelease-ex.ts
|