@cityofzion/bs-neo3 0.7.2 → 0.8.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.
Files changed (99) hide show
  1. package/.rush/temp/operation/build/all.log +1 -0
  2. package/.rush/temp/operation/build/state.json +1 -1
  3. package/.rush/temp/package-deps_build.json +11 -7
  4. package/.rush/temp/shrinkwrap-deps.json +354 -130
  5. package/CHANGELOG.json +22 -0
  6. package/CHANGELOG.md +11 -0
  7. package/bs-neo3.build.log +1 -2
  8. package/dist/BSNeo3.d.ts +28 -27
  9. package/dist/BSNeo3.js +184 -182
  10. package/dist/DoraBDSNeo3.d.ts +12 -12
  11. package/dist/DoraBDSNeo3.js +169 -169
  12. package/dist/DoraESNeo3.d.ts +7 -0
  13. package/dist/DoraESNeo3.js +19 -0
  14. package/dist/FlamingoEDSNeo3.d.ts +8 -8
  15. package/dist/FlamingoEDSNeo3.js +45 -44
  16. package/dist/GhostMarketNDSNeo3.d.ts +10 -10
  17. package/dist/GhostMarketNDSNeo3.js +75 -75
  18. package/dist/RpcBDSNeo3.d.ts +16 -15
  19. package/dist/RpcBDSNeo3.js +153 -152
  20. package/dist/assets/tokens/common.json +14 -14
  21. package/dist/assets/tokens/mainnet.json +116 -116
  22. package/dist/constants.d.ts +7 -7
  23. package/dist/constants.js +28 -28
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +22 -22
  26. package/jest.config.ts +13 -13
  27. package/jest.setup.ts +1 -1
  28. package/package.json +33 -32
  29. package/src/BSNeo3.ts +228 -223
  30. package/src/DoraBDSNeo3.ts +180 -180
  31. package/src/DoraESNeo3.ts +19 -0
  32. package/src/FlamingoEDSNeo3.ts +47 -45
  33. package/src/GhostMarketNDSNeo3.ts +117 -117
  34. package/src/RpcBDSNeo3.ts +157 -155
  35. package/src/__tests__/BDSNeo3.spec.ts +126 -126
  36. package/src/__tests__/BSNeo3.spec.ts +142 -142
  37. package/src/__tests__/DoraESNeo3.spec.ts +23 -0
  38. package/src/__tests__/FlamingoEDSNeo3.spec.ts +48 -45
  39. package/src/__tests__/GhostMarketNDSNeo3.spec.ts +43 -43
  40. package/src/__tests__/utils/sleep.ts +1 -1
  41. package/src/assets/tokens/common.json +13 -13
  42. package/src/assets/tokens/mainnet.json +115 -115
  43. package/src/constants.ts +29 -29
  44. package/src/index.ts +6 -6
  45. package/tsconfig.build.json +4 -4
  46. package/tsconfig.json +14 -14
  47. package/dist/BDSNeo3.d.ts +0 -15
  48. package/dist/BDSNeo3.js +0 -211
  49. package/dist/assets/tokens.json +0 -128
  50. package/dist/exceptions.d.ts +0 -3
  51. package/dist/exceptions.js +0 -8
  52. package/dist/explorer/dora/DoraNeo3Responses.d.ts +0 -174
  53. package/dist/explorer/dora/DoraNeo3Responses.js +0 -3
  54. package/dist/explorer/dora/DoraNeo3Routes.d.ts +0 -6
  55. package/dist/explorer/dora/DoraNeo3Routes.js +0 -9
  56. package/dist/explorer/index.d.ts +0 -6
  57. package/dist/explorer/index.js +0 -23
  58. package/docs/.nojekyll +0 -1
  59. package/docs/assets/highlight.css +0 -22
  60. package/docs/assets/main.js +0 -58
  61. package/docs/assets/search.js +0 -1
  62. package/docs/assets/style.css +0 -1280
  63. package/docs/classes/BDSNeo3.html +0 -253
  64. package/docs/classes/BSNeo3.html +0 -442
  65. package/docs/index.html +0 -82
  66. package/docs/interfaces/DoraNeo3Abi.html +0 -78
  67. package/docs/interfaces/DoraNeo3Asset.html +0 -117
  68. package/docs/interfaces/DoraNeo3AssetState.html +0 -96
  69. package/docs/interfaces/DoraNeo3Balance.html +0 -89
  70. package/docs/interfaces/DoraNeo3ConsensusNode.html +0 -75
  71. package/docs/interfaces/DoraNeo3Contract.html +0 -110
  72. package/docs/interfaces/DoraNeo3Event.html +0 -75
  73. package/docs/interfaces/DoraNeo3Features.html +0 -84
  74. package/docs/interfaces/DoraNeo3HistoryState.html +0 -75
  75. package/docs/interfaces/DoraNeo3Invocation.html +0 -75
  76. package/docs/interfaces/DoraNeo3Item.html +0 -131
  77. package/docs/interfaces/DoraNeo3Manifest.html +0 -117
  78. package/docs/interfaces/DoraNeo3Metadata.html +0 -138
  79. package/docs/interfaces/DoraNeo3Method.html +0 -102
  80. package/docs/interfaces/DoraNeo3Nef.html +0 -103
  81. package/docs/interfaces/DoraNeo3Notification.html +0 -82
  82. package/docs/interfaces/DoraNeo3Parameter.html +0 -75
  83. package/docs/interfaces/DoraNeo3Permission.html +0 -75
  84. package/docs/interfaces/DoraNeo3Signer.html +0 -75
  85. package/docs/interfaces/DoraNeo3Token.html +0 -96
  86. package/docs/interfaces/DoraNeo3Transaction.html +0 -166
  87. package/docs/interfaces/DoraNeo3TransactionHistory.html +0 -75
  88. package/docs/interfaces/DoraNeo3Transfer.html +0 -117
  89. package/docs/interfaces/DoraNeo3Witness.html +0 -75
  90. package/docs/modules.html +0 -122
  91. package/docs/variables/DORA_ASSET.html +0 -81
  92. package/docs/variables/DORA_BALANCE.html +0 -81
  93. package/docs/variables/DORA_CONTRACT.html +0 -81
  94. package/docs/variables/DORA_NODES.html +0 -81
  95. package/docs/variables/DORA_TRANSACTION.html +0 -81
  96. package/docs/variables/DORA_TRANSACTIONS.html +0 -81
  97. package/docs/variables/explorerOptions.html +0 -86
  98. package/docs/variables/gasInfoNeo3.html +0 -90
  99. package/docs/variables/neoInfoNeo3.html +0 -90
