-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: use exotics api v2 #298
Changes from 4 commits
fcdf2ca
4d51d95
82304c7
e18144f
2090b0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,14 +4,24 @@ | |||||
import { INSCRIPTION_REQUESTS_SERVICE_URL, ORDINALS_URL, XVERSE_API_BASE_URL, XVERSE_INSCRIBE_URL } from '../constant'; | ||||||
import { | ||||||
Account, | ||||||
AddressBundleResponse, | ||||||
Brc20HistoryTransactionData, | ||||||
BtcOrdinal, | ||||||
Bundle, | ||||||
BundleSatRange, | ||||||
FungibleToken, | ||||||
HiroApiBrc20TxHistoryResponse, | ||||||
Inscription, | ||||||
InscriptionRequestResponse, | ||||||
NetworkType, | ||||||
RareSatsType, | ||||||
RodarmorRareSats, | ||||||
RodarmorRareSatsType, | ||||||
SatRangeInscription, | ||||||
Satributes, | ||||||
SatributesType, | ||||||
UTXO, | ||||||
UtxoBundleResponse, | ||||||
UtxoOrdinalBundle, | ||||||
} from '../types'; | ||||||
import { parseBrc20TransactionData } from './helper'; | ||||||
|
@@ -101,8 +111,8 @@ | |||||
timeout: 30000, | ||||||
transformResponse: [(data) => parseOrdinalTextContentData(data)], | ||||||
}) | ||||||
.then((response) => response!.data) | ||||||
.catch((error) => { | ||||||
return ''; | ||||||
}); | ||||||
} | ||||||
|
@@ -132,9 +142,9 @@ | |||||
}) | ||||||
.then((response) => { | ||||||
if (response.data) { | ||||||
const responseTokensList = response!.data; | ||||||
const tokensList: Array<FungibleToken> = []; | ||||||
responseTokensList.forEach((responseToken: any) => { | ||||||
const token: FungibleToken = { | ||||||
name: responseToken.ticker, | ||||||
balance: responseToken.overallBalance, | ||||||
|
@@ -157,7 +167,7 @@ | |||||
return []; | ||||||
} | ||||||
}) | ||||||
.catch((error) => { | ||||||
return []; | ||||||
}); | ||||||
} | ||||||
|
@@ -216,12 +226,6 @@ | |||||
export const isOrdinalOwnedByAccount = (inscription: Inscription, account: Account) => | ||||||
inscription.address === account.ordinalsAddress; | ||||||
|
||||||
export type AddressBundleResponse = { | ||||||
total: number; | ||||||
offset: number; | ||||||
limit: number; | ||||||
results: UtxoOrdinalBundle[]; | ||||||
}; | ||||||
export const getAddressUtxoOrdinalBundles = async ( | ||||||
network: NetworkType, | ||||||
address: string, | ||||||
|
@@ -247,7 +251,7 @@ | |||||
} | ||||||
|
||||||
const response = await axios.get<AddressBundleResponse>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v1/address/${address}/ordinal-utxo`, | ||||||
`${XVERSE_API_BASE_URL(network)}/v2/address/${address}/ordinal-utxo`, | ||||||
{ | ||||||
params, | ||||||
}, | ||||||
|
@@ -260,9 +264,106 @@ | |||||
network: NetworkType, | ||||||
txid: string, | ||||||
vout: number, | ||||||
): Promise<UtxoOrdinalBundle> => { | ||||||
const response = await axios.get<UtxoOrdinalBundle>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v1/ordinal-utxo/${txid}:${vout}`, | ||||||
): Promise<UtxoBundleResponse> => { | ||||||
const response = await axios.get<UtxoBundleResponse>( | ||||||
`${XVERSE_API_BASE_URL(network)}/v2/ordinal-utxo/${txid}:${vout}`, | ||||||
); | ||||||
return response.data; | ||||||
}; | ||||||
|
||||||
export const mapRareSatsAPIResponseToBundle = (apiBundle: UtxoOrdinalBundle): Bundle => { | ||||||
const generalBundleInfo = { | ||||||
txid: apiBundle.txid, | ||||||
vout: apiBundle.vout, | ||||||
block_height: apiBundle.block_height, | ||||||
value: apiBundle.value, | ||||||
}; | ||||||
|
||||||
const commonUnknownRange: BundleSatRange = { | ||||||
range: { | ||||||
start: '0', | ||||||
end: '0', | ||||||
}, | ||||||
yearMined: 0, | ||||||
block: 0, | ||||||
offset: 0, | ||||||
satributes: ['COMMON'], | ||||||
inscriptions: [], | ||||||
totalSats: apiBundle.value, | ||||||
}; | ||||||
|
||||||
// if bundle has and empty sat ranges, it means that it's a common/unknown bundle | ||||||
if (!apiBundle.sat_ranges.length) { | ||||||
return { | ||||||
...generalBundleInfo, | ||||||
satRanges: [commonUnknownRange], | ||||||
inscriptions: [], | ||||||
satributes: [['COMMON']], | ||||||
totalExoticSats: 0, | ||||||
}; | ||||||
} | ||||||
|
||||||
let totalExoticSats = 0; | ||||||
let totalCommonUnknownInscribedSats = 0; | ||||||
const satRanges: BundleSatRange[] = []; | ||||||
|
||||||
apiBundle.sat_ranges.forEach((satRange) => { | ||||||
const { year_mined: yearMined, ...satRangeProps } = satRange; | ||||||
|
||||||
// filter out unsupported satributes | ||||||
const supportedSatributes = satRange.satributes.filter( | ||||||
(satribute) => | ||||||
RodarmorRareSats.includes(satribute as RodarmorRareSatsType) || | ||||||
Satributes.includes(satribute as SatributesType), | ||||||
); | ||||||
|
||||||
const rangeWithUnsupportedSatsAndWithoutInscriptions = | ||||||
satRange.satributes.length === 1 && !satRange.inscriptions.length && !supportedSatributes.length; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be
Suggested change
|
||||||
// if range has no inscriptions and only unsupported satributes, we skip it | ||||||
if (rangeWithUnsupportedSatsAndWithoutInscriptions) { | ||||||
return; | ||||||
} | ||||||
victorkirov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
// if range has inscribed sats of unsupported type or unknown, we map it to a common/unknown sat range | ||||||
const satributes = !supportedSatributes.length ? (['COMMON'] as RareSatsType[]) : supportedSatributes; | ||||||
|
||||||
const totalSats = Number(BigInt(satRange.range.end) - BigInt(satRange.range.start)); | ||||||
|
||||||
if (satributes.includes('COMMON')) { | ||||||
totalCommonUnknownInscribedSats += totalSats; | ||||||
} else { | ||||||
totalExoticSats += totalSats; | ||||||
} | ||||||
|
||||||
const range = { | ||||||
...satRangeProps, | ||||||
totalSats, | ||||||
yearMined, | ||||||
satributes, | ||||||
// only one inscription per range is supported | ||||||
inscriptions: satRange.inscriptions.length > 1 ? [satRange.inscriptions[0]] : satRange.inscriptions, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we only support one? π |
||||||
}; | ||||||
|
||||||
satRanges.push(range); | ||||||
}); | ||||||
|
||||||
// if totalExoticSats doesn't match the value of the bundle, | ||||||
// it means that the bundle is not fully exotic and we need to add a common unknown sat range | ||||||
if (totalExoticSats !== apiBundle.value) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
satRanges.push({ | ||||||
...commonUnknownRange, | ||||||
totalSats: apiBundle.value - (totalExoticSats + totalCommonUnknownInscribedSats), | ||||||
}); | ||||||
} | ||||||
|
||||||
const inscriptions = satRanges.reduce((acc, curr) => [...acc, ...curr.inscriptions], [] as SatRangeInscription[]); | ||||||
const satributes = satRanges.reduce((acc, curr) => [...acc, curr.satributes], [] as RareSatsType[][]); | ||||||
|
||||||
return { | ||||||
...generalBundleInfo, | ||||||
satRanges, | ||||||
inscriptions, | ||||||
satributes, | ||||||
totalExoticSats, | ||||||
}; | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit π