apenft-js-tron 2.0.3 → 2.0.5
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/README.md +45 -37
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/src/queryAPI/index.d.ts +1 -1
- package/dist/src/queryAPI/index.js +4 -4
- package/dist/src/tradeAPI/account.js +13 -2
- package/dist/src/tradeAPI/contractSchemas.js +3 -2
- package/dist/src/tradeAPI/nft.js +2 -2
- package/dist/src/utils/check.js +5 -5
- package/dist/src/utils/error.js +1 -1
- package/dist/src/utils/helper.js +2 -7
- package/index.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -268,33 +268,36 @@ async initApprove({ APENFTOrders, orderType, orderParams})
|
|
|
268
268
|
|
|
269
269
|
Example:
|
|
270
270
|
```js
|
|
271
|
-
let orderType = "FixPriceOrder";
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
271
|
+
let orderType = "FixPriceOrder";
|
|
272
|
+
const params = {
|
|
273
|
+
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
|
|
274
|
+
id: "67",
|
|
275
|
+
price: 20,
|
|
276
|
+
currency: "TRX",
|
|
277
|
+
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
|
|
278
|
+
buyerAddress: "",
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let orderParams = await sdk_query.getFixPriceOrderParams(params);
|
|
282
|
+
|
|
283
|
+
try {
|
|
284
|
+
await initApprove({
|
|
285
|
+
APENFTOrders: sdk_orders,
|
|
286
|
+
orderType: orderType,
|
|
287
|
+
orderParams: orderParams,
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
let result = await sdk_orders.createSellOrder(orderParams);
|
|
291
|
+
console.log(result);
|
|
292
|
+
|
|
293
|
+
if (result && result.orderHash) {
|
|
294
|
+
console.log("FixPriceOrder Listing Successful!");
|
|
295
|
+
} else {
|
|
296
|
+
console.log("Failed");
|
|
297
|
+
}
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.log(e);
|
|
300
|
+
}
|
|
298
301
|
```
|
|
299
302
|
|
|
300
303
|
#### Fixed Price
|
|
@@ -308,10 +311,10 @@ Instructions:
|
|
|
308
311
|
*
|
|
309
312
|
* @param {object} params -
|
|
310
313
|
* {
|
|
311
|
-
* collection: string
|
|
312
|
-
* id: string
|
|
314
|
+
* collection: string // collection address
|
|
315
|
+
* id: string // token id
|
|
313
316
|
* price: number
|
|
314
|
-
* currency: string
|
|
317
|
+
* currency: string
|
|
315
318
|
* expirationTime: number // timestamp, milliseconds
|
|
316
319
|
* buyerAddress?: string // buyer address, optional
|
|
317
320
|
* }
|
|
@@ -323,10 +326,10 @@ async APENFTQuery.getFixPriceOrderParams(params);
|
|
|
323
326
|
Example:
|
|
324
327
|
```js
|
|
325
328
|
const params = {
|
|
326
|
-
collection: "
|
|
327
|
-
id: "
|
|
329
|
+
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
|
|
330
|
+
id: "67",
|
|
328
331
|
price: 20,
|
|
329
|
-
currency: "
|
|
332
|
+
currency: "TRX",
|
|
330
333
|
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
|
|
331
334
|
buyerAddress: "",
|
|
332
335
|
};
|
|
@@ -349,16 +352,21 @@ async APENFTOrders.createSellOrder(orderParams);
|
|
|
349
352
|
|
|
350
353
|
Example:
|
|
351
354
|
```js
|
|
355
|
+
const orderType = "FixPriceOrder";
|
|
352
356
|
const params = {
|
|
353
|
-
collection: "
|
|
354
|
-
id: "
|
|
357
|
+
collection: "TNy9UXCHeAa2jrRiG6CjUppiwKJ9vodfS9",
|
|
358
|
+
id: "67",
|
|
355
359
|
price: 20,
|
|
356
|
-
currency: "
|
|
360
|
+
currency: "TRX",
|
|
357
361
|
expirationTime: new Date().getTime() + 7 * 24 * 60 * 60 * 1000,
|
|
358
362
|
buyerAddress: "",
|
|
359
363
|
};
|
|
360
364
|
let orderParams = await sdk_query.getFixPriceOrderParams(params);
|
|
361
|
-
|
|
365
|
+
await initApprove({
|
|
366
|
+
APENFTOrders: sdk_orders,
|
|
367
|
+
orderType: orderType,
|
|
368
|
+
orderParams: orderParams,
|
|
369
|
+
});
|
|
362
370
|
await sdk_orders.createSellOrder(orderParams);
|
|
363
371
|
```
|
|
364
372
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { APENFTOrders } from './src/tradeAPI';
|
|
2
|
-
export { APENFTQuery } from './src/queryAPI';
|
|
1
|
+
export { APENFTOrders } from './src/tradeAPI/index';
|
|
2
|
+
export { APENFTQuery } from './src/queryAPI/index';
|
|
3
3
|
export { initApprove } from './src/tradeAPI/approve';
|
|
4
4
|
export { Network, MakeOrderType, APENFTSchemaName, OrderSide } from './src/utils/types';
|
|
5
5
|
export { AssetFactory } from './src/tradeAPI/nft';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.APENFTError = exports.NULL_ADDRESS = exports.makeBigNumber = exports.getSchemaList = exports.toBaseUnitAmount = exports.AssetFactory = exports.OrderSide = exports.APENFTSchemaName = exports.MakeOrderType = exports.Network = exports.initApprove = exports.APENFTQuery = exports.APENFTOrders = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "APENFTOrders", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "APENFTQuery", { enumerable: true, get: function () { return
|
|
4
|
+
var index_1 = require("./src/tradeAPI/index");
|
|
5
|
+
Object.defineProperty(exports, "APENFTOrders", { enumerable: true, get: function () { return index_1.APENFTOrders; } });
|
|
6
|
+
var index_2 = require("./src/queryAPI/index");
|
|
7
|
+
Object.defineProperty(exports, "APENFTQuery", { enumerable: true, get: function () { return index_2.APENFTQuery; } });
|
|
8
8
|
var approve_1 = require("./src/tradeAPI/approve");
|
|
9
9
|
Object.defineProperty(exports, "initApprove", { enumerable: true, get: function () { return approve_1.initApprove; } });
|
|
10
10
|
var types_1 = require("./src/utils/types");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryAPI } from "./restful/queryAPI";
|
|
2
|
-
import { CollectionApi, AssetApi, AccountApi } from "./graphql";
|
|
2
|
+
import { CollectionApi, AssetApi, AccountApi } from "./graphql/index";
|
|
3
3
|
import TronWeb from "tronweb";
|
|
4
4
|
import { APIConfig, AddressParams, CollectionTradeTrendParams, CollectionTradingHistoryParams, HotCollectionsParams, FixPriceOrderParams, EnglishAuctionOrderParams, LowerPriceOrderParams, Pagination } from "../utils/types";
|
|
5
5
|
export declare class APENFTQuery extends QueryAPI {
|
|
@@ -64,7 +64,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
exports.APENFTQuery = void 0;
|
|
66
66
|
var queryAPI_1 = require("./restful/queryAPI");
|
|
67
|
-
var
|
|
67
|
+
var index_1 = require("./graphql/index");
|
|
68
68
|
var constants_1 = require("../utils/constants");
|
|
69
69
|
var utils_1 = require("../utils/utils");
|
|
70
70
|
var types_1 = require("../utils/types");
|
|
@@ -82,15 +82,15 @@ var APENFTQuery = /** @class */ (function (_super) {
|
|
|
82
82
|
if (((_b = _this.accountAddress) === null || _b === void 0 ? void 0 : _b.length) > 0)
|
|
83
83
|
_this.accountAddress;
|
|
84
84
|
_this.gqlApi = {
|
|
85
|
-
collectionApi: new
|
|
85
|
+
collectionApi: new index_1.GqlApi.collectionApi({
|
|
86
86
|
networkName: networkName,
|
|
87
87
|
account: _this.accountAddress,
|
|
88
88
|
}),
|
|
89
|
-
assetApi: new
|
|
89
|
+
assetApi: new index_1.GqlApi.assetApi({
|
|
90
90
|
networkName: networkName,
|
|
91
91
|
account: _this.accountAddress,
|
|
92
92
|
}),
|
|
93
|
-
accountApi: new
|
|
93
|
+
accountApi: new index_1.GqlApi.accountApi({
|
|
94
94
|
networkName: networkName,
|
|
95
95
|
account: _this.accountAddress,
|
|
96
96
|
}),
|
|
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
14
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
17
28
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
29
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
30
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -173,7 +184,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
173
184
|
buy.paymentTokenApprove.isApprove = isApprove;
|
|
174
185
|
buy.paymentTokenApprove.balances = balances;
|
|
175
186
|
return [3 /*break*/, 9];
|
|
176
|
-
case 8: throw new error_1.APENFTError({ code: '1204' });
|
|
187
|
+
case 8: throw new error_1.APENFTError({ code: '1204', context: __assign({}, paymentToken) });
|
|
177
188
|
case 9: return [2 /*return*/, buy];
|
|
178
189
|
}
|
|
179
190
|
});
|
|
@@ -261,7 +272,7 @@ var Account = /** @class */ (function (_super) {
|
|
|
261
272
|
buy.paymentTokenApprove.isApprove = isApprove;
|
|
262
273
|
buy.paymentTokenApprove.balances = balances;
|
|
263
274
|
return [3 /*break*/, 11];
|
|
264
|
-
case 10: throw new error_1.APENFTError({ code: '1204' });
|
|
275
|
+
case 10: throw new error_1.APENFTError({ code: '1204', context: __assign({}, paymentToken) });
|
|
265
276
|
case 11: return [2 /*return*/, buy];
|
|
266
277
|
}
|
|
267
278
|
});
|
|
@@ -142,7 +142,7 @@ var ContractSchemas = /** @class */ (function (_super) {
|
|
|
142
142
|
from: this.web3.defaultAddress.hex,
|
|
143
143
|
callValue: 0,
|
|
144
144
|
_isConstant: true,
|
|
145
|
-
feeLimit:
|
|
145
|
+
feeLimit: 2000000000
|
|
146
146
|
};
|
|
147
147
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
148
148
|
var tradePromise = _this.web3.transactionBuilder.triggerSmartContract(contractAddress, functionSelector, options, parameters, options.from ? _this.web3.address.toHex(options.from) : false);
|
|
@@ -201,7 +201,8 @@ var ContractSchemas = /** @class */ (function (_super) {
|
|
|
201
201
|
options = {
|
|
202
202
|
from: this.web3.defaultAddress.base58,
|
|
203
203
|
callValue: value || 0,
|
|
204
|
-
shouldPollResponse: true
|
|
204
|
+
shouldPollResponse: true,
|
|
205
|
+
feeLimit: 2000000000
|
|
205
206
|
};
|
|
206
207
|
defer = (0, PromiEvent_1.default)();
|
|
207
208
|
return [4 /*yield*/, this.web3.transactionBuilder.triggerSmartContract(contractAddress, functionSelector, options, parameters)];
|
package/dist/src/tradeAPI/nft.js
CHANGED
|
@@ -134,7 +134,7 @@ var AssetFactory = /** @class */ (function (_super) {
|
|
|
134
134
|
case 0:
|
|
135
135
|
defaultOptions = {
|
|
136
136
|
shouldPollResponse: true,
|
|
137
|
-
feeLimit:
|
|
137
|
+
feeLimit: 2000000000,
|
|
138
138
|
callValue: 0,
|
|
139
139
|
userFeePercentage: 30,
|
|
140
140
|
originEnergyLimit: 1e7
|
|
@@ -197,7 +197,7 @@ var AssetFactory = /** @class */ (function (_super) {
|
|
|
197
197
|
case 0:
|
|
198
198
|
defaultOptions = {
|
|
199
199
|
shouldPollResponse: true,
|
|
200
|
-
feeLimit:
|
|
200
|
+
feeLimit: 2000000000,
|
|
201
201
|
callValue: 0,
|
|
202
202
|
userFeePercentage: 30,
|
|
203
203
|
originEnergyLimit: 1e7
|
package/dist/src/utils/check.js
CHANGED
|
@@ -180,7 +180,7 @@ function checkApproveSchemaProxy(contract, orderMetadata, account) {
|
|
|
180
180
|
exports.checkApproveSchemaProxy = checkApproveSchemaProxy;
|
|
181
181
|
function checkUnhashedOrder(contract, order) {
|
|
182
182
|
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
-
var erc20Contract, metadata, sell, buy, assetAddress, erc20Bal,
|
|
183
|
+
var erc20Contract, metadata, sell, buy, assetAddress, erc20Bal, trxBal, error_2;
|
|
184
184
|
return __generator(this, function (_a) {
|
|
185
185
|
switch (_a.label) {
|
|
186
186
|
case 0:
|
|
@@ -214,16 +214,16 @@ function checkUnhashedOrder(contract, order) {
|
|
|
214
214
|
case 6:
|
|
215
215
|
erc20Bal = (_a.sent()).erc20Bal;
|
|
216
216
|
if ((0, helper_1.makeBigNumber)(erc20Bal).lt(buy.basePrice))
|
|
217
|
-
throw new error_1.APENFTError({ code: '1104', context: { assetType: 'ERC20' } });
|
|
217
|
+
throw new error_1.APENFTError({ code: '1104', context: { assetType: 'ERC20', erc20Bal: erc20Bal, buyBasePrice: buy.basePrice } });
|
|
218
218
|
return [4 /*yield*/, checkApproveTokenTransferProxy(contract.exchange, erc20Contract, buy.maker)];
|
|
219
219
|
case 7:
|
|
220
220
|
_a.sent();
|
|
221
221
|
return [3 /*break*/, 10];
|
|
222
222
|
case 8: return [4 /*yield*/, (0, helper_1.getAccountBalance)(contract.web3, buy.maker)];
|
|
223
223
|
case 9:
|
|
224
|
-
|
|
225
|
-
if ((0, helper_1.makeBigNumber)(
|
|
226
|
-
throw new error_1.APENFTError({ code: '1104', context: { assetType: '
|
|
224
|
+
trxBal = (_a.sent()).trxBal;
|
|
225
|
+
if ((0, helper_1.makeBigNumber)(trxBal).lt(buy.basePrice))
|
|
226
|
+
throw new error_1.APENFTError({ code: '1104', context: { assetType: 'TRX', trxBal: trxBal, buyBasePrice: buy.basePrice } });
|
|
227
227
|
_a.label = 10;
|
|
228
228
|
case 10:
|
|
229
229
|
checkDataToCall(contract.networkName, order);
|
package/dist/src/utils/error.js
CHANGED
package/dist/src/utils/helper.js
CHANGED
|
@@ -105,11 +105,6 @@ function web3Sign(web3, msg, account) {
|
|
|
105
105
|
byteArray = web3.utils.code.hexStr2byteArray(hexStrWithout0x);
|
|
106
106
|
hash = web3.utils.ethersUtils.keccak256(byteArray).replace(/^0x/, '');
|
|
107
107
|
}
|
|
108
|
-
// type===2 ledger wallet address
|
|
109
|
-
// type===0 general wallet address
|
|
110
|
-
if (web3.defaultAddress && web3.defaultAddress.type !== 2) {
|
|
111
|
-
hash += '1';
|
|
112
|
-
}
|
|
113
108
|
return [4 /*yield*/, web3.trx.sign(hash.replace(/^0x/, ''))];
|
|
114
109
|
case 1:
|
|
115
110
|
signatureRes = _a.sent();
|
|
@@ -138,7 +133,7 @@ function getAccountBalance(web3, account, erc20) {
|
|
|
138
133
|
var trxBal, erc20Bal;
|
|
139
134
|
return __generator(this, function (_a) {
|
|
140
135
|
switch (_a.label) {
|
|
141
|
-
case 0: return [4 /*yield*/, web3.trx.
|
|
136
|
+
case 0: return [4 /*yield*/, web3.trx.getUnconfirmedBalance(account).catch(function (error) {
|
|
142
137
|
throw new error_1.APENFTError({
|
|
143
138
|
code: '2003',
|
|
144
139
|
context: { funcName: 'getAccountBalance.getBalance ' }
|
|
@@ -160,7 +155,7 @@ function getAccountBalance(web3, account, erc20) {
|
|
|
160
155
|
case 2:
|
|
161
156
|
erc20Bal = _a.sent();
|
|
162
157
|
_a.label = 3;
|
|
163
|
-
case 3: return [2 /*return*/, {
|
|
158
|
+
case 3: return [2 /*return*/, { trxBal: Number(trxBal), erc20Bal: Number(erc20Bal) }];
|
|
164
159
|
}
|
|
165
160
|
});
|
|
166
161
|
});
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { APENFTOrders } from './src/tradeAPI'
|
|
2
|
-
export { APENFTQuery } from './src/queryAPI'
|
|
1
|
+
export { APENFTOrders } from './src/tradeAPI/index'
|
|
2
|
+
export { APENFTQuery } from './src/queryAPI/index'
|
|
3
3
|
export { initApprove } from './src/tradeAPI/approve'
|
|
4
4
|
export { Network, MakeOrderType, APENFTSchemaName, OrderSide } from './src/utils/types'
|
|
5
5
|
export { AssetFactory } from './src/tradeAPI/nft'
|