-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement required calls to inscribe service for BRC20 transfer (…
…#182) * feat: implement required calls to inscribe service * feat: do full BRC-20 transfer in 1 call * fix: import/export names * fix: fee calc and utxo select * fix: type issue * feat: Add all brc-20 api calls * feat: implement 1 step transfer generator * chore: add btc functions for brc-20 transfer * chore: add brc-20 tests * oopsie * feat: added mint functions and exponential backoff for retries * chore: add unit tests for mint * fix: make arguments an object instead of multiple arguments * fix: fee calc resulting in fee higher than input * fix: tests * Add missing return types and add comment * Add transfer finalize call * AAdd finalize call to transfer script and fix tests * fix issues form merge * fix: tests
- Loading branch information
1 parent
a313525
commit d456ea3
Showing
9 changed files
with
1,082 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import axios from 'axios'; | ||
|
||
import { | ||
Brc20CostEstimateRequest, | ||
Brc20CostEstimateResponse, | ||
Brc20CreateOrderRequest, | ||
Brc20CreateOrderResponse, | ||
Brc20ExecuteOrderRequest, | ||
Brc20ExecuteOrderResponse, | ||
Brc20FinalizeTransferOrderRequest, | ||
Brc20FinalizeTransferOrderResponse, | ||
NetworkType, | ||
} from 'types'; | ||
|
||
import { XVERSE_INSCRIBE_URL } from '../constant'; | ||
|
||
const apiClient = axios.create({ | ||
baseURL: XVERSE_INSCRIBE_URL, | ||
}); | ||
|
||
const getBrc20TransferFees = async ( | ||
tick: string, | ||
amount: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CostEstimateResponse> => { | ||
const requestBody: Brc20CostEstimateRequest = { | ||
operation: 'transfer', | ||
tick, | ||
amount, | ||
revealAddress, | ||
feeRate, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CostEstimateResponse>('/v1/brc20/cost-estimate', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const createBrc20TransferOrder = async ( | ||
tick: string, | ||
amount: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
network: NetworkType, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CreateOrderResponse> => { | ||
const requestBody: Brc20CreateOrderRequest = { | ||
operation: 'transfer', | ||
tick, | ||
amount, | ||
revealAddress, | ||
feeRate, | ||
network, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CreateOrderResponse>('/v1/brc20/place-order', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const getBrc20MintFees = async ( | ||
tick: string, | ||
amount: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CostEstimateResponse> => { | ||
const requestBody: Brc20CostEstimateRequest = { | ||
operation: 'mint', | ||
tick, | ||
amount, | ||
revealAddress, | ||
feeRate, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CostEstimateResponse>('/v1/brc20/cost-estimate', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const createBrc20MintOrder = async ( | ||
tick: string, | ||
amount: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
network: NetworkType, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CreateOrderResponse> => { | ||
const requestBody: Brc20CreateOrderRequest = { | ||
operation: 'mint', | ||
tick, | ||
amount, | ||
revealAddress, | ||
feeRate, | ||
network, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CreateOrderResponse>('/v1/brc20/place-order', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const getBrc20DeployFees = async ( | ||
tick: string, | ||
max: number, | ||
limit: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CostEstimateResponse> => { | ||
const requestBody: Brc20CostEstimateRequest = { | ||
operation: 'deploy', | ||
tick, | ||
lim: limit, | ||
max: max, | ||
revealAddress, | ||
feeRate, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CostEstimateResponse>('/v1/brc20/cost-estimate', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const createBrc20DeployOrder = async ( | ||
tick: string, | ||
max: number, | ||
limit: number, | ||
revealAddress: string, | ||
feeRate: number, | ||
network: NetworkType, | ||
inscriptionValue?: number, | ||
): Promise<Brc20CreateOrderResponse> => { | ||
const requestBody: Brc20CreateOrderRequest = { | ||
operation: 'deploy', | ||
tick, | ||
lim: limit, | ||
max: max, | ||
revealAddress, | ||
feeRate, | ||
network, | ||
inscriptionValue, | ||
}; | ||
const response = await apiClient.post<Brc20CreateOrderResponse>('/v1/brc20/place-order', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const executeBrc20Order = async ( | ||
commitAddress: string, | ||
commitTransactionHex: string, | ||
skipFinalize?: boolean, | ||
): Promise<Brc20ExecuteOrderResponse> => { | ||
const requestBody: Brc20ExecuteOrderRequest = { | ||
commitAddress, | ||
commitTransactionHex, | ||
skipFinalize, | ||
}; | ||
const response = await apiClient.post<Brc20ExecuteOrderResponse>('/v1/brc20/execute-order', requestBody); | ||
return response.data; | ||
}; | ||
|
||
const finalizeBrc20TransferOrder = async ( | ||
commitAddress: string, | ||
transferTransactionHex: string, | ||
): Promise<Brc20FinalizeTransferOrderResponse> => { | ||
const requestBody: Brc20FinalizeTransferOrderRequest = { | ||
commitAddress, | ||
transferTransactionHex, | ||
}; | ||
const response = await apiClient.post<Brc20FinalizeTransferOrderResponse>('/v1/brc20/finalize-order', requestBody); | ||
return response.data; | ||
}; | ||
|
||
export default { | ||
getBrc20TransferFees, | ||
createBrc20TransferOrder, | ||
getBrc20MintFees, | ||
createBrc20MintOrder, | ||
getBrc20DeployFees, | ||
createBrc20DeployOrder, | ||
executeBrc20Order, | ||
finalizeBrc20TransferOrder, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.