@xoxno/sdk-js 0.0.1
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/.editorconfig +9 -0
- package/.eslintrc.json +19 -0
- package/.github/workflows/npm-publish-github-packages.yml +36 -0
- package/.prettierrc +8 -0
- package/.releaserc +10 -0
- package/.vscode/settings.json +3 -0
- package/LICENSE +674 -0
- package/commitlint.config.js +3 -0
- package/coverage/clover.xml +280 -0
- package/coverage/coverage-final.json +12 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/collection/index.html +116 -0
- package/coverage/lcov-report/collection/index.ts.html +559 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +161 -0
- package/coverage/lcov-report/interactions/index.html +116 -0
- package/coverage/lcov-report/interactions/index.ts.html +775 -0
- package/coverage/lcov-report/nft/index.html +116 -0
- package/coverage/lcov-report/nft/index.ts.html +379 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/utils/SmartContractAbis.ts.html +331 -0
- package/coverage/lcov-report/utils/SmartContractService.ts.html +136 -0
- package/coverage/lcov-report/utils/api.ts.html +484 -0
- package/coverage/lcov-report/utils/const.ts.html +163 -0
- package/coverage/lcov-report/utils/getActivity.ts.html +250 -0
- package/coverage/lcov-report/utils/helpers.ts.html +127 -0
- package/coverage/lcov-report/utils/index.html +221 -0
- package/coverage/lcov-report/utils/regex.ts.html +106 -0
- package/coverage/lcov-report/utils/scCalls.ts.html +229 -0
- package/coverage/lcov.info +525 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +64 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1279 -0
- package/docs/classes/collection.CollectionModule.html +232 -0
- package/docs/classes/interactions.SCInteraction.html +370 -0
- package/docs/classes/nft.NFTModule.html +208 -0
- package/docs/classes/utils_SmartContractAbis.SmartContractAbis.html +198 -0
- package/docs/classes/utils_api.APIClient.html +212 -0
- package/docs/classes/utils_scCalls.ContractQueryRunner.html +129 -0
- package/docs/enums/types_collection.FieldsToSelect.html +186 -0
- package/docs/enums/types_collection.Marketplace.html +102 -0
- package/docs/enums/types_collection.SearchOrderBy.html +130 -0
- package/docs/enums/types_trading.OrderByTradingActivity.html +102 -0
- package/docs/enums/types_trading.SelectFieldsTradingActivity.html +144 -0
- package/docs/enums/utils_api.Chain.html +88 -0
- package/docs/functions/utils_SmartContractService.getSmartContract.html +77 -0
- package/docs/functions/utils_getActivity.getActivity.html +89 -0
- package/docs/functions/utils_helpers.getIdentifierFromColAndNonce.html +76 -0
- package/docs/functions/utils_helpers.nonceToHex.html +74 -0
- package/docs/functions/utils_regex.isValidCollectionTicker.html +74 -0
- package/docs/functions/utils_regex.isValidNftIdentifier.html +74 -0
- package/docs/index.html +55 -0
- package/docs/interfaces/types_collection.AttributeData.html +99 -0
- package/docs/interfaces/types_collection.Filter.html +157 -0
- package/docs/interfaces/types_collection.GlobalOffer.html +176 -0
- package/docs/interfaces/types_collection.ICollectionAttributes.html +85 -0
- package/docs/interfaces/types_collection.ICollectionProfile.html +263 -0
- package/docs/interfaces/types_collection.IMintInfo.html +155 -0
- package/docs/interfaces/types_collection.ISocials.html +127 -0
- package/docs/interfaces/types_collection.MetadataAttribute.html +92 -0
- package/docs/interfaces/types_collection.SearchNFTs.html +127 -0
- package/docs/interfaces/types_collection.SearchNFTsArgs.html +225 -0
- package/docs/interfaces/types_collection.SearchNFTsResponse.html +132 -0
- package/docs/interfaces/types_collection.TradingActivity.html +232 -0
- package/docs/interfaces/types_collection.TraitValues.html +85 -0
- package/docs/interfaces/types_nft.GameData.html +92 -0
- package/docs/interfaces/types_nft.NFTAttribute.html +127 -0
- package/docs/interfaces/types_nft.NFTMetadata.html +104 -0
- package/docs/interfaces/types_nft.NftData.html +253 -0
- package/docs/interfaces/types_nft.NftValue.html +106 -0
- package/docs/interfaces/types_nft.OffersInfo.html +169 -0
- package/docs/interfaces/types_nft.OriginalMedia.html +92 -0
- package/docs/interfaces/types_nft.SaleInfoNft.html +211 -0
- package/docs/interfaces/types_trading.TradincActivityArgs.html +225 -0
- package/docs/interfaces/types_trading.TradingActivityQueryFilter.html +151 -0
- package/docs/interfaces/types_trading.TradingActivityResponse.html +106 -0
- package/docs/modules/collection.html +71 -0
- package/docs/modules/interactions.html +71 -0
- package/docs/modules/nft.html +71 -0
- package/docs/modules/types.html +189 -0
- package/docs/modules/types_collection.html +104 -0
- package/docs/modules/types_interactions.html +69 -0
- package/docs/modules/types_nft.html +85 -0
- package/docs/modules/types_trading.html +82 -0
- package/docs/modules/utils_SmartContractAbis.html +71 -0
- package/docs/modules/utils_SmartContractService.html +71 -0
- package/docs/modules/utils_api.html +76 -0
- package/docs/modules/utils_const.html +95 -0
- package/docs/modules/utils_getActivity.html +71 -0
- package/docs/modules/utils_helpers.html +73 -0
- package/docs/modules/utils_regex.html +73 -0
- package/docs/modules/utils_scCalls.html +71 -0
- package/docs/modules.html +76 -0
- package/docs/types/types_interactions.Offer.html +89 -0
- package/docs/variables/utils_const.API_URL.html +76 -0
- package/docs/variables/utils_const.API_URL_DEV.html +76 -0
- package/docs/variables/utils_const.DR_SC.html +76 -0
- package/docs/variables/utils_const.FM_SC.html +76 -0
- package/docs/variables/utils_const.KG_SC.html +76 -0
- package/docs/variables/utils_const.Manager_SC.html +76 -0
- package/docs/variables/utils_const.Manager_SC_DEV.html +76 -0
- package/docs/variables/utils_const.P2P_SC.html +76 -0
- package/docs/variables/utils_const.P2P_SC_DEV.html +76 -0
- package/docs/variables/utils_const.Staking_SC.html +76 -0
- package/docs/variables/utils_const.Staking_SC_DEV.html +76 -0
- package/docs/variables/utils_const.XOXNO_SC.html +76 -0
- package/docs/variables/utils_const.XOXNO_SC_DEV.html +76 -0
- package/jest.config.js +7 -0
- package/package.json +74 -0
- package/src/collection/__tests__/collection.test.ts +100 -0
- package/src/collection/index.ts +158 -0
- package/src/index.ts +20 -0
- package/src/interactions/__tests__/market.test.ts +92 -0
- package/src/interactions/index.ts +228 -0
- package/src/nft/__tests__/nft.test.ts +84 -0
- package/src/nft/index.ts +98 -0
- package/src/types/collection.d.ts +267 -0
- package/src/types/index.ts +3 -0
- package/src/types/interactions.d.ts +16 -0
- package/src/types/nft.d.ts +100 -0
- package/src/types/trading.d.ts +95 -0
- package/src/utils/SmartContractAbis.ts +82 -0
- package/src/utils/SmartContractService.ts +17 -0
- package/src/utils/api.ts +133 -0
- package/src/utils/const.ts +26 -0
- package/src/utils/getActivity.ts +55 -0
- package/src/utils/helpers.ts +14 -0
- package/src/utils/regex.ts +7 -0
- package/src/utils/scCalls.ts +48 -0
- package/tsconfig.json +13 -0
- package/webpack.config.js +28 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AbiRegistry } from '@multiversx/sdk-core';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export class SmartContractAbis {
|
|
5
|
+
private static manager: AbiRegistry;
|
|
6
|
+
private static exchange: AbiRegistry;
|
|
7
|
+
private static minter: AbiRegistry;
|
|
8
|
+
private static market: AbiRegistry;
|
|
9
|
+
private static staking: AbiRegistry;
|
|
10
|
+
private static p2p: AbiRegistry;
|
|
11
|
+
|
|
12
|
+
public static async getMarket(): Promise<AbiRegistry> {
|
|
13
|
+
if (!SmartContractAbis.market) {
|
|
14
|
+
const { data } = await axios(
|
|
15
|
+
`${'https://media.xoxno.com/'}smartcontractabi/esdt-nft-marketplace.abi.json`
|
|
16
|
+
);
|
|
17
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
18
|
+
SmartContractAbis.market = abiRegistry;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return SmartContractAbis.market;
|
|
22
|
+
}
|
|
23
|
+
public static async getManager(): Promise<AbiRegistry> {
|
|
24
|
+
if (!SmartContractAbis.manager) {
|
|
25
|
+
const { data } = await axios(
|
|
26
|
+
`${'https://media.xoxno.com/'}smartcontractabi/manage.json`
|
|
27
|
+
);
|
|
28
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
29
|
+
SmartContractAbis.manager = abiRegistry;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return SmartContractAbis.manager;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static async getMinter(): Promise<AbiRegistry> {
|
|
36
|
+
if (!SmartContractAbis.minter) {
|
|
37
|
+
const { data } = await axios(
|
|
38
|
+
`${'https://media.xoxno.com/'}smartcontractabi/minter.json`
|
|
39
|
+
);
|
|
40
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
41
|
+
SmartContractAbis.minter = abiRegistry;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return SmartContractAbis.minter;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public static async getStaking(): Promise<AbiRegistry> {
|
|
48
|
+
if (!SmartContractAbis.staking) {
|
|
49
|
+
const { data } = await axios(
|
|
50
|
+
`${'https://media.xoxno.com/'}smartcontractabi/staking-nfts.abi.json`
|
|
51
|
+
);
|
|
52
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
53
|
+
SmartContractAbis.staking = abiRegistry;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return SmartContractAbis.staking;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public static async getExchange(): Promise<AbiRegistry> {
|
|
60
|
+
if (!SmartContractAbis.exchange) {
|
|
61
|
+
const { data } = await axios(
|
|
62
|
+
`${'https://media.xoxno.com/'}smartcontractabi/rs-exchange.abi.json`
|
|
63
|
+
);
|
|
64
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
65
|
+
SmartContractAbis.exchange = abiRegistry;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return SmartContractAbis.exchange;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static async getP2P(): Promise<AbiRegistry> {
|
|
72
|
+
if (!SmartContractAbis.p2p) {
|
|
73
|
+
const { data } = await axios(
|
|
74
|
+
`${'https://media.xoxno.com/'}smartcontractabi/p2p.abi.json`
|
|
75
|
+
);
|
|
76
|
+
const abiRegistry = AbiRegistry.create(data);
|
|
77
|
+
SmartContractAbis.p2p = abiRegistry;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return SmartContractAbis.p2p;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbiRegistry,
|
|
3
|
+
Address,
|
|
4
|
+
SmartContract,
|
|
5
|
+
SmartContractAbi,
|
|
6
|
+
} from '@multiversx/sdk-core/out';
|
|
7
|
+
|
|
8
|
+
export const getSmartContract = (
|
|
9
|
+
abiRegistry: AbiRegistry,
|
|
10
|
+
address: Address,
|
|
11
|
+
implementedInterface: string
|
|
12
|
+
) => {
|
|
13
|
+
return new SmartContract({
|
|
14
|
+
address: address,
|
|
15
|
+
abi: new SmartContractAbi(abiRegistry, [implementedInterface]),
|
|
16
|
+
});
|
|
17
|
+
};
|
package/src/utils/api.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
API_URL,
|
|
4
|
+
DR_SC,
|
|
5
|
+
FM_SC,
|
|
6
|
+
KG_SC,
|
|
7
|
+
Manager_SC,
|
|
8
|
+
Manager_SC_DEV,
|
|
9
|
+
P2P_SC,
|
|
10
|
+
P2P_SC_DEV,
|
|
11
|
+
Staking_SC,
|
|
12
|
+
Staking_SC_DEV,
|
|
13
|
+
XOXNO_SC,
|
|
14
|
+
XOXNO_SC_DEV,
|
|
15
|
+
} from './const';
|
|
16
|
+
export const enum Chain {
|
|
17
|
+
MAINNET = '1',
|
|
18
|
+
DEVNET = 'D',
|
|
19
|
+
}
|
|
20
|
+
export class APIClient {
|
|
21
|
+
private static instance: APIClient;
|
|
22
|
+
public apiUrl: string;
|
|
23
|
+
private apiKey: string;
|
|
24
|
+
public chain: Chain;
|
|
25
|
+
public config: {
|
|
26
|
+
XO_SC: string;
|
|
27
|
+
FM_SC: string;
|
|
28
|
+
DR_SC: string;
|
|
29
|
+
KG_SC: string;
|
|
30
|
+
Staking_SC: string;
|
|
31
|
+
Manager_SC: string;
|
|
32
|
+
P2P_SC: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
private constructor(apiUrl: string, apiKey: string, chain: Chain) {
|
|
36
|
+
this.apiUrl = apiUrl;
|
|
37
|
+
this.apiKey = apiKey;
|
|
38
|
+
this.chain = chain;
|
|
39
|
+
this.config =
|
|
40
|
+
chain === Chain.MAINNET
|
|
41
|
+
? {
|
|
42
|
+
XO_SC: XOXNO_SC,
|
|
43
|
+
FM_SC: FM_SC,
|
|
44
|
+
DR_SC,
|
|
45
|
+
KG_SC,
|
|
46
|
+
Staking_SC,
|
|
47
|
+
Manager_SC,
|
|
48
|
+
P2P_SC,
|
|
49
|
+
}
|
|
50
|
+
: {
|
|
51
|
+
XO_SC: XOXNO_SC_DEV,
|
|
52
|
+
FM_SC,
|
|
53
|
+
DR_SC,
|
|
54
|
+
KG_SC,
|
|
55
|
+
Staking_SC: Staking_SC_DEV,
|
|
56
|
+
Manager_SC: Manager_SC_DEV,
|
|
57
|
+
P2P_SC: P2P_SC_DEV,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public static init(
|
|
62
|
+
apiUrl: string = API_URL,
|
|
63
|
+
apiKey = '',
|
|
64
|
+
chain: Chain = Chain.MAINNET
|
|
65
|
+
): APIClient {
|
|
66
|
+
if (!APIClient.instance) {
|
|
67
|
+
APIClient.instance = new APIClient(apiUrl, apiKey, chain);
|
|
68
|
+
}
|
|
69
|
+
return APIClient.instance;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static getClient(): APIClient {
|
|
73
|
+
if (!APIClient.instance) {
|
|
74
|
+
throw new Error('APIClient has not been initialized');
|
|
75
|
+
}
|
|
76
|
+
return APIClient.instance;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public fetchWithTimeout = async <T>(
|
|
80
|
+
path: string,
|
|
81
|
+
options: Record<string, unknown> = {},
|
|
82
|
+
timeout = 40000
|
|
83
|
+
): Promise<T> => {
|
|
84
|
+
const timestamp = Math.round(new Date().getTime() / 1000);
|
|
85
|
+
|
|
86
|
+
const headers = {
|
|
87
|
+
'Accept-Encoding': 'gzip,deflate,br',
|
|
88
|
+
'xo-time': `Sent-At:${timestamp}`,
|
|
89
|
+
Referer: 'https://xoxno.sdk',
|
|
90
|
+
'User-Agent': 'XOXNO/1.0/SDK',
|
|
91
|
+
...(options.method === 'POST'
|
|
92
|
+
? { 'Content-Type': 'application/json' }
|
|
93
|
+
: {}),
|
|
94
|
+
...((options.headers as object) ?? {}),
|
|
95
|
+
};
|
|
96
|
+
try {
|
|
97
|
+
const { data } = await axios(
|
|
98
|
+
`${this.apiUrl}${path}${
|
|
99
|
+
options.params
|
|
100
|
+
? '?' +
|
|
101
|
+
Object.keys(options.params as any)
|
|
102
|
+
.map((key) => {
|
|
103
|
+
return `${key}=${encodeURIComponent(
|
|
104
|
+
(options.params as any)[key]
|
|
105
|
+
)}`;
|
|
106
|
+
})
|
|
107
|
+
.join('&')
|
|
108
|
+
: ''
|
|
109
|
+
}`,
|
|
110
|
+
{
|
|
111
|
+
timeout,
|
|
112
|
+
...options,
|
|
113
|
+
...(Object.keys(headers).length ? { headers } : {}),
|
|
114
|
+
method: (options.method as any) ?? 'GET',
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const result = data;
|
|
119
|
+
|
|
120
|
+
return result as T;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
'Something went wrong inside fetchWithTimeout' +
|
|
124
|
+
' ' +
|
|
125
|
+
path +
|
|
126
|
+
' ' +
|
|
127
|
+
JSON.stringify(options) +
|
|
128
|
+
' ' +
|
|
129
|
+
error
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const API_URL = 'https://api.xoxno.com';
|
|
2
|
+
export const API_URL_DEV = 'https://api-dev.xoxno.com';
|
|
3
|
+
|
|
4
|
+
export const XOXNO_SC =
|
|
5
|
+
'erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8';
|
|
6
|
+
export const FM_SC =
|
|
7
|
+
'erd1qqqqqqqqqqqqqpgq705fxpfrjne0tl3ece0rrspykq88mynn4kxs2cg43s';
|
|
8
|
+
export const DR_SC =
|
|
9
|
+
'erd1qqqqqqqqqqqqqpgqd9rvv2n378e27jcts8vfwynpx0gfl5ufz6hqhfy0u0';
|
|
10
|
+
export const KG_SC =
|
|
11
|
+
'erd1qqqqqqqqqqqqqpgq8xwzu82v8ex3h4ayl5lsvxqxnhecpwyvwe0sf2qj4e';
|
|
12
|
+
export const Staking_SC =
|
|
13
|
+
'erd1qqqqqqqqqqqqqpgqvpkd3g3uwludduv3797j54qt6c888wa59w2shntt6z';
|
|
14
|
+
export const Manager_SC =
|
|
15
|
+
'erd1qqqqqqqqqqqqqpgqg9fa0dmpn8fu3fnleeqn5zt8rl8mdqjkys5s2gtas7';
|
|
16
|
+
export const P2P_SC =
|
|
17
|
+
'erd1qqqqqqqqqqqqqpgq47y8hnct68v6asjv6gxem6h9rumn9frzah0skhxxt6';
|
|
18
|
+
|
|
19
|
+
export const XOXNO_SC_DEV =
|
|
20
|
+
'erd1qqqqqqqqqqqqqpgqn4fnwl43hhchz9emdy66eh5azzhl599zd8ssxjdyh3';
|
|
21
|
+
export const Staking_SC_DEV =
|
|
22
|
+
'erd1qqqqqqqqqqqqqpgqmkt2fvumf0zgum5qd0awl2l46x2pxdgmr5rswjr6r8';
|
|
23
|
+
export const Manager_SC_DEV =
|
|
24
|
+
'erd1qqqqqqqqqqqqqpgq6sysl7mga393a850xemfpawaqanf4da5d8ssp3xamn';
|
|
25
|
+
export const P2P_SC_DEV =
|
|
26
|
+
'erd1qqqqqqqqqqqqqpgqhuvnvkwwmucdzy3g7pvgvjumjfcgfwf69w2svch5c2';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TradincActivityArgs,
|
|
3
|
+
TradingActivityResponse,
|
|
4
|
+
TradingActivityQueryFilter,
|
|
5
|
+
} from '../types/trading';
|
|
6
|
+
import { APIClient } from '../utils/api';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Fetches the trading activity of the given collections
|
|
10
|
+
* @param args - The trading activity arguments
|
|
11
|
+
* @param api - The API client
|
|
12
|
+
* @returns - The trading activity response
|
|
13
|
+
* @throws - If the top is greater than 35
|
|
14
|
+
*/
|
|
15
|
+
export const getActivity = async (
|
|
16
|
+
args: TradincActivityArgs,
|
|
17
|
+
api: APIClient
|
|
18
|
+
): Promise<TradingActivityResponse> => {
|
|
19
|
+
if (args.top && args.top > 35) {
|
|
20
|
+
throw new Error('Top cannot be greater than 35');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const payloadBody: TradingActivityQueryFilter = {
|
|
24
|
+
filters: {
|
|
25
|
+
collection: args.collections,
|
|
26
|
+
identifier: args.identifiers || undefined,
|
|
27
|
+
address: args.owners || undefined,
|
|
28
|
+
tokens: args.placedInToken || undefined,
|
|
29
|
+
marketplace: args.marketplaces || undefined,
|
|
30
|
+
action: args.actions || undefined,
|
|
31
|
+
range: args.priceRange,
|
|
32
|
+
rankRange: args.rankRange,
|
|
33
|
+
timestampRange: args.timestampRange,
|
|
34
|
+
attributes: args.attributes,
|
|
35
|
+
},
|
|
36
|
+
orderBy: args.orderBy,
|
|
37
|
+
select: args.select,
|
|
38
|
+
top: args.top || 35,
|
|
39
|
+
skip: args.skip || 0,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const buffer = Buffer.from(JSON.stringify(payloadBody)).toString('base64');
|
|
43
|
+
const response = await api.fetchWithTimeout<TradingActivityResponse>(
|
|
44
|
+
`/getTradingActivity/${buffer}`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
...response,
|
|
49
|
+
getNextPagePayload: {
|
|
50
|
+
...args,
|
|
51
|
+
skip: (args.skip ?? 0) + (args.top ?? 35),
|
|
52
|
+
},
|
|
53
|
+
empty: response.resources.length === 0,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const nonceToHex = (nonce: number): string => {
|
|
2
|
+
let nonceHex = nonce.toString(16);
|
|
3
|
+
if (nonceHex.length % 2 !== 0) {
|
|
4
|
+
nonceHex = '0' + nonceHex;
|
|
5
|
+
}
|
|
6
|
+
return nonceHex;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const getIdentifierFromColAndNonce = (
|
|
10
|
+
collection: string,
|
|
11
|
+
nonce: number
|
|
12
|
+
): string => {
|
|
13
|
+
return [collection, nonceToHex(nonce)].join('-');
|
|
14
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const isValidCollectionTicker = (ticker: string): boolean => {
|
|
2
|
+
return /^[A-Z0-9]{3,10}-[a-z0-9]{6}$/.test(ticker);
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export const isValidNftIdentifier = (identifier: string): boolean => {
|
|
6
|
+
return /^[A-Za-z0-9]{3,10}-[A-Za-z0-9]{6}-[A-Za-z0-9]{2,5}$/.test(identifier);
|
|
7
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContractQueryResponse,
|
|
3
|
+
ProxyNetworkProvider,
|
|
4
|
+
} from '@multiversx/sdk-network-providers';
|
|
5
|
+
import { INetworkProvider } from '@multiversx/sdk-network-providers/out/interface';
|
|
6
|
+
import {
|
|
7
|
+
ResultsParser,
|
|
8
|
+
SmartContract,
|
|
9
|
+
Interaction,
|
|
10
|
+
TypedOutcomeBundle,
|
|
11
|
+
} from '@multiversx/sdk-core';
|
|
12
|
+
import { APIClient } from './api';
|
|
13
|
+
|
|
14
|
+
export class ContractQueryRunner {
|
|
15
|
+
private readonly proxy: INetworkProvider;
|
|
16
|
+
private readonly parser: ResultsParser = new ResultsParser();
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
const api = APIClient.getClient().apiUrl;
|
|
20
|
+
this.proxy = new ProxyNetworkProvider(api, {
|
|
21
|
+
timeout: 10000,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async runQuery(
|
|
26
|
+
contract: SmartContract,
|
|
27
|
+
interaction: Interaction
|
|
28
|
+
): Promise<TypedOutcomeBundle> {
|
|
29
|
+
try {
|
|
30
|
+
const queryResponse: ContractQueryResponse =
|
|
31
|
+
await this.proxy.queryContract(interaction.buildQuery());
|
|
32
|
+
|
|
33
|
+
return this.parser.parseQueryResponse(
|
|
34
|
+
queryResponse,
|
|
35
|
+
interaction.getEndpoint()
|
|
36
|
+
);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.log(
|
|
39
|
+
`Unexpected error when running query '${
|
|
40
|
+
interaction.buildQuery().func
|
|
41
|
+
}' to sc '${contract.getAddress().bech32()}' `
|
|
42
|
+
);
|
|
43
|
+
console.error(error);
|
|
44
|
+
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"forceConsistentCasingInFileNames": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src"]
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
mode: 'production',
|
|
6
|
+
entry: './src/index.ts',
|
|
7
|
+
output: {
|
|
8
|
+
path: path.resolve(__dirname, 'dist'),
|
|
9
|
+
filename: 'xoxno.min.js',
|
|
10
|
+
library: {
|
|
11
|
+
name: 'XOXNO',
|
|
12
|
+
type: 'umd',
|
|
13
|
+
},
|
|
14
|
+
clean: true,
|
|
15
|
+
},
|
|
16
|
+
resolve: {
|
|
17
|
+
extensions: ['.ts', '.js'],
|
|
18
|
+
},
|
|
19
|
+
module: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
test: /\.ts$/,
|
|
23
|
+
use: 'ts-loader',
|
|
24
|
+
exclude: /node_modules/,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
};
|