@cityofzion/bs-neo3 0.7.3 → 0.9.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/.rush/temp/operation/build/all.log +1 -0
- package/.rush/temp/operation/build/state.json +1 -1
- package/.rush/temp/package-deps_build.json +9 -7
- package/.rush/temp/shrinkwrap-deps.json +354 -130
- package/CHANGELOG.json +22 -0
- package/CHANGELOG.md +11 -0
- package/bs-neo3.build.log +1 -2
- package/dist/BSNeo3.d.ts +29 -28
- package/dist/BSNeo3.js +187 -184
- package/dist/DoraBDSNeo3.d.ts +12 -12
- package/dist/DoraBDSNeo3.js +169 -169
- package/dist/DoraESNeo3.d.ts +7 -7
- package/dist/DoraESNeo3.js +19 -19
- package/dist/FlamingoEDSNeo3.d.ts +8 -8
- package/dist/FlamingoEDSNeo3.js +45 -44
- package/dist/GhostMarketNDSNeo3.d.ts +10 -10
- package/dist/GhostMarketNDSNeo3.js +75 -75
- package/dist/RpcBDSNeo3.d.ts +16 -16
- package/dist/RpcBDSNeo3.js +153 -153
- package/dist/assets/tokens/common.json +14 -14
- package/dist/assets/tokens/mainnet.json +116 -116
- package/dist/constants.d.ts +7 -7
- package/dist/constants.js +28 -28
- package/dist/index.d.ts +6 -6
- package/dist/index.js +22 -22
- package/jest.config.ts +13 -13
- package/jest.setup.ts +1 -1
- package/package.json +33 -32
- package/src/BSNeo3.ts +232 -228
- package/src/DoraBDSNeo3.ts +180 -180
- package/src/DoraESNeo3.ts +19 -19
- package/src/FlamingoEDSNeo3.ts +47 -45
- package/src/GhostMarketNDSNeo3.ts +117 -117
- package/src/RpcBDSNeo3.ts +157 -157
- package/src/__tests__/BDSNeo3.spec.ts +126 -126
- package/src/__tests__/BSNeo3.spec.ts +150 -142
- package/src/__tests__/DoraESNeo3.spec.ts +23 -23
- package/src/__tests__/FlamingoEDSNeo3.spec.ts +48 -45
- package/src/__tests__/GhostMarketNDSNeo3.spec.ts +43 -43
- package/src/__tests__/utils/sleep.ts +1 -1
- package/src/assets/tokens/common.json +13 -13
- package/src/assets/tokens/mainnet.json +115 -115
- package/src/constants.ts +29 -29
- package/src/index.ts +6 -6
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +14 -14
- package/dist/BDSNeo3.d.ts +0 -15
- package/dist/BDSNeo3.js +0 -211
- package/dist/assets/tokens.json +0 -128
- package/dist/exceptions.d.ts +0 -3
- package/dist/exceptions.js +0 -8
- package/dist/explorer/dora/DoraNeo3Responses.d.ts +0 -174
- package/dist/explorer/dora/DoraNeo3Responses.js +0 -3
- package/dist/explorer/dora/DoraNeo3Routes.d.ts +0 -6
- package/dist/explorer/dora/DoraNeo3Routes.js +0 -9
- package/dist/explorer/index.d.ts +0 -6
- package/dist/explorer/index.js +0 -23
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -22
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1280
- package/docs/classes/BDSNeo3.html +0 -253
- package/docs/classes/BSNeo3.html +0 -442
- package/docs/index.html +0 -82
- package/docs/interfaces/DoraNeo3Abi.html +0 -78
- package/docs/interfaces/DoraNeo3Asset.html +0 -117
- package/docs/interfaces/DoraNeo3AssetState.html +0 -96
- package/docs/interfaces/DoraNeo3Balance.html +0 -89
- package/docs/interfaces/DoraNeo3ConsensusNode.html +0 -75
- package/docs/interfaces/DoraNeo3Contract.html +0 -110
- package/docs/interfaces/DoraNeo3Event.html +0 -75
- package/docs/interfaces/DoraNeo3Features.html +0 -84
- package/docs/interfaces/DoraNeo3HistoryState.html +0 -75
- package/docs/interfaces/DoraNeo3Invocation.html +0 -75
- package/docs/interfaces/DoraNeo3Item.html +0 -131
- package/docs/interfaces/DoraNeo3Manifest.html +0 -117
- package/docs/interfaces/DoraNeo3Metadata.html +0 -138
- package/docs/interfaces/DoraNeo3Method.html +0 -102
- package/docs/interfaces/DoraNeo3Nef.html +0 -103
- package/docs/interfaces/DoraNeo3Notification.html +0 -82
- package/docs/interfaces/DoraNeo3Parameter.html +0 -75
- package/docs/interfaces/DoraNeo3Permission.html +0 -75
- package/docs/interfaces/DoraNeo3Signer.html +0 -75
- package/docs/interfaces/DoraNeo3Token.html +0 -96
- package/docs/interfaces/DoraNeo3Transaction.html +0 -166
- package/docs/interfaces/DoraNeo3TransactionHistory.html +0 -75
- package/docs/interfaces/DoraNeo3Transfer.html +0 -117
- package/docs/interfaces/DoraNeo3Witness.html +0 -75
- package/docs/modules.html +0 -122
- package/docs/variables/DORA_ASSET.html +0 -81
- package/docs/variables/DORA_BALANCE.html +0 -81
- package/docs/variables/DORA_CONTRACT.html +0 -81
- package/docs/variables/DORA_NODES.html +0 -81
- package/docs/variables/DORA_TRANSACTION.html +0 -81
- package/docs/variables/DORA_TRANSACTIONS.html +0 -81
- package/docs/variables/explorerOptions.html +0 -86
- package/docs/variables/gasInfoNeo3.html +0 -90
- package/docs/variables/neoInfoNeo3.html +0 -90
package/src/DoraBDSNeo3.ts
CHANGED
|
@@ -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:
|
|
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
|
+
}
|
package/src/DoraESNeo3.ts
CHANGED
|
@@ -1,19 +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
|
+
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
|
+
}
|
package/src/FlamingoEDSNeo3.ts
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|