import BigNumber from 'bignumber.js';
import { TransactionReceipt, Log, EventLog } from 'web3-core';
export type Address = string;
export type Integer = BigNumber;
export type Decimal = BigNumber;
export type BigNumberable = BigNumber | string | number;
export type LogValue = string | number | boolean;
export type ParsedLogValue = BigNumber | string | number | boolean;
export const Networks = {
MAINNET: 1,
ROPSTEN: 3,
GOERLI: 5,
SEPOLIA: 11155111
};
/**
* @description The paging data params requests to get the fixed items in one page
* @typedef {Object} PagingDataParams
* @property {number?} limit The limited items per page
* @property {number?} page The index of page
*/
export interface PagingDataParams {
limit?: number;
page?: number;
}
export interface NonceResult {
status: string;
data: number;
}
export interface ServerTime {
time: string;
}
/**
* @typedef {CommonPaginateDataTypes}
* @property {T} items Generic data
* @property {number} meta.totalItems total items data
* @property {number} meta.itemsPerPage total items per page
* @property {number} meta.totalPages total page
* @property {number} meta.currentPage current page
* @property {number} links.first First link (example: http://localhost:8081/v1/collections?page=1&limit=300)
* @property {number} links.previous Previous link page (example: http://localhost:8081/v1/collections?page=1&limit=300)
* @property {number} links.next Next page (example: http://localhost:8081/v1/collections?page=2&limit=300)
* @property {number} links.last Last page (example: http://localhost:8081/v1/collections?page=10&limit=300)
*/
export interface CommonPaginateDataTypes<T> {
items: T;
meta: {
totalItems: number;
itemCount: number;
itemsPerPage: number;
totalPages: number;
currentPage: number;
totalAssetsForSale?: number;
};
links: {
first: string;
previous: string;
next: string;
last: string;
};
}
/**
* @typedef {TxResult}
* @property {string?} transactionHash The recorded transaction hash on the on-chain etherscan.
* @property {number?} transactionIndex QUANTITY - integer of the transaction's index position in the block.
* @property {string?} blockHash DATA , 32 Bytes - hash of the block where this transaction was in.
* @property {number?} blockNumber QUANTITY - block number where this transaction was in.
* @property {string?} from DATA , 20 Bytes - address of the sender
* @property {string?} to DATA, 20 Bytes - address of the receiver. null when it's a contract creation transaction.
* @property {string?} contractAddress DATA, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null.
* @property {number?} cumulativeGasUsed QUANTITY - The total amount of gas used when this transaction was executed in the block.
* @property {number?} gasUsed QUANTITY - The amount of gas used by this specific transaction alone.
* @property {Log[]?} logs Array of log objects, which this transaction generated.
* @property {number?} nonce The unique number to identify the unique on-chain transactions
* @property {boolean?} status Status of the transaction receipt
* @property {number?} gasEstimate The estimated gas and check the balance of the sender
* (to make sure that the sender has enough gas to complete the request).
* This means that even though the call doesn't consume any gas, the from address must have enough gas to execute the transaction.
* @property {number?} gas The final gas fee that user need to be charged for the on-chain transaction
* @property {Promise<TransactionReceipt>?} confirmation The promise data for transactionReceipt -
* for more informations of transactionReceipt on web3-core, you can find out in https://www.npmjs.com/package/web3-core
*/
export interface TxResult {
transactionHash?: string;
transactionIndex?: number;
blockHash?: string;
blockNumber?: number;
from?: string;
to?: string;
contractAddress?: string;
cumulativeGasUsed?: number;
gasUsed?: number;
logs?: Log[];
events?: {
[eventName: string]: EventLog;
};
nonce?: number; // non-standard field, returned only through Myria Sender service
status?: boolean;
confirmation?: Promise<TransactionReceipt>;
gasEstimate?: number;
gas?: number;
message?: string;
isNetworkTimeout?: boolean;
}
export interface StarkwareLibOptions {
ethereumNodeTimeout?: number;
}
/**
* @typedef {Object} ConfirmationType (Hash/Confirmed/Both/Simulate/Sender)
*/
export enum ConfirmationType {
Hash = 'Hash',
Confirmed = 'Confirmed',
Both = 'Both',
Simulate = 'Simulate',
Sender = 'Sender',
}
export interface TxOptions {
from?: Address | null;
value?: number | string;
}
export interface NativeSendOptions extends TxOptions {
gasPrice?: number | string;
gas?: number | string | null;
nonce?: string | number;
}
/**
* @typedef {Object} SendOptions
* @property {ConfirmationType} confirmationType Type of confirmation for on-chain transaction
*
*/
export interface SendOptions extends NativeSendOptions {
confirmations?: number;
confirmationType?: ConfirmationType;
gasMultiplier?: number;
sendGaslessTransaction?: boolean;
signatureType?: string;
enabledTimeout?: boolean;
timeout?: number;
}
export interface CallOptions extends TxOptions {
blockNumber?: number;
}
export const BASE_DECIMALS = 6;
export const ETH_DECIMALS = 18;
export enum Network {
MAINNET = 1,
GOERLI = 5,
SEPOLIA = 11155111
}
export interface SignedIntStruct {
value: string;
isPositive: boolean;
}
export interface ParsedLogArgs {
[name: string]: ParsedLogValue;
}
export interface ParsedLog extends Log {
name?: string;
args: ParsedLogArgs;
}
export interface ZeroExSwapResponse {
guaranteedPrice: string;
to: string;
data: Buffer;
value: string;
buyAmount: string;
sellAmount: string;
buyTokenAddress: string;
sellTokenAddress: string;
allowanceTarget: string;
}
export type RegisterTokenResponse = {
status: string;
data: {
assetType: string;
assetInfo: string;
tokenType: string;
quantum: string;
status: boolean;
starkKey: string;
contractAddress: string;
createdAt: number;
};
};
export type RegisterTokenParam = {
starkKey: string;
tokenType: string;
quantum: string;
tokenId: string;
contractAddress: string;
};
export interface RegisterERC20TokenRequest {
starkKey: string;
contractAddress: string;
quantum: string;
}
export interface RegisterTokenParams {
starkKey: string;
contractAddress: string;
}
export interface RegisteredTokenResponse {
assetType: string;
assetInfo: string;
tokenType: TokenType;
quantum: string;
contractAddress?: string;
tokenName?: string;
tokenSymbol?: string;
avatarUrl?: string;
status: REGISTERED_TOKEN_STATUS;
starkKey: string;
createdAt: number;
updatedAt?: number;
}
/* eslint-disable @typescript-eslint/naming-convention */
export enum REGISTERED_TOKEN_STATUS {
Pending = 'Pending',
Registered = 'Registered',
Failed = 'Failed',
}
/* eslint-enable @typescript-eslint/naming-convention */
/**
* @typedef {Object} CommonSignatureHeader
* @property {string} xSignature Signature is generated from metamask sign
* @property {string} xTimestamp Get current timestamp range
* @property {string} starkKey Stark key of requestor
* @property {string} walletAddress Wallet address of requestor
*/
export interface CommonSignatureHeader {
xSignature: string;
xTimestamp: string;
starkKey: string;
walletAddress: string;
}
/**
* @typedef {string} TokenType
* @enum {TokenType} Type of Token (ETH / ERC20 / ERC721 / MINTABLE_ERC20 / MINTABLE_ERC721)
*/
export enum TokenType {
ETH = 'ETH',
ERC20 = 'ERC20',
ERC721 = 'ERC721',
MINTABLE_ERC20 = 'MINTABLE_ERC20',
MINTABLE_ERC721 = 'MINTABLE_ERC721',
}
export type VaultForMintableERC721 = {
starkKey: string;
tokenId: string;
tokenAddress: string;
};
export type VaultForMintableERC20 = {
starkKey: string;
quantum: string;
tokenAddress: string;
tokenId?: string;
blueprint?: string;
};
export interface IDepositSignature {
ethAddress: string;
vaultId: string;
txHash: string;
amount: string;
}
export type PaginatedType<T> = {
items: Array<T>;
lastEvaluatedKey?: Record<string, unknown>;
};
export type SignatureHeaderAuthorization = {
'x-signature': string;
'x-timestamp': string;
'stark-key': string;
};
Source