@shapeshiftoss/unchained-client 10.14.11 → 10.15.0
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/cosmossdk/thorchain/parser/__tests__/thorchain.test.js +1 -1
- package/dist/cjs/cosmossdk/thorchain/parser/rfox.js +1 -1
- package/dist/cjs/evm/arbitrum/parser/index.js +2 -2
- package/dist/cjs/evm/ethereum/parser/index.js +6 -0
- package/dist/cjs/generated/mayachain/apis/V1Api.d.ts +1 -13
- package/dist/cjs/generated/mayachain/apis/V1Api.js +0 -27
- package/dist/cjs/generated/mayachain/models/index.d.ts +0 -2
- package/dist/cjs/generated/mayachain/models/index.js +0 -2
- package/dist/cjs/generated/thorchain/apis/V1Api.d.ts +1 -25
- package/dist/cjs/generated/thorchain/apis/V1Api.js +0 -54
- package/dist/cjs/generated/thorchain/models/index.d.ts +0 -3
- package/dist/cjs/generated/thorchain/models/index.js +0 -3
- package/dist/cjs/tron/__tests__/api.test.d.ts +1 -0
- package/dist/cjs/tron/__tests__/api.test.js +300 -0
- package/dist/cjs/tron/api.d.ts +35 -15
- package/dist/cjs/tron/api.js +189 -81
- package/dist/cjs/tron/types.d.ts +4 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/cosmossdk/thorchain/parser/__tests__/thorchain.test.js +2 -2
- package/dist/esm/cosmossdk/thorchain/parser/rfox.js +2 -2
- package/dist/esm/evm/arbitrum/parser/index.js +3 -3
- package/dist/esm/evm/ethereum/parser/index.js +7 -1
- package/dist/esm/generated/mayachain/apis/V1Api.d.ts +1 -13
- package/dist/esm/generated/mayachain/apis/V1Api.js +1 -28
- package/dist/esm/generated/mayachain/models/index.d.ts +0 -2
- package/dist/esm/generated/mayachain/models/index.js +0 -2
- package/dist/esm/generated/thorchain/apis/V1Api.d.ts +1 -25
- package/dist/esm/generated/thorchain/apis/V1Api.js +1 -55
- package/dist/esm/generated/thorchain/models/index.d.ts +0 -3
- package/dist/esm/generated/thorchain/models/index.js +0 -3
- package/dist/esm/tron/__tests__/api.test.d.ts +1 -0
- package/dist/esm/tron/__tests__/api.test.js +298 -0
- package/dist/esm/tron/api.d.ts +35 -15
- package/dist/esm/tron/api.js +187 -80
- package/dist/esm/tron/types.d.ts +4 -0
- package/package.json +5 -5
- package/dist/cjs/generated/mayachain/models/AffiliateFee.d.ts +0 -67
- package/dist/cjs/generated/mayachain/models/AffiliateFee.js +0 -63
- package/dist/cjs/generated/mayachain/models/AffiliateFees.d.ts +0 -32
- package/dist/cjs/generated/mayachain/models/AffiliateFees.js +0 -52
- package/dist/cjs/generated/thorchain/models/AffiliateFee.d.ts +0 -67
- package/dist/cjs/generated/thorchain/models/AffiliateFee.js +0 -63
- package/dist/cjs/generated/thorchain/models/AffiliateFees.d.ts +0 -32
- package/dist/cjs/generated/thorchain/models/AffiliateFees.js +0 -52
- package/dist/cjs/generated/thorchain/models/AffiliateRevenue.d.ts +0 -45
- package/dist/cjs/generated/thorchain/models/AffiliateRevenue.js +0 -57
- package/dist/esm/generated/mayachain/models/AffiliateFee.d.ts +0 -67
- package/dist/esm/generated/mayachain/models/AffiliateFee.js +0 -56
- package/dist/esm/generated/mayachain/models/AffiliateFees.d.ts +0 -32
- package/dist/esm/generated/mayachain/models/AffiliateFees.js +0 -45
- package/dist/esm/generated/thorchain/models/AffiliateFee.d.ts +0 -67
- package/dist/esm/generated/thorchain/models/AffiliateFee.js +0 -56
- package/dist/esm/generated/thorchain/models/AffiliateFees.d.ts +0 -32
- package/dist/esm/generated/thorchain/models/AffiliateFees.js +0 -45
- package/dist/esm/generated/thorchain/models/AffiliateRevenue.d.ts +0 -45
- package/dist/esm/generated/thorchain/models/AffiliateRevenue.js +0 -50
package/dist/esm/tron/api.d.ts
CHANGED
|
@@ -3,10 +3,18 @@ export interface TronApiConfig {
|
|
|
3
3
|
rpcUrl: string;
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
}
|
|
6
|
+
export type TronContractEnergyShare = {
|
|
7
|
+
callerPercent: number;
|
|
8
|
+
originEnergyLimit: number;
|
|
9
|
+
originEnergyAvailable: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const getCallerEnergy: (energyUsed: number, share: TronContractEnergyShare) => number;
|
|
6
12
|
export declare class TronApi {
|
|
7
13
|
private readonly rpcUrl;
|
|
8
14
|
private readonly apiKey;
|
|
9
15
|
private tronWeb;
|
|
16
|
+
private readonly contracts;
|
|
17
|
+
private readonly originEnergy;
|
|
10
18
|
private requestQueue;
|
|
11
19
|
private readonly minRequestInterval;
|
|
12
20
|
constructor(config: TronApiConfig);
|
|
@@ -24,10 +32,16 @@ export declare class TronApi {
|
|
|
24
32
|
balance: string;
|
|
25
33
|
}[];
|
|
26
34
|
}>;
|
|
27
|
-
|
|
35
|
+
getTrc20Balance(params: {
|
|
36
|
+
contractAddress: string;
|
|
28
37
|
address: string;
|
|
38
|
+
}): Promise<string>;
|
|
39
|
+
getTrc20Allowance(params: {
|
|
29
40
|
contractAddress: string;
|
|
41
|
+
owner: string;
|
|
42
|
+
spender: string;
|
|
30
43
|
}): Promise<string>;
|
|
44
|
+
isAccountActivated(address: string): Promise<boolean>;
|
|
31
45
|
getTxHistory(_params: {
|
|
32
46
|
pubkey: string;
|
|
33
47
|
pageSize?: number;
|
|
@@ -47,23 +61,29 @@ export declare class TronApi {
|
|
|
47
61
|
hex: string;
|
|
48
62
|
};
|
|
49
63
|
}): Promise<string>;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
getChainPrices(): Promise<{
|
|
65
|
+
bandwidthPrice: number;
|
|
66
|
+
energyPrice: number;
|
|
67
|
+
memoFee: number;
|
|
68
|
+
}>;
|
|
69
|
+
getContractEnergyShare(contractAddress: string): Promise<TronContractEnergyShare>;
|
|
70
|
+
private getContract;
|
|
71
|
+
private getPricingContext;
|
|
72
|
+
private getOriginEnergyAvailable;
|
|
73
|
+
private post;
|
|
74
|
+
estimateTrc20TransferFee(params: {
|
|
57
75
|
contractAddress: string;
|
|
58
76
|
from: string;
|
|
59
77
|
to: string;
|
|
60
78
|
amount: string;
|
|
79
|
+
requireEnergyShare?: boolean;
|
|
61
80
|
}): Promise<string>;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}>;
|
|
81
|
+
estimateContractCallFee(params: {
|
|
82
|
+
contractAddress: string;
|
|
83
|
+
from: string;
|
|
84
|
+
data: string;
|
|
85
|
+
callValue?: string;
|
|
86
|
+
requireEnergyShare?: boolean;
|
|
87
|
+
}): Promise<string>;
|
|
88
|
+
private getSimulatedEnergy;
|
|
69
89
|
}
|
package/dist/esm/tron/api.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { TronWeb } from 'tronweb';
|
|
2
|
+
const TRON_CALLER_PAYS_ALL = {
|
|
3
|
+
callerPercent: 100,
|
|
4
|
+
originEnergyLimit: 0,
|
|
5
|
+
originEnergyAvailable: 0,
|
|
6
|
+
};
|
|
7
|
+
// java-tron reads a stored zero, which TronGrid omits, as this creator default
|
|
8
|
+
const TRON_CREATOR_DEFAULT_ENERGY_LIMIT = 10_000_000;
|
|
9
|
+
// A deployer's unspent energy moves slowly next to how often the swappers re-estimate
|
|
10
|
+
const TRON_ORIGIN_ENERGY_TTL_MS = 15_000;
|
|
11
|
+
// A deployer can raise the caller's share after deployment, so the split is re-read within the minute
|
|
12
|
+
const TRON_CONTRACT_TTL_MS = 60_000;
|
|
13
|
+
// The deployer covers the rest only out of what they have staked, so a dry deployer (Tether) leaves the caller paying in full
|
|
14
|
+
export const getCallerEnergy = (energyUsed, share) => {
|
|
15
|
+
const originShare = Math.floor((energyUsed * (100 - share.callerPercent)) / 100);
|
|
16
|
+
const originCovered = Math.max(0, Math.min(originShare, share.originEnergyLimit, share.originEnergyAvailable));
|
|
17
|
+
return energyUsed - originCovered;
|
|
18
|
+
};
|
|
2
19
|
export class TronApi {
|
|
3
20
|
rpcUrl;
|
|
4
21
|
apiKey;
|
|
5
22
|
tronWeb = null;
|
|
23
|
+
contracts = new Map();
|
|
24
|
+
originEnergy = new Map();
|
|
6
25
|
requestQueue = Promise.resolve();
|
|
7
26
|
minRequestInterval = 1_500;
|
|
8
27
|
constructor(config) {
|
|
@@ -95,9 +114,12 @@ export class TronApi {
|
|
|
95
114
|
}
|
|
96
115
|
for (const contractAddress of Array.from(discoveredContracts).slice(0, MAX_FALLBACK_CONTRACTS)) {
|
|
97
116
|
await this.throttle();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
117
|
+
await this.getTrc20Balance({ contractAddress, address: params.pubkey })
|
|
118
|
+
.then(balance => {
|
|
119
|
+
if (balance !== '0')
|
|
120
|
+
tokens.push({ contractAddress, balance });
|
|
121
|
+
})
|
|
122
|
+
.catch(() => undefined);
|
|
101
123
|
}
|
|
102
124
|
}
|
|
103
125
|
catch (fallbackErr) {
|
|
@@ -118,16 +140,36 @@ export class TronApi {
|
|
|
118
140
|
tokens,
|
|
119
141
|
};
|
|
120
142
|
}
|
|
121
|
-
async
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
143
|
+
async getTrc20Balance(params) {
|
|
144
|
+
const result = await this.getTronWeb().transactionBuilder.triggerConstantContract(params.contractAddress, 'balanceOf(address)', {}, [{ type: 'address', value: params.address }], params.address);
|
|
145
|
+
const [balance] = result.constant_result ?? [];
|
|
146
|
+
if (!balance)
|
|
147
|
+
throw new Error('[tron] balanceOf call returned no data');
|
|
148
|
+
return BigInt(`0x${balance}`).toString();
|
|
149
|
+
}
|
|
150
|
+
// A direct selector call - contract().at() would first fetch the ABI, doubling the requests
|
|
151
|
+
async getTrc20Allowance(params) {
|
|
152
|
+
const tronWeb = this.getTronWeb();
|
|
153
|
+
const result = await tronWeb.transactionBuilder.triggerConstantContract(params.contractAddress, 'allowance(address,address)', {}, [
|
|
154
|
+
{ type: 'address', value: params.owner },
|
|
155
|
+
{ type: 'address', value: params.spender },
|
|
156
|
+
], params.owner);
|
|
157
|
+
const [allowance] = result.constant_result ?? [];
|
|
158
|
+
if (!allowance)
|
|
159
|
+
throw new Error('[tron] allowance call returned no data');
|
|
160
|
+
return BigInt(`0x${allowance}`).toString();
|
|
161
|
+
}
|
|
162
|
+
// Accounts exist on-chain only once they have received TRX; a fresh address returns {}
|
|
163
|
+
async isAccountActivated(address) {
|
|
164
|
+
const response = await fetch(`${this.rpcUrl}/wallet/getaccount`, {
|
|
165
|
+
method: 'POST',
|
|
166
|
+
headers: this.tronGridHeaders,
|
|
167
|
+
body: JSON.stringify({ address, visible: true }),
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok)
|
|
170
|
+
throw new Error(`[tron] getaccount failed: ${response.status}`);
|
|
171
|
+
const data = await response.json();
|
|
172
|
+
return !!data.address;
|
|
131
173
|
}
|
|
132
174
|
getTxHistory(_params) {
|
|
133
175
|
throw new Error('Transaction history is not supported for TRON');
|
|
@@ -146,13 +188,11 @@ export class TronApi {
|
|
|
146
188
|
body: JSON.stringify({ value: params.txid, visible: true }),
|
|
147
189
|
}),
|
|
148
190
|
]);
|
|
149
|
-
if (!txResponse.ok)
|
|
191
|
+
if (!txResponse.ok)
|
|
150
192
|
return null;
|
|
151
|
-
}
|
|
152
193
|
const tx = await txResponse.json();
|
|
153
|
-
if (!tx || !tx.txID)
|
|
194
|
+
if (!tx || !tx.txID)
|
|
154
195
|
return null;
|
|
155
|
-
}
|
|
156
196
|
let blockNumber = 0;
|
|
157
197
|
let blockTimeStamp = 0;
|
|
158
198
|
let fee = '0';
|
|
@@ -186,9 +226,8 @@ export class TronApi {
|
|
|
186
226
|
headers: this.tronGridHeaders,
|
|
187
227
|
body: JSON.stringify({ num: params.height }),
|
|
188
228
|
});
|
|
189
|
-
if (!response.ok)
|
|
229
|
+
if (!response.ok)
|
|
190
230
|
return null;
|
|
191
|
-
}
|
|
192
231
|
return await response.json();
|
|
193
232
|
}
|
|
194
233
|
async sendTx(params) {
|
|
@@ -200,9 +239,8 @@ export class TronApi {
|
|
|
200
239
|
throw new Error(result.message || JSON.stringify(result) || 'Failed to broadcast transaction');
|
|
201
240
|
}
|
|
202
241
|
const txid = result.txid || result.transaction?.txID;
|
|
203
|
-
if (!txid)
|
|
242
|
+
if (!txid)
|
|
204
243
|
throw new Error('Transaction ID not found in broadcast result');
|
|
205
|
-
}
|
|
206
244
|
return txid;
|
|
207
245
|
}
|
|
208
246
|
catch (error) {
|
|
@@ -210,69 +248,138 @@ export class TronApi {
|
|
|
210
248
|
}
|
|
211
249
|
}
|
|
212
250
|
async getChainPrices() {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
251
|
+
const params = await this.getTronWeb().trx.getChainParameters();
|
|
252
|
+
const param = (key) => {
|
|
253
|
+
const value = params.find(p => p.key === key)?.value;
|
|
254
|
+
if (value === undefined)
|
|
255
|
+
throw new Error(`[tron] chain parameter ${key} missing`);
|
|
256
|
+
return value;
|
|
257
|
+
};
|
|
258
|
+
return {
|
|
259
|
+
bandwidthPrice: param('getTransactionFee'),
|
|
260
|
+
energyPrice: param('getEnergyFee'),
|
|
261
|
+
memoFee: param('getMemoFee'),
|
|
262
|
+
};
|
|
223
263
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
264
|
+
// A plain address answers getcontract with {} and pays in full
|
|
265
|
+
async getContractEnergyShare(contractAddress) {
|
|
266
|
+
const contract = await this.getContract(contractAddress);
|
|
267
|
+
if (!contract.origin_address)
|
|
268
|
+
return TRON_CALLER_PAYS_ALL;
|
|
269
|
+
// TronGrid omits zero-valued fields, so a contract whose deployer pays everything carries no percent at all
|
|
270
|
+
const callerPercent = contract.consume_user_resource_percent ?? 0;
|
|
271
|
+
if (callerPercent >= 100)
|
|
272
|
+
return TRON_CALLER_PAYS_ALL;
|
|
273
|
+
return {
|
|
274
|
+
callerPercent,
|
|
275
|
+
originEnergyLimit: contract.origin_energy_limit || TRON_CREATOR_DEFAULT_ENERGY_LIMIT,
|
|
276
|
+
originEnergyAvailable: await this.getOriginEnergyAvailable(contract.origin_address),
|
|
277
|
+
};
|
|
236
278
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
279
|
+
getContract(contractAddress) {
|
|
280
|
+
const cached = this.contracts.get(contractAddress);
|
|
281
|
+
if (cached && Date.now() - cached.readAt < TRON_CONTRACT_TTL_MS)
|
|
282
|
+
return cached.value;
|
|
283
|
+
const value = this.post('/wallet/getcontract', {
|
|
284
|
+
value: contractAddress,
|
|
285
|
+
visible: true,
|
|
286
|
+
})
|
|
287
|
+
.then(body => {
|
|
288
|
+
if (body.Error)
|
|
289
|
+
throw new Error(`[tron] getcontract failed: ${body.Error}`);
|
|
290
|
+
// only a contract record is worth keeping; an empty body is re-read next time
|
|
291
|
+
if (!body.origin_address && this.contracts.get(contractAddress)?.value === value) {
|
|
292
|
+
this.contracts.delete(contractAddress);
|
|
293
|
+
}
|
|
294
|
+
return body;
|
|
295
|
+
})
|
|
296
|
+
.catch(err => {
|
|
297
|
+
if (this.contracts.get(contractAddress)?.value === value) {
|
|
298
|
+
this.contracts.delete(contractAddress);
|
|
299
|
+
}
|
|
300
|
+
throw err;
|
|
301
|
+
});
|
|
302
|
+
this.contracts.set(contractAddress, { readAt: Date.now(), value });
|
|
303
|
+
return value;
|
|
253
304
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
305
|
+
// A failed share lookup prices the simulation as if the caller paid in full, unless the caller must not guess
|
|
306
|
+
async getPricingContext(contractAddress, requireEnergyShare = false) {
|
|
307
|
+
const [{ energyPrice }, share] = await Promise.all([
|
|
308
|
+
this.getChainPrices(),
|
|
309
|
+
this.getContractEnergyShare(contractAddress).catch((error) => {
|
|
310
|
+
if (requireEnergyShare)
|
|
311
|
+
throw error;
|
|
312
|
+
console.warn(`[tron] energy share lookup failed for ${contractAddress}, pricing in full`, error);
|
|
313
|
+
return TRON_CALLER_PAYS_ALL;
|
|
314
|
+
}),
|
|
315
|
+
]);
|
|
316
|
+
return { energyPrice, share };
|
|
317
|
+
}
|
|
318
|
+
getOriginEnergyAvailable(originAddress) {
|
|
319
|
+
const cached = this.originEnergy.get(originAddress);
|
|
320
|
+
if (cached && Date.now() - cached.readAt < TRON_ORIGIN_ENERGY_TTL_MS)
|
|
321
|
+
return cached.value;
|
|
322
|
+
const value = this.post('/wallet/getaccountresource', { address: originAddress, visible: true })
|
|
323
|
+
.then(body => {
|
|
324
|
+
if (body.Error)
|
|
325
|
+
throw new Error(`[tron] getaccountresource failed: ${body.Error}`);
|
|
326
|
+
return Math.max(0, (body.EnergyLimit ?? 0) - (body.EnergyUsed ?? 0));
|
|
327
|
+
})
|
|
328
|
+
.catch(err => {
|
|
329
|
+
if (this.originEnergy.get(originAddress)?.value === value) {
|
|
330
|
+
this.originEnergy.delete(originAddress);
|
|
331
|
+
}
|
|
332
|
+
throw err;
|
|
333
|
+
});
|
|
334
|
+
this.originEnergy.set(originAddress, { readAt: Date.now(), value });
|
|
335
|
+
return value;
|
|
336
|
+
}
|
|
337
|
+
async post(path, body) {
|
|
338
|
+
const response = await fetch(`${this.rpcUrl}${path}`, {
|
|
339
|
+
method: 'POST',
|
|
340
|
+
headers: this.tronGridHeaders,
|
|
341
|
+
body: JSON.stringify(body),
|
|
342
|
+
});
|
|
343
|
+
if (!response.ok)
|
|
344
|
+
throw new Error(`[tron] ${path} failed: ${response.status}`);
|
|
345
|
+
return response.json();
|
|
346
|
+
}
|
|
347
|
+
async estimateTrc20TransferFee(params) {
|
|
348
|
+
const tronWeb = this.getTronWeb();
|
|
349
|
+
const { energyPrice, share } = await this.getPricingContext(params.contractAddress, params.requireEnergyShare);
|
|
350
|
+
const result = await tronWeb.transactionBuilder.triggerConstantContract(params.contractAddress, 'transfer(address,uint256)', {}, [
|
|
351
|
+
{ type: 'address', value: params.to },
|
|
352
|
+
{ type: 'uint256', value: params.amount },
|
|
353
|
+
], params.from);
|
|
354
|
+
const energy = this.getSimulatedEnergy(result, 'trc20 transfer');
|
|
355
|
+
return String(getCallerEnergy(energy, share) * energyPrice);
|
|
356
|
+
}
|
|
357
|
+
async estimateContractCallFee(params) {
|
|
358
|
+
const { energyPrice, share } = await this.getPricingContext(params.contractAddress, params.requireEnergyShare);
|
|
359
|
+
const response = await fetch(`${this.rpcUrl}/wallet/triggerconstantcontract`, {
|
|
360
|
+
method: 'POST',
|
|
361
|
+
headers: { 'Content-Type': 'application/json', ...this.tronGridHeaders },
|
|
362
|
+
body: JSON.stringify({
|
|
363
|
+
owner_address: params.from,
|
|
364
|
+
contract_address: params.contractAddress,
|
|
365
|
+
data: params.data.startsWith('0x') ? params.data.slice(2) : params.data,
|
|
366
|
+
call_value: Number(params.callValue) || 0,
|
|
367
|
+
visible: true,
|
|
368
|
+
}),
|
|
369
|
+
});
|
|
370
|
+
if (!response.ok) {
|
|
371
|
+
throw new Error(`[tron] contract call simulation request failed: ${response.status}`);
|
|
266
372
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
};
|
|
373
|
+
const result = await response.json();
|
|
374
|
+
const energy = this.getSimulatedEnergy(result, 'contract call');
|
|
375
|
+
return String(getCallerEnergy(energy, share) * energyPrice);
|
|
376
|
+
}
|
|
377
|
+
// A revert still reports result.result: true with the partial energy burned - trusting it would underestimate
|
|
378
|
+
getSimulatedEnergy(result, label) {
|
|
379
|
+
const isReverted = result.transaction?.ret?.some(ret => ret.ret === 'FAILED');
|
|
380
|
+
if (result.result?.result !== true || isReverted || !result.energy_used) {
|
|
381
|
+
throw new Error(`[tron] ${label} simulation failed: ${result.result?.message ?? 'unknown error'}`);
|
|
276
382
|
}
|
|
383
|
+
return result.energy_used;
|
|
277
384
|
}
|
|
278
385
|
}
|
package/dist/esm/tron/types.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export interface TronTx {
|
|
|
29
29
|
amount?: number;
|
|
30
30
|
owner_address?: string;
|
|
31
31
|
to_address?: string;
|
|
32
|
+
contract_address?: string;
|
|
33
|
+
call_value?: number;
|
|
34
|
+
data?: string;
|
|
32
35
|
};
|
|
33
36
|
type_url: string;
|
|
34
37
|
};
|
|
@@ -38,6 +41,7 @@ export interface TronTx {
|
|
|
38
41
|
ref_block_hash: string;
|
|
39
42
|
expiration: number;
|
|
40
43
|
timestamp: number;
|
|
44
|
+
fee_limit?: number;
|
|
41
45
|
};
|
|
42
46
|
raw_data_hex: string;
|
|
43
47
|
txID: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/unchained-client",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.15.0",
|
|
4
4
|
"repository": "https://github.com/shapeshift/web",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"bs58": "^5.0.0",
|
|
28
28
|
"ethers": "6.11.1",
|
|
29
29
|
"isomorphic-ws": "^4.0.1",
|
|
30
|
-
"viem": "2.
|
|
30
|
+
"viem": "2.55.11",
|
|
31
31
|
"ws": "^8.17.1",
|
|
32
|
-
"@shapeshiftoss/caip": "^8.
|
|
33
|
-
"@shapeshiftoss/
|
|
34
|
-
"@shapeshiftoss/
|
|
32
|
+
"@shapeshiftoss/caip": "^8.17.1",
|
|
33
|
+
"@shapeshiftoss/contracts": "^1.1.0",
|
|
34
|
+
"@shapeshiftoss/utils": "^1.3.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@openapitools/openapi-generator-cli": "^2.5.1"
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mayachain Unchained API
|
|
3
|
-
* Provides access to mayachain chain data.
|
|
4
|
-
*
|
|
5
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
-
* https://openapi-generator.tech
|
|
10
|
-
* Do not edit the class manually.
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @export
|
|
15
|
-
* @interface AffiliateFee
|
|
16
|
-
*/
|
|
17
|
-
export interface AffiliateFee {
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @type {string}
|
|
21
|
-
* @memberof AffiliateFee
|
|
22
|
-
*/
|
|
23
|
-
address?: string;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @type {string}
|
|
27
|
-
* @memberof AffiliateFee
|
|
28
|
-
*/
|
|
29
|
-
amount?: string;
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
* @type {string}
|
|
33
|
-
* @memberof AffiliateFee
|
|
34
|
-
*/
|
|
35
|
-
asset?: string;
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
* @type {string}
|
|
39
|
-
* @memberof AffiliateFee
|
|
40
|
-
*/
|
|
41
|
-
blockHash?: string;
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @type {number}
|
|
45
|
-
* @memberof AffiliateFee
|
|
46
|
-
*/
|
|
47
|
-
blockHeight?: number;
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @type {number}
|
|
51
|
-
* @memberof AffiliateFee
|
|
52
|
-
*/
|
|
53
|
-
timestamp?: number;
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @type {string}
|
|
57
|
-
* @memberof AffiliateFee
|
|
58
|
-
*/
|
|
59
|
-
txId?: string;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Check if a given object implements the AffiliateFee interface.
|
|
63
|
-
*/
|
|
64
|
-
export declare function instanceOfAffiliateFee(value: object): boolean;
|
|
65
|
-
export declare function AffiliateFeeFromJSON(json: any): AffiliateFee;
|
|
66
|
-
export declare function AffiliateFeeFromJSONTyped(json: any, ignoreDiscriminator: boolean): AffiliateFee;
|
|
67
|
-
export declare function AffiliateFeeToJSON(value?: AffiliateFee | null): any;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/* eslint-disable */
|
|
5
|
-
/**
|
|
6
|
-
* Mayachain Unchained API
|
|
7
|
-
* Provides access to mayachain chain data.
|
|
8
|
-
*
|
|
9
|
-
* The version of the OpenAPI document: 1.0.0
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
13
|
-
* https://openapi-generator.tech
|
|
14
|
-
* Do not edit the class manually.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AffiliateFeeToJSON = exports.AffiliateFeeFromJSONTyped = exports.AffiliateFeeFromJSON = exports.instanceOfAffiliateFee = void 0;
|
|
18
|
-
const runtime_1 = require("../runtime");
|
|
19
|
-
/**
|
|
20
|
-
* Check if a given object implements the AffiliateFee interface.
|
|
21
|
-
*/
|
|
22
|
-
function instanceOfAffiliateFee(value) {
|
|
23
|
-
let isInstance = true;
|
|
24
|
-
return isInstance;
|
|
25
|
-
}
|
|
26
|
-
exports.instanceOfAffiliateFee = instanceOfAffiliateFee;
|
|
27
|
-
function AffiliateFeeFromJSON(json) {
|
|
28
|
-
return AffiliateFeeFromJSONTyped(json, false);
|
|
29
|
-
}
|
|
30
|
-
exports.AffiliateFeeFromJSON = AffiliateFeeFromJSON;
|
|
31
|
-
function AffiliateFeeFromJSONTyped(json, ignoreDiscriminator) {
|
|
32
|
-
if ((json === undefined) || (json === null)) {
|
|
33
|
-
return json;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
'address': !(0, runtime_1.exists)(json, 'address') ? undefined : json['address'],
|
|
37
|
-
'amount': !(0, runtime_1.exists)(json, 'amount') ? undefined : json['amount'],
|
|
38
|
-
'asset': !(0, runtime_1.exists)(json, 'asset') ? undefined : json['asset'],
|
|
39
|
-
'blockHash': !(0, runtime_1.exists)(json, 'blockHash') ? undefined : json['blockHash'],
|
|
40
|
-
'blockHeight': !(0, runtime_1.exists)(json, 'blockHeight') ? undefined : json['blockHeight'],
|
|
41
|
-
'timestamp': !(0, runtime_1.exists)(json, 'timestamp') ? undefined : json['timestamp'],
|
|
42
|
-
'txId': !(0, runtime_1.exists)(json, 'txId') ? undefined : json['txId'],
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
exports.AffiliateFeeFromJSONTyped = AffiliateFeeFromJSONTyped;
|
|
46
|
-
function AffiliateFeeToJSON(value) {
|
|
47
|
-
if (value === undefined) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
if (value === null) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
'address': value.address,
|
|
55
|
-
'amount': value.amount,
|
|
56
|
-
'asset': value.asset,
|
|
57
|
-
'blockHash': value.blockHash,
|
|
58
|
-
'blockHeight': value.blockHeight,
|
|
59
|
-
'timestamp': value.timestamp,
|
|
60
|
-
'txId': value.txId,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
exports.AffiliateFeeToJSON = AffiliateFeeToJSON;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mayachain Unchained API
|
|
3
|
-
* Provides access to mayachain chain data.
|
|
4
|
-
*
|
|
5
|
-
* The version of the OpenAPI document: 1.0.0
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
9
|
-
* https://openapi-generator.tech
|
|
10
|
-
* Do not edit the class manually.
|
|
11
|
-
*/
|
|
12
|
-
import type { AffiliateFee } from './AffiliateFee';
|
|
13
|
-
/**
|
|
14
|
-
* Contains info about affiliate fee history
|
|
15
|
-
* @export
|
|
16
|
-
* @interface AffiliateFees
|
|
17
|
-
*/
|
|
18
|
-
export interface AffiliateFees {
|
|
19
|
-
/**
|
|
20
|
-
* Affiliate fees
|
|
21
|
-
* @type {Array<AffiliateFee>}
|
|
22
|
-
* @memberof AffiliateFees
|
|
23
|
-
*/
|
|
24
|
-
fees: Array<AffiliateFee>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Check if a given object implements the AffiliateFees interface.
|
|
28
|
-
*/
|
|
29
|
-
export declare function instanceOfAffiliateFees(value: object): boolean;
|
|
30
|
-
export declare function AffiliateFeesFromJSON(json: any): AffiliateFees;
|
|
31
|
-
export declare function AffiliateFeesFromJSONTyped(json: any, ignoreDiscriminator: boolean): AffiliateFees;
|
|
32
|
-
export declare function AffiliateFeesToJSON(value?: AffiliateFees | null): any;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/* eslint-disable */
|
|
5
|
-
/**
|
|
6
|
-
* Mayachain Unchained API
|
|
7
|
-
* Provides access to mayachain chain data.
|
|
8
|
-
*
|
|
9
|
-
* The version of the OpenAPI document: 1.0.0
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
13
|
-
* https://openapi-generator.tech
|
|
14
|
-
* Do not edit the class manually.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AffiliateFeesToJSON = exports.AffiliateFeesFromJSONTyped = exports.AffiliateFeesFromJSON = exports.instanceOfAffiliateFees = void 0;
|
|
18
|
-
const AffiliateFee_1 = require("./AffiliateFee");
|
|
19
|
-
/**
|
|
20
|
-
* Check if a given object implements the AffiliateFees interface.
|
|
21
|
-
*/
|
|
22
|
-
function instanceOfAffiliateFees(value) {
|
|
23
|
-
let isInstance = true;
|
|
24
|
-
isInstance = isInstance && "fees" in value;
|
|
25
|
-
return isInstance;
|
|
26
|
-
}
|
|
27
|
-
exports.instanceOfAffiliateFees = instanceOfAffiliateFees;
|
|
28
|
-
function AffiliateFeesFromJSON(json) {
|
|
29
|
-
return AffiliateFeesFromJSONTyped(json, false);
|
|
30
|
-
}
|
|
31
|
-
exports.AffiliateFeesFromJSON = AffiliateFeesFromJSON;
|
|
32
|
-
function AffiliateFeesFromJSONTyped(json, ignoreDiscriminator) {
|
|
33
|
-
if ((json === undefined) || (json === null)) {
|
|
34
|
-
return json;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
'fees': (json['fees'].map(AffiliateFee_1.AffiliateFeeFromJSON)),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
exports.AffiliateFeesFromJSONTyped = AffiliateFeesFromJSONTyped;
|
|
41
|
-
function AffiliateFeesToJSON(value) {
|
|
42
|
-
if (value === undefined) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
if (value === null) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
'fees': (value.fees.map(AffiliateFee_1.AffiliateFeeToJSON)),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
exports.AffiliateFeesToJSON = AffiliateFeesToJSON;
|