New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@thorchain/asgardex-binance

Package Overview
Dependencies
Maintainers
5
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thorchain/asgardex-binance - npm Package Compare versions

Comparing version 0.1.0 to 2.0.0

lib/types/binance-ws.d.ts

46

CHANGELOG.md

@@ -0,3 +1,49 @@

# v.2.0.0 (2020-07-20)
- BREAKING CHANGE: `getTransactions` expects `GetTxsParams` as its parameter
- Refactored implementation of `getTransactions`
- Use latest `@binance-chain/javascript-sdk@4.0.5"
- Fix `Tx` type
# v.1.0.0 (2020-05-14)
Refactors the client to be constructed with a `net` and optional `phrase`
```
import BinanceClient, { Network } from '../src/client'
...
const net = Network.MAIN
const phrase = process.env.VAULT_PHRASE
const bnbClient = new BinanceClient(net, phrase)
```
### Removal:
- init()
- initClient()
- setPrivateKey()
- removePrivateKey()
### Change:
- getClientUrl(): string -> Class-based
- getExplorerUrl(): string -> Class-based
- getPrefix(): string -> Class-based
### Add:
- setNetwork(net: Network): void
- getNetwork(): Network
- generatePhrase(): string
- setPhrase(phrase?: string): void
- validatePhrase(phrase: string): boolean
- getAddress(): string
- validateAddress(address: string): boolean
- getBalance(address?: Address): Promise<Balance>
- getTransactions(address?: string): Promise<any[]>
- vaultTx(addressTo: Address, amount: number, asset: string, memo: string): Promise<TransferResult>
- normalTx(addressTo: Address, amount: number, asset: string): Promise<TransferResult>
# v.0.1.0 (2020-04-13)
First release

84

lib/client.d.ts

@@ -1,6 +0,2 @@

import { Address, MultiTransfer, Market, Balance, Network, TransferResult } from './types/binance';
export declare const MISSING_NETWORK_ERROR: Error;
export declare const getBinanceUrl: (network: Network) => string;
export declare const getExplorerUrl: (network: Network) => string;
export declare const getPrefix: (network: Network) => string;
import { Address, MultiTransfer, Network, TransferResult, Balances, Prefix, GetTxsParams, TxPage } from './types/binance';
/**

@@ -10,11 +6,73 @@ * Interface for custom Binance client

export interface BinanceClient {
getBalance(address: Address): Promise<Balance>;
isTestnet(): boolean;
setNetwork(net: Network): BinanceClient;
getNetwork(): Network;
getClientUrl(): string;
getExplorerUrl(): string;
getPrefix(): Prefix;
setPhrase(phrase?: string): BinanceClient;
getAddress(): string;
validateAddress(address: string): boolean;
getBalance(address?: Address): Promise<Balances>;
getTransactions(params?: GetTxsParams): Promise<TxPage>;
vaultTx(addressTo: Address, amount: number, asset: string, memo: string): Promise<TransferResult>;
normalTx(addressTo: Address, amount: number, asset: string): Promise<TransferResult>;
getMarkets(limit?: number, offset?: number): Promise<any>;
multiSend(address: Address, transactions: MultiTransfer[], memo?: string): Promise<TransferResult>;
transfer(fromAddress: Address, toAddress: Address, amount: number, asset: string, memo?: string): Promise<TransferResult>;
setPrivateKey(privateKey: string): Promise<BinanceClient>;
removePrivateKey(): Promise<void>;
isValidAddress(address: Address): Promise<boolean>;
getMarkets(limit?: number, offset?: number): Promise<Market>;
}
export declare const client: (network?: Network) => Promise<BinanceClient>;
/**
* Custom Binance client
*
* @example
* ```
* import { Client as BinanceClient } from '@thorchain/asgardex-binance'
*
* # testnet (by default)
* const client = new BinanceClient('any BIP39 mnemonic')
* await client.transfer(...)
* # mainnet
* const client = await binance.client('any BIP39 mnemonic', Network.MAINNET)
* await client.transfer(...)
*
* ```
*
* @class Binance
* @implements {BinanceClient}
*/
declare class Client implements BinanceClient {
private network;
private bncClient;
private phrase;
private address;
private privateKey;
private dirtyPrivateKey;
/**
* Client has to be initialised with network type and phrase
* It will throw an error if an invalid phrase has been passed
**/
constructor(phrase: string, network?: Network);
setNetwork(network: Network): BinanceClient;
getNetwork(): Network;
getClientUrl: () => string;
getExplorerUrl: () => string;
getPrefix: () => Prefix;
static generatePhrase: () => string;
setPhrase: (phrase: string) => BinanceClient;
static validatePhrase: (phrase: string) => boolean;
private getPrivateKey;
private setPrivateKey;
getAddress: () => string;
validateAddress: (address: Address) => boolean;
getBalance: (address?: string | undefined) => Promise<Balances>;
getTransactions: (params?: GetTxsParams) => Promise<TxPage>;
vaultTx: (addressTo: Address, amount: number, asset: string, memo: string) => Promise<TransferResult>;
normalTx: (addressTo: Address, amount: number, asset: string) => Promise<TransferResult>;
getMarkets: (limit?: number, offset?: number) => Promise<never[] | {
result: any;
status: number;
}>;
multiSend: (address: Address, transactions: MultiTransfer[], memo?: string) => Promise<{
result: any;
status: number;
}>;
}
export { Client };
export * from './client';
export * from './util';
export * from './types/binance';
export * as WS from './types/binance-ws';

188

lib/types/binance.d.ts
/**
* Type definitions for Binance Chain API
* @see https://docs.binance.org/api-reference/dex-api/
*
*/
import { NETWORK_PREFIX_MAPPING } from '@binance-chain/javascript-sdk/lib/client';
/**
* Address
*/
export declare type Address = string;
/**
* Token

@@ -181,3 +191,3 @@ * @see https://docs.binance.org/api-reference/dex-api/paths.html#token

*/
tx: [Tx];
tx: Txs;
};

@@ -204,3 +214,3 @@ /**

*/
data: string;
data: string | null;
/**

@@ -213,7 +223,7 @@ * From address

*/
orderId: string;
orderId: string | null;
/**
* Time of transaction
*/
timeStamp: number;
timeStamp: string;
/**

@@ -242,4 +252,8 @@ * To address

*/
txType: string;
txType: TxType;
/**
* memo
*/
memo: string;
/**
* Value of transaction

@@ -263,5 +277,27 @@ */

*/
proposalId: string;
proposalId: string | null;
};
export declare type Txs = Tx[];
export declare type TxSide = 'RECEIVE' | 'SEND';
/**
* Type of transactions
* @see https://docs.binance.org/api-reference/dex-api/paths.html#apiv1transactions
*/
export declare type TxType = 'NEW_ORDER' | 'ISSUE_TOKEN' | 'BURN_TOKEN' | 'LIST_TOKEN' | 'CANCEL_ORDER' | 'FREEZE_TOKEN' | 'UN_FREEZE_TOKEN' | 'TRANSFER' | 'PROPOSAL' | 'VOTE' | 'MINT' | 'DEPOSIT' | 'CREATE_VALIDATOR' | 'REMOVE_VALIDATOR' | 'TIME_LOCK' | 'TIME_UNLOCK' | 'TIME_RELOCK' | 'SET_ACCOUNT_FLAG' | 'HTL_TRANSFER' | 'CLAIM_HTL' | 'DEPOSIT_HTL' | 'REFUND_HTL';
/**
* Parameters for `/api/v1/transactions` endpoint
* @see https://docs.binance.org/api-reference/dex-api/paths.html#apiv1transactions
*/
export declare type GetTxsParams = {
address?: string;
blockHeight?: number;
endTime?: number;
limit?: number;
offset?: number;
side?: TxSide;
startTime?: number;
txAsset?: string;
txType?: TxType;
};
/**
* OrderList

@@ -369,64 +405,3 @@ * @see https://docs.binance.org/api-reference/dex-api/paths.html#orderlist

};
export declare type TxHash = string;
export declare type Address = string;
export declare type Asset = {
/**
* Asset symbol
*/
a: string;
/**
* Asset value
*/
A: string;
};
export declare type Assets = Asset[];
export declare type Trade = {
/**
* Receiver address
*/
o: Address;
/**
* Asset to trade
*/
c: Assets;
};
export declare type Trades = Trade[];
export declare type TransferEventData = {
/**
* Payload name ??
*/
e: string;
/**
* ???
*/
E: number;
/**
* Tx hash
*/
H: TxHash;
/**
* Memo
*/
M: string;
/**
* Sender address
*/
f: Address;
t: Trades;
};
/**
* Payload of a transfer event
* https://docs.binance.org/api-reference/dex-api/ws-streams.html#3-transfer
*/
export declare type TransferEvent = {
/**
* Name of the event
*/
stream: string;
/**
* Event payload
*/
data?: TransferEventData;
};
/**
* Balance

@@ -453,2 +428,3 @@ * @see https://docs.binance.org/api-reference/dex-api/paths.html#balance

};
export declare type Balances = Balance[];
/**

@@ -468,77 +444,4 @@ * Result of `bncClient.transfer(...)`

};
export declare enum Network {
TESTNET = "testnet",
MAINNET = "mainnet"
}
/**
* Binance Chain Client
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#module_client.BncClient
* */
export interface BncClient {
/**
* Sets the client network (testnet or mainnet).
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientchoosenetworknetwork
*/
chooseNetwork(network: Network): void;
/**
* Initialize the client with the chain's ID. Asynchronous.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientinitchain--promise
*/
initChain(): Promise<BncClient>;
/**
* Sets the client's private key for calls made by this client.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientsetprivatekeyprivatekey-localonly--promise
*/
setPrivateKey(privateKey: string, localOnly?: boolean): Promise<BncClient>;
/**
* Validates an address.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientcheckaddressaddress-prefix--boolean
*/
checkAddress(address: Address, prefix: string): boolean;
/**
* Getter for Binance DEX url
*/
getBinanceUrl(): string;
/**
* Getter for prefix
*/
getPrefix(): string;
/**
* Validates an address.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#cryptocheckaddress--boolean
*/
isValidAddress(address: Address): boolean;
/**
* Get balances
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#clientgetbalancesbalances
*/
getBalance(address: Address): Promise<Balance>;
/**
* Get markets
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientgetmarketsoffset-limit--promise
*/
getMarkets(limit: number, offset: number): Promise<Market>;
/**
* Create and sign a multi send tx
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclientmultisendfromaddress-outputs-memo-sequence--promise
*/
multiSend(fromAddress: Address, outputs: MultiTransfer[], memo?: string, sequence?: number): Promise<TransferResult>;
/**
* Transfer tokens from one address to another.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#bncclienttransferfromaddress-toaddress-amount-asset-memo-sequence--promise
*/
transfer(fromAddress: Address, toAddress: Address, amount: number, asset: string, memo?: string, sequence?: number): Promise<TransferResult>;
/**
* crypto
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#crypto
*/
crypto: BNBCrypto;
}
declare type BNBCrypto = {
/**
* Checks whether an address is valid.
* https://github.com/binance-chain/javascript-sdk/wiki/API-Documentation#cryptocheckaddress--boolean
*/
checkAddress(address: Address, hrp: string): boolean;
};
export declare type Network = keyof typeof NETWORK_PREFIX_MAPPING;
export declare type Prefix = typeof NETWORK_PREFIX_MAPPING[Network];
export declare type MultiTransfer = {

@@ -552,2 +455,1 @@ to: Address;

};
export {};

@@ -1,2 +0,2 @@

import { TransferEventData, TransferEvent } from './types/binance';
import { Transfer } from './types/binance-ws';
/**

@@ -7,3 +7,3 @@ * Get `hash` from transfer event sent by Binance chain

export declare const getHashFromTransfer: (transfer?: {
data: Pick<TransferEventData, "H">;
data?: Pick<Transfer, "H"> | undefined;
} | undefined) => string | undefined;

@@ -13,2 +13,2 @@ /**

*/
export declare const getTxHashFromMemo: (transfer?: TransferEvent | undefined) => string | undefined;
export declare const getTxHashFromMemo: (transfer?: import("./types/binance-ws").WSEvent<Transfer> | undefined) => string | undefined;
{
"name": "@thorchain/asgardex-binance",
"version": "0.1.0",
"version": "2.0.0",
"description": "Custom Binance client and utilities used by ASGARDEX clients",

@@ -11,3 +11,3 @@ "keywords": [

"author": "THORChain",
"homepage": "https://gitlab.com/thorchain/bepswap/asgardex-common",
"homepage": "https://gitlab.com/thorchain/asgardex-common/asgardex-binance",
"license": "MIT",

@@ -26,3 +26,3 @@ "main": "lib/index.js",

"type": "git",
"url": "git@gitlab.com:thorchain/bepswap/asgardex-common.git"
"url": "git@gitlab.com:thorchain/asgardex-common/asgardex-binance.git"
},

@@ -33,9 +33,27 @@ "scripts": {

"test": "jest",
"lint": "eslint \"{src,__tests__}/**/*.ts\" --fix",
"prepublishOnly": "yarn build"
},
"peerDependencies": {
"@binance-chain/javascript-sdk": "2.x"
},
"devDependencies": {
"@binance-chain/javascript-sdk": "^2.16.4"
"@binance-chain/javascript-sdk": "^4.0.5",
"@types/jest": "^25.2.3",
"@typescript-eslint/eslint-plugin": "^3.0.1",
"@typescript-eslint/parser": "^3.0.1",
"dotenv": "^8.2.0",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.6",
"prettier": "^2.0.5",
"rollup": "2.10.9",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.2",
"rollup-plugin-typescript2": "^0.27.1",
"ts-jest": "^26.0.0",
"tslib": "^2.0.0",
"typescript": "^3.9.3"
},

@@ -45,3 +63,5 @@ "publishConfig": {

},
"gitHead": "26721f57fb6c70554ac34255e6f8e947b768d4cd"
"peerDependencies": {
"@binance-chain/javascript-sdk": "^4.05"
}
}
# `@thorchain/asgardex-binance`
Binance Module for ASGARDEX Clients
## Modules
- `client` - Custom client for communicating with Binance Chain by using [`binance-chain/javascript-sdk`](https://github.com/binance-chain/javascript-sdk)
- `types` - TypeScript type definitions for [`binance-chain/javascript-sdk`](https://github.com/binance-chain/javascript-sdk) (not completed).
- `types` - TypeScript type definitions for [`binance-chain/javascript-sdk`](https://github.com/binance-chain/javascript-sdk) (not completed) and [`Binance WebSocket Streams`](https://docs.binance.org/api-reference/dex-api/ws-streams.html).
- `util` - Utitilies for using [`binance-chain/javascript-sdk`](https://github.com/binance-chain/javascript-sdk)

@@ -8,0 +10,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc