@proton/wrap-constants 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coins.d.ts +42 -9
- package/dist/constants.d.ts +10 -0
- package/dist/graph.d.ts +30 -0
- package/dist/index.d.ts +2 -0
- package/dist/math.d.ts +17 -0
- package/dist/parsers/actions.d.ts +1323 -0
- package/dist/parsers/address.d.ts +932 -0
- package/dist/parsers/auth.d.ts +1816 -0
- package/dist/parsers/base.d.ts +35 -0
- package/dist/parsers/currency.d.ts +236 -0
- package/dist/parsers/deposit.d.ts +63 -0
- package/dist/parsers/dex.d.ts +508 -0
- package/dist/parsers/index.d.ts +12 -0
- package/dist/parsers/otc.d.ts +46 -0
- package/dist/parsers/pool.d.ts +51 -0
- package/dist/parsers/withdraw.d.ts +1053 -0
- package/dist/parsers/withdrawalHistory.d.ts +98 -0
- package/dist/parsers/wrap.d.ts +109 -0
- package/dist/utils.d.ts +1 -0
- package/dist/wrap-constants.cjs.development.js +1325 -310
- package/dist/wrap-constants.cjs.development.js.map +1 -1
- package/dist/wrap-constants.cjs.production.min.js +1 -1
- package/dist/wrap-constants.cjs.production.min.js.map +1 -1
- package/dist/wrap-constants.esm.js +1303 -311
- package/dist/wrap-constants.esm.js.map +1 -1
- package/package.json +14 -8
- package/src/coins.ts +563 -149
- package/src/constants.ts +41 -14
- package/src/graph.ts +126 -0
- package/src/index.ts +3 -1
- package/src/math.ts +112 -0
- package/src/parsers/actions.ts +82 -0
- package/src/parsers/address.ts +27 -0
- package/src/parsers/auth.ts +22 -0
- package/src/parsers/base.ts +18 -0
- package/src/parsers/currency.ts +89 -0
- package/src/parsers/deposit.ts +30 -0
- package/src/parsers/dex.ts +167 -0
- package/src/parsers/index.ts +12 -0
- package/src/parsers/otc.ts +23 -0
- package/src/parsers/pool.ts +51 -0
- package/src/parsers/withdraw.ts +39 -0
- package/src/parsers/withdrawalHistory.ts +23 -0
- package/src/parsers/wrap.ts +41 -0
- package/src/utils.ts +12 -1
- package/dist/parsers.d.ts +0 -849
- package/dist/pools.d.ts +0 -31
- package/src/parsers.ts +0 -258
- package/src/pools.ts +0 -26
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { ExtendedAsset, ExtendedSymbol } from '@bloks/numbers';
|
|
2
|
+
import { createZodDto } from 'nestjs-zod';
|
|
3
|
+
import { z } from 'nestjs-zod/z';
|
|
4
|
+
|
|
5
|
+
const numTransform = z.string().regex(/\d+/).transform(Number)
|
|
6
|
+
|
|
7
|
+
const ohlcvParser = z.object({
|
|
8
|
+
time: z.number(),
|
|
9
|
+
open: z.number(),
|
|
10
|
+
high: z.number(),
|
|
11
|
+
low: z.number(),
|
|
12
|
+
close: z.number(),
|
|
13
|
+
volume: z.number(),
|
|
14
|
+
volume_bid: z.number(),
|
|
15
|
+
count: z.number()
|
|
16
|
+
})
|
|
17
|
+
export type OHLCV = z.infer<typeof ohlcvParser>
|
|
18
|
+
export class OHLCV_DTO extends createZodDto(ohlcvParser) {}
|
|
19
|
+
|
|
20
|
+
const getOhlcvParser = z.object({
|
|
21
|
+
interval: z.string(),
|
|
22
|
+
dateFrom: z.string(),
|
|
23
|
+
dateTo: z.string(),
|
|
24
|
+
marketId: z.number().or(numTransform),
|
|
25
|
+
limit: z.number().or(numTransform).default(500).refine(n => n <= 1000, 'Max limit is 1000'),
|
|
26
|
+
})
|
|
27
|
+
export type GetOHLCV = z.infer<typeof getOhlcvParser>
|
|
28
|
+
export class GetOHLCV_DTO extends createZodDto(getOhlcvParser) {}
|
|
29
|
+
|
|
30
|
+
const orderHistoryParser = z.object({
|
|
31
|
+
seq: z.number(),
|
|
32
|
+
block_num: z.number(),
|
|
33
|
+
block_time: z.string(),
|
|
34
|
+
order_id: z.number(),
|
|
35
|
+
market_id: z.number(),
|
|
36
|
+
quantity_init: z.number().optional(),
|
|
37
|
+
quantity_curr: z.number(),
|
|
38
|
+
price: z.number(),
|
|
39
|
+
account_name: z.string(),
|
|
40
|
+
order_side: z.number(),
|
|
41
|
+
order_type: z.number(),
|
|
42
|
+
status: z.string(),
|
|
43
|
+
quantity_change: z.number(),
|
|
44
|
+
trx_id: z.string(),
|
|
45
|
+
})
|
|
46
|
+
export type OrderHistory = z.infer<typeof orderHistoryParser>
|
|
47
|
+
export class OrderHistory_DTO extends createZodDto(orderHistoryParser) {}
|
|
48
|
+
|
|
49
|
+
const getOrderHistoryParser = z.object({
|
|
50
|
+
account: z.string(),
|
|
51
|
+
offset: z.number().or(numTransform).default(0),
|
|
52
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
53
|
+
})
|
|
54
|
+
export type GetOrderHistory = z.infer<typeof getOrderHistoryParser>
|
|
55
|
+
export class GetOrderHistory_DTO extends createZodDto(getOrderHistoryParser) {}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
const depthParser = z.object({
|
|
59
|
+
level: z.number(),
|
|
60
|
+
ask: z.number(),
|
|
61
|
+
bid: z.number(),
|
|
62
|
+
count: z.number(),
|
|
63
|
+
})
|
|
64
|
+
export type Depth = z.infer<typeof depthParser>
|
|
65
|
+
export class Depth_DTO extends createZodDto(depthParser) {}
|
|
66
|
+
|
|
67
|
+
const getDepthParser = z.object({
|
|
68
|
+
marketId: z.number(),
|
|
69
|
+
step: z.string(),
|
|
70
|
+
side: z.string(),
|
|
71
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
72
|
+
})
|
|
73
|
+
export type GetDepth = z.infer<typeof getDepthParser>
|
|
74
|
+
export class GetDepth_DTO extends createZodDto(getDepthParser) {}
|
|
75
|
+
|
|
76
|
+
const tradeParser = z.object({
|
|
77
|
+
block_num: z.number(),
|
|
78
|
+
block_time: z.string(),
|
|
79
|
+
trade_id: z.number(),
|
|
80
|
+
market_id: z.number(),
|
|
81
|
+
price: z.number(),
|
|
82
|
+
bid_user: z.string(),
|
|
83
|
+
bid_user_order_id: z.number(),
|
|
84
|
+
bid_amount: z.number(),
|
|
85
|
+
bid_fee: z.number(),
|
|
86
|
+
ask_user: z.string(),
|
|
87
|
+
ask_user_order_id: z.number(),
|
|
88
|
+
ask_amount: z.number(),
|
|
89
|
+
ask_fee: z.number(),
|
|
90
|
+
order_side: z.number(),
|
|
91
|
+
trx_id: z.string(),
|
|
92
|
+
})
|
|
93
|
+
export type Trade = z.infer<typeof tradeParser>
|
|
94
|
+
export class Trade_DTO extends createZodDto(tradeParser) {}
|
|
95
|
+
|
|
96
|
+
const getTradesParser = z.object({
|
|
97
|
+
marketId: z.number().or(numTransform),
|
|
98
|
+
offset: z.number().or(numTransform).default(0),
|
|
99
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
export type GetTrades = z.infer<typeof getTradesParser>
|
|
103
|
+
export class GetTrades_DTO extends createZodDto(getTradesParser) {}
|
|
104
|
+
|
|
105
|
+
const syncParser = z.object({
|
|
106
|
+
sourceid: z.number(),
|
|
107
|
+
block_num: z.string(),
|
|
108
|
+
block_time: z.string(),
|
|
109
|
+
irreversible: z.string(),
|
|
110
|
+
is_master: z.number(),
|
|
111
|
+
last_updated: z.string(),
|
|
112
|
+
})
|
|
113
|
+
export type Sync = z.infer<typeof syncParser>
|
|
114
|
+
|
|
115
|
+
export enum orderType { INVALID = 0, MARKET = 1, LIMIT = 2, STOPLOSS = 3, TAKEPROFIT = 4 }
|
|
116
|
+
|
|
117
|
+
export enum orderSide { INVALID = 0, BUY = 1, SELL = 2 }
|
|
118
|
+
|
|
119
|
+
export enum logStatus {
|
|
120
|
+
CREATE = "create",
|
|
121
|
+
UPDATE = "update",
|
|
122
|
+
TRANSFER = "transfer",
|
|
123
|
+
CANCEL = "cancel",
|
|
124
|
+
DELETE = "delete",
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface CurrentOrder {
|
|
128
|
+
order_id: number
|
|
129
|
+
market_id: number
|
|
130
|
+
quantity_init: number
|
|
131
|
+
quantity_curr: number
|
|
132
|
+
price: number
|
|
133
|
+
account_name: string
|
|
134
|
+
order_side: number
|
|
135
|
+
order_type: number
|
|
136
|
+
status: string
|
|
137
|
+
created_at: string
|
|
138
|
+
updated_at: string
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface RawMarket {
|
|
142
|
+
market_id: number
|
|
143
|
+
order_min: number
|
|
144
|
+
status_code: number
|
|
145
|
+
maker_fee: number
|
|
146
|
+
taker_fee: number
|
|
147
|
+
bid_token: {
|
|
148
|
+
sym: string
|
|
149
|
+
contract: string
|
|
150
|
+
}
|
|
151
|
+
ask_token: {
|
|
152
|
+
quantity: string
|
|
153
|
+
contract: string
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface Market {
|
|
158
|
+
market_id: number
|
|
159
|
+
order_min: number
|
|
160
|
+
status_code: number
|
|
161
|
+
maker_fee: number
|
|
162
|
+
taker_fee: number
|
|
163
|
+
bid_token: ExtendedSymbol
|
|
164
|
+
ask_token: ExtendedAsset
|
|
165
|
+
bid_multiplier: number
|
|
166
|
+
ask_multiplier: number
|
|
167
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './actions'
|
|
2
|
+
export * from './address'
|
|
3
|
+
export * from './auth'
|
|
4
|
+
export * from './base'
|
|
5
|
+
export * from './currency'
|
|
6
|
+
export * from './deposit'
|
|
7
|
+
export * from './otc'
|
|
8
|
+
export * from './pool'
|
|
9
|
+
export * from './withdraw'
|
|
10
|
+
export * from './withdrawalHistory'
|
|
11
|
+
export * from './wrap'
|
|
12
|
+
export * from './dex'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'nestjs-zod/z'
|
|
2
|
+
|
|
3
|
+
export const otcOrderResponseParser = z.object({
|
|
4
|
+
success : z.boolean(),
|
|
5
|
+
transaction_id: z.string(),
|
|
6
|
+
errormsg : z.string().optional()
|
|
7
|
+
})
|
|
8
|
+
export type OtcOrderResponse = z.infer<typeof otcOrderResponseParser>
|
|
9
|
+
|
|
10
|
+
export const otcQuoteBodyParser = z.object({
|
|
11
|
+
baseAmount : z.number(),
|
|
12
|
+
baseSymbol : z.string(),
|
|
13
|
+
quoteSymbol: z.string()
|
|
14
|
+
})
|
|
15
|
+
export type OtcQuoteBody = z.infer<typeof otcQuoteBodyParser>
|
|
16
|
+
|
|
17
|
+
export const otcQuoteResponseParser = z.object({
|
|
18
|
+
success : z.boolean(),
|
|
19
|
+
token : z.string(),
|
|
20
|
+
qty : z.number(),
|
|
21
|
+
errormsg: z.string().optional()
|
|
22
|
+
})
|
|
23
|
+
export type OtcQuoteResponse = z.infer<typeof otcQuoteResponseParser>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Coin } from "../coins"
|
|
2
|
+
import { ExtendedAsset } from '@bloks/numbers'
|
|
3
|
+
import { INode } from "../graph";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface RawPool {
|
|
7
|
+
lt_symbol: string;
|
|
8
|
+
creator: string;
|
|
9
|
+
memo: string;
|
|
10
|
+
pool1: {
|
|
11
|
+
quantity: string;
|
|
12
|
+
contract: string;
|
|
13
|
+
};
|
|
14
|
+
pool2: {
|
|
15
|
+
quantity: string;
|
|
16
|
+
contract: string;
|
|
17
|
+
};
|
|
18
|
+
hash: string;
|
|
19
|
+
fee: {
|
|
20
|
+
exchange_fee: number;
|
|
21
|
+
add_liquidity_fee: number;
|
|
22
|
+
remove_liquidity_fee: number;
|
|
23
|
+
};
|
|
24
|
+
active: boolean;
|
|
25
|
+
amplifier: number;
|
|
26
|
+
}
|
|
27
|
+
export interface Pool extends Omit<RawPool, 'pool1'|'pool2'> {
|
|
28
|
+
lt_symbol: string;
|
|
29
|
+
creator: string;
|
|
30
|
+
memo: string;
|
|
31
|
+
pool1: ExtendedTokenWithRate;
|
|
32
|
+
pool2: ExtendedTokenWithRate;
|
|
33
|
+
hash: string;
|
|
34
|
+
fee: {
|
|
35
|
+
exchange_fee: number;
|
|
36
|
+
add_liquidity_fee: number;
|
|
37
|
+
remove_liquidity_fee: number;
|
|
38
|
+
};
|
|
39
|
+
liquidityUsd: number;
|
|
40
|
+
liquidityApr: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ExtendedToken = Coin & ExtendedAsset & { key: string; }
|
|
44
|
+
export type ExtendedTokenWithRate = ExtendedToken & { rate: number; }
|
|
45
|
+
|
|
46
|
+
export type PoolTable = {
|
|
47
|
+
pool1: ExtendedTokenWithRate;
|
|
48
|
+
pool2: ExtendedTokenWithRate;
|
|
49
|
+
path: INode<Pool>[];
|
|
50
|
+
getPathString: () => string;
|
|
51
|
+
} | undefined
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'nestjs-zod/z'
|
|
2
|
+
import { singleActionTransactionParser } from './actions'
|
|
3
|
+
import { authorizationParser } from './base'
|
|
4
|
+
import { WRAP_CONTRACT } from '../constants'
|
|
5
|
+
import { baseActionParser } from './actions'
|
|
6
|
+
|
|
7
|
+
const withdrawData = {
|
|
8
|
+
from: z.string().refine((val) => val !== WRAP_CONTRACT, {
|
|
9
|
+
message: `${WRAP_CONTRACT} must be receiver`,
|
|
10
|
+
}),
|
|
11
|
+
to: z.literal(WRAP_CONTRACT),
|
|
12
|
+
quantity: z.string(),
|
|
13
|
+
memo: z.string()
|
|
14
|
+
}
|
|
15
|
+
const withdrawBodyBaseAction = baseActionParser('*', 'transfer', withdrawData)
|
|
16
|
+
export type WithdrawBodyBaseAction = z.infer<typeof withdrawBodyBaseAction>
|
|
17
|
+
|
|
18
|
+
export const withdrawBodyParser = z.object({
|
|
19
|
+
signer : authorizationParser,
|
|
20
|
+
signatures : z.array(z.string()).length(1),
|
|
21
|
+
transaction: singleActionTransactionParser('*', 'transfer', withdrawData),
|
|
22
|
+
quoteId: z.string(),
|
|
23
|
+
provider: z.string().optional()
|
|
24
|
+
})
|
|
25
|
+
export type WithdrawBody = z.infer<typeof withdrawBodyParser>
|
|
26
|
+
|
|
27
|
+
export const withdrawMetalResponseParser = z.object({
|
|
28
|
+
success: z.boolean(),
|
|
29
|
+
id : z.string(),
|
|
30
|
+
})
|
|
31
|
+
export type WithdrawMetalResponse = z.infer<typeof withdrawMetalResponseParser>
|
|
32
|
+
|
|
33
|
+
export const withdrawalFeeQuoteParser = z.object({
|
|
34
|
+
quoteId : z.string(),
|
|
35
|
+
estimatedFee: z.string(),
|
|
36
|
+
currency : z.string(),
|
|
37
|
+
network : z.string(),
|
|
38
|
+
})
|
|
39
|
+
export type WithdrawalFeeQuote = z.infer<typeof withdrawalFeeQuoteParser>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'nestjs-zod/z'
|
|
2
|
+
|
|
3
|
+
export const withdrawHistoryMetalSwapParser = z.object({
|
|
4
|
+
id : z.string(),
|
|
5
|
+
status : z.string(),
|
|
6
|
+
amount : z.string(),
|
|
7
|
+
currency : z.string(),
|
|
8
|
+
network : z.string(),
|
|
9
|
+
created : z.string(),
|
|
10
|
+
withdrawalAddress: z.string(),
|
|
11
|
+
withdrawalHash : z.string().optional()
|
|
12
|
+
})
|
|
13
|
+
export type WithdrawHistoryMetalSwap = z.infer<typeof withdrawHistoryMetalSwapParser>
|
|
14
|
+
|
|
15
|
+
export const withdrawHistoryMetalResponseParser = z.object({
|
|
16
|
+
swaps : z.array(withdrawHistoryMetalSwapParser),
|
|
17
|
+
page : z.number(),
|
|
18
|
+
pageSize : z.number(),
|
|
19
|
+
numberOfElements: z.number(),
|
|
20
|
+
totalPages : z.number(),
|
|
21
|
+
totalElements : z.number()
|
|
22
|
+
})
|
|
23
|
+
export type WithdrawHistoryMetalResponse = z.infer<typeof withdrawHistoryMetalResponseParser>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'nestjs-zod/z'
|
|
2
|
+
import { ExtendedAssetParser } from './base'
|
|
3
|
+
|
|
4
|
+
export enum Status {
|
|
5
|
+
PENDING = 'pending',
|
|
6
|
+
SUCCESS = 'success',
|
|
7
|
+
FAIL = 'fail',
|
|
8
|
+
PROCESSING = 'processing'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const wrapStartParser = z.object({
|
|
12
|
+
balance : ExtendedAssetParser,
|
|
13
|
+
id : z.string(),
|
|
14
|
+
txid : z.string(),
|
|
15
|
+
chain : z.string(),
|
|
16
|
+
deposit_address: z.string(),
|
|
17
|
+
confirmations : z.number()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
export type WrapStart = z.infer<typeof wrapStartParser>
|
|
21
|
+
|
|
22
|
+
export const wrapSetConfParser = z.object({
|
|
23
|
+
wrap_hash : z.string(),
|
|
24
|
+
confirmations: z.number()
|
|
25
|
+
})
|
|
26
|
+
export type WrapSetConf = z.infer<typeof wrapSetConfParser>
|
|
27
|
+
|
|
28
|
+
export const wrapParser = z.object({
|
|
29
|
+
index : z.number(),
|
|
30
|
+
proton_account : z.string(),
|
|
31
|
+
balance : ExtendedAssetParser,
|
|
32
|
+
id : z.string(),
|
|
33
|
+
txid : z.string(),
|
|
34
|
+
chain : z.string(),
|
|
35
|
+
deposit_address: z.string(),
|
|
36
|
+
status : z.nativeEnum(Status),
|
|
37
|
+
finish_txid : z.string(),
|
|
38
|
+
wrap_hash : z.string(),
|
|
39
|
+
confirmations : z.number(),
|
|
40
|
+
})
|
|
41
|
+
export type Wrap = z.infer<typeof wrapParser>
|
package/src/utils.ts
CHANGED
|
@@ -8,4 +8,15 @@ export const isSameToken = (token1: PartialCoin, token2: PartialCoin) => {
|
|
|
8
8
|
return token1.xtokenSymbol === token2.xtokenSymbol &&
|
|
9
9
|
token1.xtokenPrecision === token2.xtokenPrecision &&
|
|
10
10
|
token1.xtokenContract === token2.xtokenContract
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const median = (numbers: number[]) => {
|
|
14
|
+
const sorted = numbers.slice().sort((a, b) => a - b);
|
|
15
|
+
const middle = Math.floor(sorted.length / 2);
|
|
16
|
+
|
|
17
|
+
if (sorted.length % 2 === 0) {
|
|
18
|
+
return (sorted[middle - 1] + sorted[middle]) / 2;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return sorted[middle];
|
|
22
|
+
}
|