@@ -1,180 +1,180 @@
1
- import {
2
- BalanceResponse,
3
- ContractResponse,
4
- TransactionsByAddressParams,
5
- TransactionsByAddressResponse,
6
- TransactionResponse,
7
- TransactionNotifications,
8
- Network,
9
- Token,
10
- TransactionTransferNft,
11
- TransactionTransferAsset,
12
- } from '@cityofzion/blockchain-service'
13
- import { wallet, u } from '@cityofzion/neon-js'
14
- import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
15
- import { RPCBDSNeo3 } from './RpcBDSNeo3'
16
- import { TOKENS } from './constants'
17
-
18
- const NeoRest = new NeoRESTApi({
19
- doraUrl: 'https://dora.coz.io',
20
- endpoint: '/api/v2/neo3',
21
- })
22
-
23
- export class DoraBDSNeo3 extends RPCBDSNeo3 {
24
- readonly network: Network
25
-
26
- constructor(network: Network, feeToken: Token, claimToken: Token) {
27
- if (network.type === 'custom') {
28
- throw new Error('DoraBDSNeo3 does not support custom networks')
29
- }
30
-
31
- super(network, feeToken, claimToken)
32
- this.network = network
33
- }
34
-
35
- async getTransaction(hash: string): Promise<TransactionResponse> {
36
- try {
37
- const data = await NeoRest.transaction(hash, this.network.type)
38
- return {
39
- block: data.block,
40
- time: Number(data.time),
41
- hash: data.hash,
42
- fee: u.BigInteger.fromNumber(data.netfee ?? 0)
43
- .add(u.BigInteger.fromNumber(data.sysfee ?? 0))
44
- .toDecimal(this.feeToken.decimals),
45
- notifications: [],
46
- transfers: [],
47
- }
48
- } catch {
49
- throw new Error(`Transaction not found: ${hash}`)
50
- }
51
- }
52
-
53
- async getTransactionsByAddress({
54
- address,
55
- page = 1,
56
- }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
57
- const data = await NeoRest.addressTXFull(address, page, this.network.type)
58
- const transactions = await Promise.all(
59
- data.items.map(async (item): Promise<TransactionResponse> => {
60
- const filteredTransfers = item.notifications.filter(
61
- item => item.event_name === 'Transfer' && (item.state.value.length === 3 || item.state.value.length === 4)
62
- )
63
- const transferPromises = filteredTransfers.map<Promise<TransactionTransferAsset | TransactionTransferNft>>(
64
- async ({ contract: contractHash, state: { value: properties } }) => {
65
- const isAsset = properties.length === 3
66
-
67
- const from = properties[0].value
68
- const to = properties[1].value
69
- const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint'
70
- const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn'
71
-
72
- if (isAsset) {
73
- const token = await this.getTokenInfo(contractHash)
74
- const [, , { value: amount }] = properties
75
- return {
76
- amount: u.BigInteger.fromNumber(amount).toDecimal(token.decimals ?? 0),
77
- from: convertedFrom,
78
- to: convertedTo,
79
- contractHash,
80
- type: 'token',
81
- token,
82
- }
83
- }
84
-
85
- return {
86
- from: convertedFrom,
87
- to: convertedTo,
88
- tokenId: properties[3].value,
89
- contractHash,
90
- type: 'nft',
91
- }
92
- }
93
- )
94
- const transfers = await Promise.all(transferPromises)
95
-
96
- const notifications = item.notifications.map<TransactionNotifications>(notification => ({
97
- eventName: notification.event_name,
98
- state: notification.state as any,
99
- }))
100
-
101
- return {
102
- block: item.block,
103
- time: Number(item.time),
104
- hash: item.hash,
105
- fee: u.BigInteger.fromNumber(item.netfee ?? 0)
106
- .add(u.BigInteger.fromNumber(item.sysfee ?? 0))
107
- .toDecimal(this.feeToken.decimals),
108
- transfers,
109
- notifications,
110
- }
111
- })
112
- )
113
-
114
- return {
115
- totalCount: data.totalCount,
116
- transactions,
117
- limit: 15,
118
- }
119
- }
120
-
121
- async getContract(contractHash: string): Promise<ContractResponse> {
122
- try {
123
- const data = await NeoRest.contract(contractHash, this.network.type)
124
- return {
125
- hash: data.hash,
126
- methods: data.manifest.abi?.methods ?? [],
127
- name: data.manifest.name,
128
- }
129
- } catch {
130
- throw new Error(`Contract not found: ${contractHash}`)
131
- }
132
- }
133
-
134
- async getTokenInfo(tokenHash: string): Promise<Token> {
135
- const localToken = TOKENS[this.network.type].find(token => token.hash === tokenHash)
136
- if (localToken) return localToken
137
-
138
- if (this.tokenCache.has(tokenHash)) {
139
- return this.tokenCache.get(tokenHash)!
140
- }
141
-
142
- try {
143
- const { decimals, symbol, name, scripthash } = await NeoRest.asset(tokenHash, this.network.type)
144
- const token = {
145
- decimals: Number(decimals),
146
- symbol,
147
- name,
148
- hash: scripthash,
149
- }
150
- this.tokenCache.set(tokenHash, token)
151
-
152
- return token
153
- } catch {
154
- throw new Error(`Token not found: ${tokenHash}`)
155
- }
156
- }
157
-
158
- async getBalance(address: string): Promise<BalanceResponse[]> {
159
- const response = await NeoRest.balance(address, this.network.type)
160
-
161
- const promises = response.map<Promise<BalanceResponse | undefined>>(async balance => {
162
- try {
163
- const token = await this.getTokenInfo(balance.asset)
164
- return {
165
- amount: u.BigInteger.fromNumber(balance.balance).toDecimal(token.decimals),
166
- token,
167
- }
168
- } catch {}
169
- })
170
- const balances = await Promise.all(promises)
171
- const filteredBalances = balances.filter(balance => balance !== undefined) as BalanceResponse[]
172
- return filteredBalances
173
- }
174
-
175
- private convertByteStringToAddress(byteString: string): string {
176
- const account = new wallet.Account(u.reverseHex(u.HexString.fromBase64(byteString).toString()))
177
-
178
- return account.address
179
- }
180
- }
1
+ import {
2
+ BalanceResponse,
3
+ ContractResponse,
4
+ TransactionsByAddressParams,
5
+ TransactionsByAddressResponse,
6
+ TransactionResponse,
7
+ TransactionNotifications,
8
+ Network,
9
+ Token,
10
+ TransactionTransferNft,
11
+ TransactionTransferAsset,
12
+ } from '@cityofzion/blockchain-service'
13
+ import { wallet, u } from '@cityofzion/neon-js'
14
+ import { NeoRESTApi } from '@cityofzion/dora-ts/dist/api'
15
+ import { RPCBDSNeo3 } from './RpcBDSNeo3'
16
+ import { TOKENS } from './constants'
17
+
18
+ const NeoRest = new NeoRESTApi({
19
+ doraUrl: 'https://dora.coz.io',
20
+ endpoint: '/api/v2/neo3',
21
+ })
22
+
23
+ export class DoraBDSNeo3 extends RPCBDSNeo3 {
24
+ readonly network: Network
25
+
26
+ constructor(network: Network, feeToken: Token, claimToken: Token) {
27
+ if (network.type === 'custom') {
28
+ throw new Error('DoraBDSNeo3 does not support custom networks')
29
+ }
30
+
31
+ super(network, feeToken, claimToken)
32
+ this.network = network
33
+ }
34
+
35
+ async getTransaction(hash: string): Promise<TransactionResponse> {
36
+ try {
37
+ const data = await NeoRest.transaction(hash, this.network.type)
38
+ return {
39
+ block: data.block,
40
+ time: Number(data.time),
41
+ hash: data.hash,
42
+ fee: u.BigInteger.fromNumber(data.netfee ?? 0)
43
+ .add(u.BigInteger.fromNumber(data.sysfee ?? 0))
44
+ .toDecimal(this.feeToken.decimals),
45
+ notifications: [],
46
+ transfers: [],
47
+ }
48
+ } catch {
49
+ throw new Error(`Transaction not found: ${hash}`)
50
+ }
51
+ }
52
+
53
+ async getTransactionsByAddress({
54
+ address,
55
+ page = 1,
56
+ }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
57
+ const data = await NeoRest.addressTXFull(address, page, this.network.type)
58
+ const transactions = await Promise.all(
59
+ data.items.map(async (item): Promise<TransactionResponse> => {
60
+ const filteredTransfers = item.notifications.filter(
61
+ item => item.event_name === 'Transfer' && (item.state.value.length === 3 || item.state.value.length === 4)
62
+ )
63
+ const transferPromises = filteredTransfers.map<Promise<TransactionTransferAsset | TransactionTransferNft>>(
64
+ async ({ contract: contractHash, state: { value: properties } }) => {
65
+ const isAsset = properties.length === 3
66
+
67
+ const from = properties[0].value
68
+ const to = properties[1].value
69
+ const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint'
70
+ const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn'
71
+
72
+ if (isAsset) {
73
+ const token = await this.getTokenInfo(contractHash)
74
+ const [, , { value: amount }] = properties
75
+ return {
76
+ amount: u.BigInteger.fromNumber(amount).toDecimal(token.decimals ?? 0),
77
+ from: convertedFrom,
78
+ to: convertedTo,
79
+ contractHash,
80
+ type: 'token',
81
+ token,
82
+ }
83
+ }
84
+
85
+ return {
86
+ from: convertedFrom,
87
+ to: convertedTo,
88
+ tokenId: properties[3].value,
89
+ contractHash,
90
+ type: 'nft',
91
+ }
92
+ }
93
+ )
94
+ const transfers = await Promise.all(transferPromises)
95
+
96
+ const notifications = item.notifications.map<TransactionNotifications>(notification => ({
97
+ eventName: notification.event_name,
98
+ state: notification.state as any,
99
+ }))
100
+
101
+ return {
102
+ block: item.block,
103
+ time: Number(item.time),
104
+ hash: item.hash,
105
+ fee: u.BigInteger.fromNumber(item.netfee ?? 0)
106
+ .add(u.BigInteger.fromNumber(item.sysfee ?? 0))
107
+ .toDecimal(this.feeToken.decimals),
108
+ transfers,
109
+ notifications,
110
+ }
111
+ })
112
+ )
113
+
114
+ return {
115
+ totalCount: data.totalCount,
116
+ transactions,
117
+ limit: 15,
118
+ }
119
+ }
120
+
121
+ async getContract(contractHash: string): Promise<ContractResponse> {
122
+ try {
123
+ const data = await NeoRest.contract(contractHash, this.network.type)
124
+ return {
125
+ hash: data.hash,
126
+ methods: data.manifest.abi?.methods ?? [],
127
+ name: data.manifest.name,
128
+ }
129
+ } catch {
130
+ throw new Error(`Contract not found: ${contractHash}`)
131
+ }
132
+ }
133
+
134
+ async getTokenInfo(tokenHash: string): Promise<Token> {
135
+ const localToken = TOKENS[this.network.type].find(token => token.hash === tokenHash)
136
+ if (localToken) return localToken
137
+
138
+ if (this.tokenCache.has(tokenHash)) {
139
+ return this.tokenCache.get(tokenHash)!
140
+ }
141
+
142
+ try {
143
+ const { decimals, symbol, name, scripthash } = await NeoRest.asset(tokenHash, this.network.type)
144
+ const token = {
145
+ decimals: Number(decimals),
146
+ symbol,
147
+ name,
148
+ hash: scripthash,
149
+ }
150
+ this.tokenCache.set(tokenHash, token)
151
+
152
+ return token
153
+ } catch {
154
+ throw new Error(`Token not found: ${tokenHash}`)
155
+ }
156
+ }
157
+
158
+ async getBalance(address: string): Promise<BalanceResponse[]> {
159
+ const response = await NeoRest.balance(address, this.network.type)
160
+
161
+ const promises = response.map<Promise<BalanceResponse | undefined>>(async balance => {
162
+ try {
163
+ const token = await this.getTokenInfo(balance.asset)
164
+ return {
165
+ amount: balance.balance.toString(),
166
+ token,
167
+ }
168
+ } catch {}
169
+ })
170
+ const balances = await Promise.all(promises)
171
+ const filteredBalances = balances.filter(balance => balance !== undefined) as BalanceResponse[]
172
+ return filteredBalances
173
+ }
174
+
175
+ private convertByteStringToAddress(byteString: string): string {
176
+ const account = new wallet.Account(u.reverseHex(u.HexString.fromBase64(byteString).toString()))
177
+
178
+ return account.address
179
+ }
180
+ }
@@ -0,0 +1,19 @@
1
+ import { ExplorerService, NetworkType, BuildNftUrlParams } from '@cityofzion/blockchain-service'
2
+
3
+ export class DoraESNeo3 implements ExplorerService {
4
+ private networkType: NetworkType
5
+
6
+ constructor(networkType: NetworkType) {
7
+ this.networkType = networkType
8
+ }
9
+
10
+ buildTransactionUrl(hash: string): string {
11
+ if (this.networkType === 'custom') throw new Error('DoraESNeo3 does not support custom network')
12
+ return `https://dora.coz.io/transaction/neo3/${this.networkType}/${hash}`
13
+ }
14
+
15
+ buildNftUrl({ contractHash, tokenId }: BuildNftUrlParams): string {
16
+ if (this.networkType === 'custom') throw new Error('DoraESNeo3 does not support custom network')
17
+ return `https://dora.coz.io/nft/neo3/${this.networkType}/${contractHash}/${tokenId}`
18
+ }
19
+ }
@@ -1,45 +1,47 @@
1
- import {
2
- Currency,
3
- ExchangeDataService,
4
- Network,
5
- NetworkType,
6
- TokenPricesResponse,
7
- } from '@cityofzion/blockchain-service'
8
- import axios, { AxiosInstance } from 'axios'
9
-
10
- type FlamingoTokenInfoPricesResponse = {
11
- symbol: string
12
- usd_price: number
13
- }[]
14
-
15
- export class FlamingoEDSNeo3 implements ExchangeDataService {
16
- readonly networkType: NetworkType
17
- private axiosInstance: AxiosInstance
18
-
19
- constructor(networkType: NetworkType) {
20
- this.networkType = networkType
21
- this.axiosInstance = axios.create({ baseURL: 'https://api.flamingo.finance' })
22
- }
23
-
24
- async getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]> {
25
- if (this.networkType !== 'mainnet') throw new Error('Exchange is only available on mainnet')
26
-
27
- const { data: prices } = await this.axiosInstance.get<FlamingoTokenInfoPricesResponse>('/token-info/prices')
28
-
29
- let currencyRatio: number = 1
30
-
31
- if (currency !== 'USD') {
32
- currencyRatio = await this.getCurrencyRatio(currency)
33
- }
34
-
35
- return prices.map(price => ({
36
- price: price.usd_price * currencyRatio,
37
- symbol: price.symbol,
38
- }))
39
- }
40
-
41
- private async getCurrencyRatio(currency: Currency): Promise<number> {
42
- const { data } = await this.axiosInstance.get<number>(`/fiat/exchange-rate?pair=USD_${currency}`)
43
- return data
44
- }
45
- }
1
+ import {
2
+ Currency,
3
+ ExchangeDataService,
4
+ Network,
5
+ NetworkType,
6
+ TokenPricesResponse,
7
+ } from '@cityofzion/blockchain-service'
8
+ import axios, { AxiosInstance } from 'axios'
9
+
10
+ type FlamingoTokenInfoPricesResponse = {
11
+ symbol: string
12
+ usd_price: number
13
+ hash: string
14
+ }[]
15
+
16
+ export class FlamingoEDSNeo3 implements ExchangeDataService {
17
+ readonly networkType: NetworkType
18
+ private axiosInstance: AxiosInstance
19
+
20
+ constructor(networkType: NetworkType) {
21
+ this.networkType = networkType
22
+ this.axiosInstance = axios.create({ baseURL: 'https://api.flamingo.finance' })
23
+ }
24
+
25
+ async getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]> {
26
+ if (this.networkType !== 'mainnet') throw new Error('Exchange is only available on mainnet')
27
+
28
+ const { data: prices } = await this.axiosInstance.get<FlamingoTokenInfoPricesResponse>('/token-info/prices')
29
+
30
+ let currencyRatio: number = 1
31
+
32
+ if (currency !== 'USD') {
33
+ currencyRatio = await this.getCurrencyRatio(currency)
34
+ }
35
+
36
+ return prices.map(price => ({
37
+ price: price.usd_price * currencyRatio,
38
+ symbol: price.symbol,
39
+ hash: price.hash,
40
+ }))
41
+ }
42
+
43
+ private async getCurrencyRatio(currency: Currency): Promise<number> {
44
+ const { data } = await this.axiosInstance.get<number>(`/fiat/exchange-rate?pair=USD_${currency}`)
45
+ return data
46
+ }
47
+ }