wan-ton-sdk 0.0.6
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/Bridge.compile.ts +8 -0
- package/Bridge.ts +645 -0
- package/Bridge.ts.org +647 -0
- package/Fake.compile.ts +8 -0
- package/GroupApprove.compile.ts +6 -0
- package/GroupApprove.ts +274 -0
- package/JettonMinter.compile.ts +5 -0
- package/JettonMinter.ts +135 -0
- package/JettonWallet.compile.ts +5 -0
- package/JettonWallet.ts +127 -0
- package/README.md +24 -0
- package/Signature.compile.ts +6 -0
- package/Signature.ts +105 -0
- package/address.compile.ts +8 -0
- package/client/1.json +1730 -0
- package/client/client.ts +73 -0
- package/client/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +15 -0
- package/client/log/wan-ton-sdk.out.2024-12-19 +0 -0
- package/code/decode.spec.ts +81 -0
- package/code/encode-decode.ts +622 -0
- package/code/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +20 -0
- package/code/log/wan-ton-sdk.out.2025-01-15 +0 -0
- package/code/log/wan-ton-sdk.out.2025-01-20 +0 -0
- package/code/userLock.ts +291 -0
- package/common.ts +62 -0
- package/config/config-ex.ts +25 -0
- package/config/config.ts +1 -0
- package/const/const-value.ts +33 -0
- package/contractAccess/bridgeAccess.ts +60 -0
- package/contractAccess/groupApproveAccess.ts +59 -0
- package/data/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs.json +7348 -0
- package/db/Db.spec.ts +193 -0
- package/db/Db.ts +736 -0
- package/db/DbAccess.spec.ts +23 -0
- package/db/DbAccess.ts +174 -0
- package/db/common.ts +94 -0
- package/db/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +15 -0
- package/db/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/event/getEvents.ts +441 -0
- package/event/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +15 -0
- package/event/log/wan-ton-sdk.out.2024-12-19 +0 -0
- package/example/0:1.txt +1 -0
- package/example/AddToken-ex.ts +148 -0
- package/example/README.md +21 -0
- package/example/addSmg-ex.ts +78 -0
- package/example/addTokenPair-ex.ts +73 -0
- package/example/compileContract-ex.ts +10 -0
- package/example/converTranToTonTran.ts +43 -0
- package/example/createDb-ex.ts +8 -0
- package/example/dbFeedTrans-ex.ts +20 -0
- package/example/delTokenPair-ex.ts +63 -0
- package/example/deploy-ex.ts +68 -0
- package/example/getAllEvents-ex.ts +61 -0
- package/example/getAllTrans.ts +32 -0
- package/example/getContractState-ex.ts +33 -0
- package/example/getEventByHash-ex.ts +39 -0
- package/example/getEvents-ex.ts +55 -0
- package/example/getJettonInfo-ex.ts +44 -0
- package/example/getTokenPair-ex.ts +47 -0
- package/example/getTransByRange-ex.ts +81 -0
- package/example/getTransaction-ex.ts +62 -0
- package/example/isTranSuccess-ex.ts +33 -0
- package/example/locateTx-ex.ts +44 -0
- package/example/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +55 -0
- package/example/log/wan-ton-sdk.out.2025-04-21 +447 -0
- package/example/log/wan-ton-sdk.out.2025-04-22 +1918 -0
- package/example/log/wan-ton-sdk.out.2025-04-23 +4216 -0
- package/example/log/wan-ton-sdk.out.2025-04-24.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-25 +46814 -0
- package/example/log/wan-ton-sdk.out.2025-04-27.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-28 +4966 -0
- package/example/log/wan-ton-sdk.out.2025-04-29 +1328 -0
- package/example/log/wan-ton-sdk.out.2025-04-30 +9 -0
- package/example/mintToken-ex.ts +82 -0
- package/example/setFee-ex.ts +82 -0
- package/example/setFeeProxy.ts +70 -0
- package/example/smgRelease-ex.ts +173 -0
- package/example/upgradeBridgeSc-ex.ts +49 -0
- package/example/userLock-ex.ts +78 -0
- package/fee/fee.ts +23 -0
- package/index.ts +67 -0
- package/jest.config.ts +9 -0
- package/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +20 -0
- package/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/log/wan-ton-sdk.out.2025-04-30 +10 -0
- package/opcodes.ts +58 -0
- package/package.json +34 -0
- package/publish.sh +78 -0
- package/sign/buildHash.ts +47 -0
- package/sign/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +15 -0
- package/sign/log/wan-ton-sdk.out.2025-04-14 +3 -0
- package/sign/rawTrans.spec.ts +117 -0
- package/sign/rawTrans.ts +122 -0
- package/sign/tools-secp256k1.js +210 -0
- package/testData/JettonMinter.compile.func.ts +8 -0
- package/testData/JettonWallet.compile.func.ts +8 -0
- package/testData/addressList.json +6 -0
- package/testData/bridge.compile.func.ts +8 -0
- package/testData/bridge.compiled.json +1 -0
- package/testData/contractAddress.json +7 -0
- package/testData/jettonTokenInfo.json +14 -0
- package/testData/prvlist.json +6 -0
- package/testData/smg.json +5 -0
- package/testData/tokenInfo.json +23 -0
- package/transResult/transResult.ts +621 -0
- package/tsconfig.json +19 -0
- package/utils/.compiled.json +1 -0
- package/utils/compileContract.ts +60 -0
- package/utils/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +15 -0
- package/utils/log/wan-ton-sdk.out.2025-01-08 +0 -0
- package/utils/logger.spec.ts +14 -0
- package/utils/logger.ts +96 -0
- package/utils/utils.spec.ts +21 -0
- package/utils/utils.ts +295 -0
- package/wallet/balance.ts +29 -0
- package/wallet/jetton.spec.ts +27 -0
- package/wallet/jetton.ts +159 -0
- package/wallet/walletContract.spec.ts +111 -0
- package/wallet/walletContract.ts +105 -0
package/code/userLock.ts
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
import {getQueryID, remove0x} from "../utils/utils";
|
2
|
+
import {isAddrDepolyed} from "../wallet/walletContract";
|
3
|
+
import {JettonMaster, TonClient} from "@ton/ton";
|
4
|
+
import {BridgeAccess} from "../contractAccess/bridgeAccess";
|
5
|
+
import {Address, beginCell, ContractProvider, internal, toNano} from "@ton/core";
|
6
|
+
import {BIP44_CHAINID, TON_COIN_ACCOUNT_STR,LOCK_COIN,LOCK_ORIGINAL_TOKEN,LOCK_WRAPPED_TOKEN} from "../const/const-value";
|
7
|
+
import * as opcodes from "../opcodes";
|
8
|
+
import {Maybe} from "@ton/core/src/utils/maybe";
|
9
|
+
import {StateInit} from "@ton/core";
|
10
|
+
import {Cell} from "@ton/core";
|
11
|
+
import {Blockchain} from "@ton/sandbox";
|
12
|
+
import {Bridge} from "../Bridge";
|
13
|
+
import {TON_FEE} from "../fee/fee";
|
14
|
+
const formatUtil = require('util');
|
15
|
+
|
16
|
+
export const LOCK_TYPE={
|
17
|
+
coin:1,
|
18
|
+
tokenOrg:2,
|
19
|
+
tokenWrapped:3
|
20
|
+
}
|
21
|
+
|
22
|
+
export async function buildUserLockMessages(opts: {
|
23
|
+
value: bigint,
|
24
|
+
smgID:string,
|
25
|
+
tokenPairID:number,
|
26
|
+
crossValue:bigint,
|
27
|
+
dstUserAccount:string, // hex string
|
28
|
+
bridgeScAddr:string,
|
29
|
+
client:TonClient|Blockchain,
|
30
|
+
senderAccount:string,
|
31
|
+
}){
|
32
|
+
|
33
|
+
console.log("buildUserLockMessages","opts",opts);
|
34
|
+
|
35
|
+
let queryID = await getQueryID();
|
36
|
+
if(! Address.isAddress(Address.parse(opts.bridgeScAddr))){
|
37
|
+
throw new Error(formatUtil.format("invalid bridgeScAddr %s",opts.bridgeScAddr));
|
38
|
+
}
|
39
|
+
|
40
|
+
if( !(await isAddrDepolyed(opts.client,opts.bridgeScAddr))){
|
41
|
+
throw new Error(formatUtil.format("contract %s is not deployed",opts.bridgeScAddr));
|
42
|
+
}
|
43
|
+
let tokenPairInfo = (await getTokenPairInfo(opts.client,Address.parse(opts.bridgeScAddr),opts.tokenPairID));
|
44
|
+
let tokenAccount = tokenPairInfo.tokenAccount
|
45
|
+
let fromChainID = tokenPairInfo.srcChainID
|
46
|
+
let dstChainID = tokenPairInfo.toChainID
|
47
|
+
|
48
|
+
let lockFee = BigInt(await getFee(opts.client,Address.parse(opts.bridgeScAddr),opts.tokenPairID,fromChainID,dstChainID));
|
49
|
+
console.log("lockFee=%s",lockFee.toString(10));
|
50
|
+
let addrTokenAccount:Address;
|
51
|
+
let jwAddrBridgeSc:Address;
|
52
|
+
let jwAddrSrc:Address;
|
53
|
+
|
54
|
+
console.log("tokenAccount",tokenAccount);
|
55
|
+
console.log("TON_COIN_ACCOUNT_STR",TON_COIN_ACCOUNT_STR);
|
56
|
+
if(tokenAccount == TON_COIN_ACCOUNT_STR){
|
57
|
+
jwAddrBridgeSc = jwAddrSrc = addrTokenAccount = Address.parse(TON_COIN_ACCOUNT_STR)
|
58
|
+
return buildLockCoinMessages(opts,jwAddrBridgeSc,jwAddrSrc,addrTokenAccount,lockFee);
|
59
|
+
}else{
|
60
|
+
addrTokenAccount = Address.parse(tokenAccount);
|
61
|
+
jwAddrBridgeSc = await getJettonWalletAddr(opts.client,addrTokenAccount,Address.parse(opts.bridgeScAddr))
|
62
|
+
jwAddrSrc = await getJettonWalletAddr(opts.client,addrTokenAccount,Address.parse(opts.senderAccount))
|
63
|
+
|
64
|
+
let jettonAdminAddr:Address;
|
65
|
+
jettonAdminAddr = await getJettonAdminAddr(opts.client,addrTokenAccount);
|
66
|
+
console.log("jettonAdminAddr from getJettonAdminAddr",jettonAdminAddr.toString());
|
67
|
+
addrTokenAccount = Address.parse(tokenAccount);
|
68
|
+
if(jettonAdminAddr.toString() == opts.bridgeScAddr.toString()){
|
69
|
+
return buildLockWrappedTokenMessages(opts,jwAddrBridgeSc,jwAddrSrc,addrTokenAccount,lockFee);
|
70
|
+
}else{
|
71
|
+
return buildLockOriginalTokenMessages(opts,jwAddrBridgeSc,jwAddrSrc,addrTokenAccount,lockFee);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
throw new Error("unknown tokenAccount");
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
async function buildInternalMessage(src: {
|
79
|
+
to: Address | string,
|
80
|
+
value: bigint | string,
|
81
|
+
bounce?: Maybe<boolean>,
|
82
|
+
init?: Maybe<StateInit>,
|
83
|
+
body?: Maybe<Cell | string>
|
84
|
+
}){
|
85
|
+
return internal(src);
|
86
|
+
}
|
87
|
+
|
88
|
+
async function buildLockCoinMessages(opts: {
|
89
|
+
value: bigint,
|
90
|
+
smgID:string,
|
91
|
+
tokenPairID:number,
|
92
|
+
crossValue:bigint,
|
93
|
+
dstUserAccount:string, // hex string
|
94
|
+
bridgeScAddr:string,
|
95
|
+
client:TonClient|Blockchain,
|
96
|
+
senderAccount:string,
|
97
|
+
},jwAddrBridgeSc:Address,jwAddrSrc:Address,addrTokenAccount:Address,lockFee:bigint){
|
98
|
+
console.log("buildLockCoinMessages","jwAddrBridgeSc",jwAddrBridgeSc.toString(),"jwAddrSrc",jwAddrSrc.toString(),"addrTokenAccount",addrTokenAccount.toString(),"lockFee",lockFee);
|
99
|
+
let totalValue:bigint;
|
100
|
+
totalValue = opts.value + opts.crossValue;
|
101
|
+
console.log("totalValue=>",totalValue);
|
102
|
+
let queryId = await getQueryID();
|
103
|
+
let dstUserAccountBuffer = Buffer.from(opts.dstUserAccount,'hex');
|
104
|
+
let dstUserAccountBufferLen = dstUserAccountBuffer.length
|
105
|
+
let extraCell = beginCell()
|
106
|
+
.storeAddress(addrTokenAccount)
|
107
|
+
.storeAddress(jwAddrSrc)
|
108
|
+
.storeAddress(jwAddrBridgeSc)
|
109
|
+
.endCell()
|
110
|
+
let extraCell2 = beginCell()
|
111
|
+
.storeAddress(Address.parse(opts.senderAccount))
|
112
|
+
.storeUint(lockFee, 256)
|
113
|
+
.endCell()
|
114
|
+
|
115
|
+
let body = beginCell()
|
116
|
+
.storeUint(opcodes.OP_CROSS_UserLock, 32)
|
117
|
+
.storeUint(queryId, 64)
|
118
|
+
.storeUint(BigInt(opts.smgID), 256)
|
119
|
+
.storeUint(opts.tokenPairID, 32)
|
120
|
+
.storeUint(opts.crossValue, 256)
|
121
|
+
.storeUint(dstUserAccountBufferLen,8)
|
122
|
+
.storeBuffer(dstUserAccountBuffer,dstUserAccountBufferLen)
|
123
|
+
.storeRef(extraCell)
|
124
|
+
.storeRef(extraCell2)
|
125
|
+
.endCell()
|
126
|
+
|
127
|
+
let msg = await buildInternalMessage({to:opts.bridgeScAddr,value:totalValue,body:body,bounce:true});
|
128
|
+
return {
|
129
|
+
internalMsg:msg,
|
130
|
+
body:body,
|
131
|
+
to:opts.bridgeScAddr,
|
132
|
+
lockType:LOCK_TYPE.coin,
|
133
|
+
value:totalValue,
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
async function buildLockOriginalTokenMessages(opts: {
|
138
|
+
value: bigint,
|
139
|
+
smgID:string,
|
140
|
+
tokenPairID:number,
|
141
|
+
crossValue:bigint,
|
142
|
+
dstUserAccount:string, // hex string
|
143
|
+
bridgeScAddr:string,
|
144
|
+
client:TonClient|Blockchain,
|
145
|
+
senderAccount:string,
|
146
|
+
},jwAddrBridgeSc:Address,jwAddrSrc:Address,addrTokenAccount:Address,lockFee:bigint){
|
147
|
+
console.log("buildLockOriginalTokenMessages","jwAddrBridgeSc",jwAddrBridgeSc.toString(),"jwAddrSrc",jwAddrSrc.toString(),"addrTokenAccount",addrTokenAccount.toString(),"lockFee",lockFee);
|
148
|
+
|
149
|
+
if(opts.value < (lockFee + TON_FEE.NOTIFY_FEE_USER_LOCK)){ //todo value > lockFee + transUserLockFee
|
150
|
+
throw new Error("insufficient ton balance");
|
151
|
+
}
|
152
|
+
// forward payLoad
|
153
|
+
let queryId = await getQueryID();
|
154
|
+
|
155
|
+
let dstUserAccountBuffer = Buffer.from(remove0x(opts.dstUserAccount),'hex');
|
156
|
+
let dstUserAccountBufferLen = dstUserAccountBuffer.length
|
157
|
+
let extraCell = beginCell()
|
158
|
+
.storeAddress(addrTokenAccount)
|
159
|
+
.storeAddress(jwAddrSrc)
|
160
|
+
.storeAddress(jwAddrBridgeSc)
|
161
|
+
.endCell()
|
162
|
+
let extraCell2 = beginCell()
|
163
|
+
.storeAddress(Address.parse(opts.senderAccount))
|
164
|
+
.storeUint(lockFee, 256)
|
165
|
+
.endCell()
|
166
|
+
let body = beginCell()
|
167
|
+
.storeUint(opcodes.OP_CROSS_UserLock, 32)
|
168
|
+
.storeUint(queryId, 64)
|
169
|
+
.storeUint(BigInt(opts.smgID), 256)
|
170
|
+
.storeUint(opts.tokenPairID, 32)
|
171
|
+
.storeUint(opts.crossValue, 256)
|
172
|
+
.storeUint(dstUserAccountBufferLen,8)
|
173
|
+
.storeBuffer(dstUserAccountBuffer,dstUserAccountBufferLen)
|
174
|
+
.storeRef(extraCell)
|
175
|
+
.storeRef(extraCell2)
|
176
|
+
.endCell()
|
177
|
+
|
178
|
+
// sendToken payLoad
|
179
|
+
//let forwardAmount = lockFee + toNano('0.3');
|
180
|
+
let forwardAmount = lockFee + TON_FEE.NOTIFY_FEE_USER_LOCK;
|
181
|
+
console.log("forwardAmount=>",forwardAmount);
|
182
|
+
let sendTokenAmount = opts.crossValue;
|
183
|
+
let sendJettonCel = beginCell()
|
184
|
+
.storeUint(0xf8a7ea5, 32) // const int op::transfer = 0xf8a7ea5;
|
185
|
+
.storeUint(queryId, 64) // op, queryId
|
186
|
+
.storeCoins(sendTokenAmount) //jetton_amount
|
187
|
+
.storeAddress(Address.parse(opts.bridgeScAddr)) // receive address (token)
|
188
|
+
//.storeAddress(Address.parse(opts.bridgeScAddr)) //response address
|
189
|
+
.storeAddress(Address.parse(opts.senderAccount))
|
190
|
+
.storeMaybeRef(null)
|
191
|
+
.storeCoins(forwardAmount) // forward_ton_amount
|
192
|
+
.storeMaybeRef(body) //forwardPayload
|
193
|
+
.endCell();
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
let msg = await buildInternalMessage({to:jwAddrSrc,value:opts.value,body:sendJettonCel,bounce:true});
|
198
|
+
return {
|
199
|
+
internalMsg:msg,
|
200
|
+
body:sendJettonCel,
|
201
|
+
to:jwAddrSrc,
|
202
|
+
lockType:LOCK_TYPE.tokenOrg,
|
203
|
+
value:opts.value,
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
async function buildLockWrappedTokenMessages(opts:any,jwAddrBridgeSc:Address,jwAddrSrc:Address,addrTokenAccount:Address,lockFee:bigint){
|
208
|
+
console.log("buildLockWrappedTokenMessages","jwAddrBridgeSc",jwAddrBridgeSc.toString(),"jwAddrSrc",jwAddrSrc.toString(),"addrTokenAccount",addrTokenAccount.toString(),"lockFee",lockFee);
|
209
|
+
let ret = (await buildLockOriginalTokenMessages(opts,jwAddrBridgeSc,jwAddrSrc,addrTokenAccount,lockFee));
|
210
|
+
ret.lockType = LOCK_TYPE.tokenWrapped;
|
211
|
+
return ret;
|
212
|
+
}
|
213
|
+
|
214
|
+
async function getFee(client:TonClient|Blockchain,bridgeScAddr:Address,tokenPairID:number,srcChainId,dstChainId){
|
215
|
+
let fee = 0;
|
216
|
+
if(client instanceof TonClient){
|
217
|
+
let ba = BridgeAccess.create(client,bridgeScAddr.toString())
|
218
|
+
let feeTp = await ba.readContract("getChainFee",[srcChainId,dstChainId])
|
219
|
+
if(feeTp.contractFee != 0){
|
220
|
+
fee = feeTp.contractFee;
|
221
|
+
}else{
|
222
|
+
fee = await ba.readContract("getTokenPairFee",[tokenPairID]);
|
223
|
+
}
|
224
|
+
}else{
|
225
|
+
let b = await Bridge.createFromAddress(bridgeScAddr)
|
226
|
+
let opened = await client.openContract(b);
|
227
|
+
let feeTp = await opened.getChainFee(srcChainId,dstChainId);
|
228
|
+
if(feeTp.contractFee != 0){
|
229
|
+
fee = feeTp.contractFee;
|
230
|
+
}else{
|
231
|
+
fee = await opened.getTokenPairFee(tokenPairID);
|
232
|
+
}
|
233
|
+
}
|
234
|
+
return fee;
|
235
|
+
}
|
236
|
+
|
237
|
+
async function getJettonWalletAddr(client:TonClient|Blockchain,jettonMasterAddr:Address,ownerAddr:Address){
|
238
|
+
console.log("in getJettonWalletAddr", "jettonMasterAddr", jettonMasterAddr.toString(),"ownerAddr",ownerAddr.toString());
|
239
|
+
if(client instanceof TonClient){
|
240
|
+
let jettonMasterSc = JettonMaster.create(jettonMasterAddr)
|
241
|
+
let jettonMasterScOpened = await client.open(jettonMasterSc)
|
242
|
+
return await jettonMasterScOpened.getWalletAddress(ownerAddr)
|
243
|
+
}else{
|
244
|
+
let jettonMasterSc = JettonMaster.create(jettonMasterAddr)
|
245
|
+
let jettonMasterScOpened = await client.openContract(jettonMasterSc)
|
246
|
+
return await jettonMasterScOpened.getWalletAddress(ownerAddr)
|
247
|
+
}
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
async function getJettonAdminAddr(client:TonClient|Blockchain,jettonMasterAddr:Address){
|
252
|
+
console.log("in getJettonAdminAddr", "jettonMasterAddr", jettonMasterAddr.toString());
|
253
|
+
if(client instanceof TonClient){
|
254
|
+
let jettonMasterSc = JettonMaster.create(jettonMasterAddr)
|
255
|
+
let jettonMasterScOpened = await client.open(jettonMasterSc)
|
256
|
+
return (await jettonMasterScOpened.getJettonData()).adminAddress
|
257
|
+
}else{
|
258
|
+
let jettonMasterSc = JettonMaster.create(jettonMasterAddr)
|
259
|
+
let jettonMasterScOpened = await client.openContract(jettonMasterSc)
|
260
|
+
return (await jettonMasterScOpened.getJettonData()).adminAddress
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
export async function getTokenPairInfo(client:TonClient|Blockchain,bridgeScAddr:Address,tokenPairID:number){
|
265
|
+
let tokePairInfo ;
|
266
|
+
let tokenAccount = "";
|
267
|
+
|
268
|
+
if(client instanceof TonClient){
|
269
|
+
let ba = new BridgeAccess(client,bridgeScAddr)
|
270
|
+
tokePairInfo = await ba.readContract("getTokenPair",[tokenPairID])
|
271
|
+
}else{
|
272
|
+
let b = Bridge.createFromAddress(bridgeScAddr);
|
273
|
+
let opened = await client.openContract(b);
|
274
|
+
tokePairInfo = await opened.getTokenPair(tokenPairID)
|
275
|
+
}
|
276
|
+
console.log("in getTokenPairInfo","tokenPairInfo",tokePairInfo,"tokenPairId",tokenPairID);
|
277
|
+
if (tokePairInfo.fromChainID == BIP44_CHAINID){
|
278
|
+
tokenAccount = tokePairInfo.fromAccount;
|
279
|
+
}else{
|
280
|
+
if(tokePairInfo.toChainID == BIP44_CHAINID){
|
281
|
+
tokenAccount = tokePairInfo.toAccount;
|
282
|
+
}else{
|
283
|
+
throw new Error(formatUtil.format("invalid TokenPair %d",tokenPairID));
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
if(! Address.isAddress(Address.parse(tokenAccount))){
|
288
|
+
throw new Error(formatUtil.format("invalid tokenAccount %s",tokenAccount));
|
289
|
+
}
|
290
|
+
return {tokenAccount,srcChainID:tokePairInfo.fromChainID, toChainID:tokePairInfo.toChainID};
|
291
|
+
}
|
package/common.ts
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
import {
|
2
|
+
Address,
|
3
|
+
beginCell,
|
4
|
+
Cell,
|
5
|
+
Contract,
|
6
|
+
contractAddress,
|
7
|
+
ContractProvider,
|
8
|
+
Sender,
|
9
|
+
SendMode,
|
10
|
+
toNano
|
11
|
+
} from '@ton/core';
|
12
|
+
|
13
|
+
import {logger} from './utils/logger'
|
14
|
+
const formatUtil = require('util');
|
15
|
+
|
16
|
+
|
17
|
+
export class common {
|
18
|
+
static createFromAddress(address: Address) {
|
19
|
+
return address;
|
20
|
+
}
|
21
|
+
|
22
|
+
static computeHash(currentChainId: bigint,uniqueId:bigint,tokenPairId:bigint,value:bigint,fee:bigint,tokenAccount:Address|string,userAccount: Address) {
|
23
|
+
|
24
|
+
|
25
|
+
let tokenAccountBuf:Buffer
|
26
|
+
|
27
|
+
if(Address.isAddress(tokenAccount)) {
|
28
|
+
tokenAccountBuf = tokenAccount.hash;
|
29
|
+
}else{
|
30
|
+
tokenAccountBuf = Buffer.from(tokenAccount.substring(0,2).toLowerCase() == '0x'?tokenAccount.substring(2):tokenAccount,'hex');
|
31
|
+
}
|
32
|
+
|
33
|
+
let userAccountBuf = userAccount.hash;
|
34
|
+
|
35
|
+
let msg = beginCell()
|
36
|
+
.storeUint(currentChainId, 64)
|
37
|
+
.storeUint(uniqueId, 256)
|
38
|
+
.storeUint(tokenPairId, 32)
|
39
|
+
.storeUint(value, 256)
|
40
|
+
.storeUint(fee, 256)
|
41
|
+
.storeRef(
|
42
|
+
beginCell()
|
43
|
+
.storeAddress(userAccount)
|
44
|
+
.storeBuffer(tokenAccountBuf)
|
45
|
+
.endCell()
|
46
|
+
);
|
47
|
+
logger.info(formatUtil.format(" tokenAccount...",tokenAccount));
|
48
|
+
logger.info(formatUtil.format(" tokenAccountBuf......",tokenAccountBuf.toString('hex'),tokenAccountBuf.length));
|
49
|
+
logger.info(formatUtil.format("(bigInt) tokenAccountBuf......",BigInt("0x" + tokenAccountBuf.toString('hex'))));
|
50
|
+
|
51
|
+
logger.info(formatUtil.format(" userAccount...",userAccount));
|
52
|
+
logger.info(formatUtil.format(" userAccountBuf......",userAccountBuf.toString('hex'),userAccountBuf.length));
|
53
|
+
logger.info(formatUtil.format("(bigInt) userAccountBuf......",BigInt("0x" + userAccountBuf.toString('hex'))));
|
54
|
+
logger.info(formatUtil.format("user_account_cell(cell)",msg.endCell()));
|
55
|
+
let hashBuf = msg.endCell().hash();
|
56
|
+
return {
|
57
|
+
hashHex: hashBuf.toString('hex'),
|
58
|
+
hashBig: BigInt(`0x${hashBuf.toString('hex')}`),
|
59
|
+
hashBuf: hashBuf
|
60
|
+
};
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import {TonConfig} from "../client/client";
|
2
|
+
|
3
|
+
export const configTestnet:TonConfig = {
|
4
|
+
network:{
|
5
|
+
network:"testnet", // testnet|mainnet
|
6
|
+
},
|
7
|
+
usingDbCache:true,
|
8
|
+
urls:[
|
9
|
+
{
|
10
|
+
//url:'',
|
11
|
+
//apiKey:''
|
12
|
+
}]
|
13
|
+
}
|
14
|
+
|
15
|
+
export const configMainnet:TonConfig = {
|
16
|
+
network:{
|
17
|
+
network:"mainnet", // testnet|mainnet
|
18
|
+
},
|
19
|
+
//usingDbCache:true,
|
20
|
+
urls:[
|
21
|
+
{
|
22
|
+
//url:'',
|
23
|
+
//apiKey:''
|
24
|
+
}]
|
25
|
+
}
|
package/config/config.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export const BIP44_CHAINID = 0x8000025f;
|
2
|
+
export const BIP44_WANCHAIN_CHAINID = 0x8057414e; // 2153201998
|
3
|
+
export const TON_COIN_ACCOUT = "0x0000000000000000000000000000000000000000000000000000000000000000"; // 32 bytes
|
4
|
+
export const TON_COIN_ACCOUNT_STR = 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'
|
5
|
+
export const WK_CHIANID = "0";
|
6
|
+
|
7
|
+
export const ZERO_ACCOUNT_STR = TON_COIN_ACCOUNT_STR
|
8
|
+
|
9
|
+
// send_raw_message flags
|
10
|
+
export const REVERT_ON_ERRORS = 0;
|
11
|
+
export const PAY_FEES_SEPARATELY = 1;
|
12
|
+
export const IGNORE_ERRORS = 2;
|
13
|
+
export const BOUNCE_MESSAGE = 16;
|
14
|
+
export const SELFDESTRUCT_ON_EMPTY = 32;
|
15
|
+
|
16
|
+
// send_raw_message MODE
|
17
|
+
export const NORMAL = 0;
|
18
|
+
export const CARRY_REMAINING_GAS = 64;
|
19
|
+
export const CARRY_REMAINING_BALANCE = 128;
|
20
|
+
|
21
|
+
//
|
22
|
+
export const LOCK_COIN = 0;
|
23
|
+
export const LOCK_ORIGINAL_TOKEN = 1;
|
24
|
+
export const LOCK_WRAPPED_TOKEN = 2;
|
25
|
+
|
26
|
+
|
27
|
+
export const MAX_LIMIT = 90;
|
28
|
+
//export const MAX_LIMIT = 10;
|
29
|
+
export const MAX_RETRY = 3;
|
30
|
+
|
31
|
+
export const MAX_BACKTRACE_SECONDS = 30*86400;
|
32
|
+
|
33
|
+
export const TONCLINET_TIMEOUT = 60 * 1000 * 1000;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import core_1, { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SendMode } from "@ton/core";
|
2
|
+
import {TonClient} from "@ton/ton";
|
3
|
+
import {Bridge} from '../Bridge';
|
4
|
+
|
5
|
+
import {logger} from '../utils/logger'
|
6
|
+
import {bigIntReplacer, formatError} from "../utils/utils";
|
7
|
+
const formatUtil = require('util');
|
8
|
+
|
9
|
+
export class BridgeAccess {
|
10
|
+
private client: TonClient;
|
11
|
+
private readonly contractAddr: Address;
|
12
|
+
|
13
|
+
static create(client:TonClient,contractAddr:string):BridgeAccess {
|
14
|
+
let addr = Address.parse(contractAddr);
|
15
|
+
return new BridgeAccess(client, addr);
|
16
|
+
}
|
17
|
+
|
18
|
+
constructor(client:TonClient,contractAddr:Address){
|
19
|
+
this.client = client;
|
20
|
+
this.contractAddr = contractAddr;
|
21
|
+
}
|
22
|
+
|
23
|
+
async writeContract(methodName:string,via:Sender,opts:any){
|
24
|
+
if(!methodName.startsWith('send')){
|
25
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
26
|
+
}
|
27
|
+
try{
|
28
|
+
let c = Bridge.createFromAddress(this.contractAddr);
|
29
|
+
logger.info(formatUtil.format("writeContract contractAddress",this.contractAddr));
|
30
|
+
let cOpened = this.client.open(c);
|
31
|
+
return await cOpened[methodName](via,opts);
|
32
|
+
}catch(err){
|
33
|
+
logger.info(formatUtil.format("writeContract err=>","methodName",methodName,"opts",JSON.stringify(opts,bigIntReplacer),"err",formatError(err)));
|
34
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
async readContract(methodName:string,parameters:any[]){
|
39
|
+
if(!methodName.startsWith('get')){
|
40
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
41
|
+
}
|
42
|
+
try{
|
43
|
+
let c = Bridge.createFromAddress(this.contractAddr);
|
44
|
+
let cOpened = this.client.open(c);
|
45
|
+
logger.info(formatUtil.format("methodName=>",methodName));
|
46
|
+
return await cOpened[methodName](...parameters);
|
47
|
+
}catch(err){
|
48
|
+
logger.error(formatUtil.format(formatError(err)));
|
49
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
/*
|
55
|
+
1. put down all the getMethod
|
56
|
+
2. for users, all the parameter value is hexString, or bigInt, or Address, or string
|
57
|
+
3. convert the input value to the value which is used in Bridge.ts class
|
58
|
+
4. use client's runGetMessage or use the Bridge.ts?
|
59
|
+
*/
|
60
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import core_1, { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SendMode } from "@ton/core";
|
2
|
+
import {TonClient} from "@ton/ton";
|
3
|
+
import {GroupApprove} from '../GroupApprove';
|
4
|
+
|
5
|
+
import {logger} from '../utils/logger'
|
6
|
+
const formatUtil = require('util');
|
7
|
+
|
8
|
+
export class GroupApproveAccess {
|
9
|
+
private client: TonClient;
|
10
|
+
private readonly contractAddr: Address;
|
11
|
+
|
12
|
+
static create(client:TonClient,contractAddr:string):GroupApproveAccess {
|
13
|
+
let addr = Address.parse(contractAddr);
|
14
|
+
return new GroupApproveAccess(client, addr);
|
15
|
+
}
|
16
|
+
|
17
|
+
constructor(client:TonClient,contractAddr:Address){
|
18
|
+
this.client = client;
|
19
|
+
this.contractAddr = contractAddr;
|
20
|
+
}
|
21
|
+
|
22
|
+
async writeContract(methodName:string,via:Sender,opts:any){
|
23
|
+
if(!methodName.startsWith('send')){
|
24
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
25
|
+
}
|
26
|
+
try{
|
27
|
+
let c = GroupApprove.createFromAddress(this.contractAddr);
|
28
|
+
logger.info(formatUtil.format("writeContract contractAddress",this.contractAddr));
|
29
|
+
let cOpened = this.client.open(c);
|
30
|
+
return await cOpened[methodName](via,opts);
|
31
|
+
}catch(err){
|
32
|
+
logger.info(formatUtil.format("err=>",err));
|
33
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
async readContract(methodName:string,parameters:any[]){
|
38
|
+
if(!methodName.startsWith('get')){
|
39
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
40
|
+
}
|
41
|
+
try{
|
42
|
+
let c = GroupApprove.createFromAddress(this.contractAddr);
|
43
|
+
let cOpened = this.client.open(c);
|
44
|
+
logger.info(formatUtil.format("methodName=>",methodName));
|
45
|
+
return await cOpened[methodName](...parameters);
|
46
|
+
}catch(err){
|
47
|
+
logger.info(formatUtil.format(err));
|
48
|
+
throw new Error(`${methodName} is not supported Non send method`);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
1. put down all the getMethod
|
55
|
+
2. for users, all the parameter value is hexString, or bigInt, or Address, or string
|
56
|
+
3. convert the input value to the value which is used in GroupApprove.ts class
|
57
|
+
4. use client's runGetMessage or use the GroupApprove.ts?
|
58
|
+
*/
|
59
|
+
|