Skip to content

Commit

Permalink
feat: implement required calls to inscribe service for BRC20 transfer (
Browse files Browse the repository at this point in the history
…#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
victorkirov authored Aug 8, 2023
1 parent a313525 commit d456ea3
Show file tree
Hide file tree
Showing 9 changed files with 1,082 additions and 41 deletions.
180 changes: 180 additions & 0 deletions api/xverseInscribe.ts
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,
};
2 changes: 2 additions & 0 deletions constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const NFT_BASE_URI = 'https://stacks.gamma.io/api/v1/collections';

export const XVERSE_API_BASE_URL = 'https://api.xverse.app';

export const XVERSE_INSCRIBE_URL = 'https://inscribe.xverse.app';

export const XVERSE_SPONSOR_URL = 'https://sponsor.xverse.app';

export const GAIA_HUB_URL = 'https://hub.blockstack.org';
Expand Down
Loading

0 comments on commit d456ea3

Please sign in to comment.