@proton/wrap-constants 0.1.1 → 0.2.2
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 +291 -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 +1236 -289
- 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 +1216 -293
- package/dist/wrap-constants.esm.js.map +1 -1
- package/package.json +14 -8
- package/src/coins.ts +578 -150
- 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 +156 -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,156 @@
|
|
|
1
|
+
import { ExtendedAsset, ExtendedSymbol } from '@bloks/numbers';
|
|
2
|
+
import * as z from 'zod';
|
|
3
|
+
|
|
4
|
+
const numTransform = z.string().regex(/\d+/).transform(Number)
|
|
5
|
+
|
|
6
|
+
export const ohlcvParser = z.object({
|
|
7
|
+
time: z.number(),
|
|
8
|
+
open: z.number(),
|
|
9
|
+
high: z.number(),
|
|
10
|
+
low: z.number(),
|
|
11
|
+
close: z.number(),
|
|
12
|
+
volume: z.number(),
|
|
13
|
+
volume_bid: z.number(),
|
|
14
|
+
count: z.number()
|
|
15
|
+
})
|
|
16
|
+
export type OHLCV = z.infer<typeof ohlcvParser>
|
|
17
|
+
|
|
18
|
+
export const getOhlcvParser = z.object({
|
|
19
|
+
interval: z.string(),
|
|
20
|
+
dateFrom: z.string(),
|
|
21
|
+
dateTo: z.string(),
|
|
22
|
+
marketId: z.number().or(numTransform),
|
|
23
|
+
limit: z.number().or(numTransform).default(500).refine(n => n <= 1000, 'Max limit is 1000'),
|
|
24
|
+
})
|
|
25
|
+
export type GetOHLCV = z.infer<typeof getOhlcvParser>
|
|
26
|
+
|
|
27
|
+
export const orderHistoryParser = z.object({
|
|
28
|
+
seq: z.number(),
|
|
29
|
+
block_num: z.number(),
|
|
30
|
+
block_time: z.string(),
|
|
31
|
+
order_id: z.number(),
|
|
32
|
+
market_id: z.number(),
|
|
33
|
+
quantity_init: z.number().optional(),
|
|
34
|
+
quantity_curr: z.number(),
|
|
35
|
+
price: z.number(),
|
|
36
|
+
account_name: z.string(),
|
|
37
|
+
order_side: z.number(),
|
|
38
|
+
order_type: z.number(),
|
|
39
|
+
status: z.string(),
|
|
40
|
+
quantity_change: z.number(),
|
|
41
|
+
trx_id: z.string(),
|
|
42
|
+
})
|
|
43
|
+
export type OrderHistory = z.infer<typeof orderHistoryParser>
|
|
44
|
+
|
|
45
|
+
export const getOrderHistoryParser = z.object({
|
|
46
|
+
account: z.string(),
|
|
47
|
+
offset: z.number().or(numTransform).default(0),
|
|
48
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
49
|
+
})
|
|
50
|
+
export type GetOrderHistory = z.infer<typeof getOrderHistoryParser>
|
|
51
|
+
|
|
52
|
+
export const depthParser = z.object({
|
|
53
|
+
level: z.number(),
|
|
54
|
+
ask: z.number(),
|
|
55
|
+
bid: z.number(),
|
|
56
|
+
count: z.number(),
|
|
57
|
+
})
|
|
58
|
+
export type Depth = z.infer<typeof depthParser>
|
|
59
|
+
|
|
60
|
+
export const getDepthParser = z.object({
|
|
61
|
+
marketId: z.number(),
|
|
62
|
+
step: z.string(),
|
|
63
|
+
side: z.string(),
|
|
64
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
65
|
+
})
|
|
66
|
+
export type GetDepth = z.infer<typeof getDepthParser>
|
|
67
|
+
|
|
68
|
+
export const tradeParser = z.object({
|
|
69
|
+
block_num: z.number(),
|
|
70
|
+
block_time: z.string(),
|
|
71
|
+
trade_id: z.number(),
|
|
72
|
+
market_id: z.number(),
|
|
73
|
+
price: z.number(),
|
|
74
|
+
bid_user: z.string(),
|
|
75
|
+
bid_user_order_id: z.number(),
|
|
76
|
+
bid_amount: z.number(),
|
|
77
|
+
bid_fee: z.number(),
|
|
78
|
+
ask_user: z.string(),
|
|
79
|
+
ask_user_order_id: z.number(),
|
|
80
|
+
ask_amount: z.number(),
|
|
81
|
+
ask_fee: z.number(),
|
|
82
|
+
order_side: z.number(),
|
|
83
|
+
trx_id: z.string(),
|
|
84
|
+
})
|
|
85
|
+
export type Trade = z.infer<typeof tradeParser>
|
|
86
|
+
|
|
87
|
+
export const getTradesParser = z.object({
|
|
88
|
+
marketId: z.number().or(numTransform),
|
|
89
|
+
offset: z.number().or(numTransform).default(0),
|
|
90
|
+
limit: z.number().or(numTransform).default(100).refine(n => n <= 250, 'Max limit is 250'),
|
|
91
|
+
})
|
|
92
|
+
export type GetTrades = z.infer<typeof getTradesParser>
|
|
93
|
+
|
|
94
|
+
export const syncParser = z.object({
|
|
95
|
+
sourceid: z.number(),
|
|
96
|
+
block_num: z.string(),
|
|
97
|
+
block_time: z.string(),
|
|
98
|
+
irreversible: z.string(),
|
|
99
|
+
is_master: z.number(),
|
|
100
|
+
last_updated: z.string(),
|
|
101
|
+
})
|
|
102
|
+
export type Sync = z.infer<typeof syncParser>
|
|
103
|
+
|
|
104
|
+
export enum orderType { INVALID = 0, MARKET = 1, LIMIT = 2, STOPLOSS = 3, TAKEPROFIT = 4 }
|
|
105
|
+
|
|
106
|
+
export enum orderSide { INVALID = 0, BUY = 1, SELL = 2 }
|
|
107
|
+
|
|
108
|
+
export enum logStatus {
|
|
109
|
+
CREATE = "create",
|
|
110
|
+
UPDATE = "update",
|
|
111
|
+
TRANSFER = "transfer",
|
|
112
|
+
CANCEL = "cancel",
|
|
113
|
+
DELETE = "delete",
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface CurrentOrder {
|
|
117
|
+
order_id: number
|
|
118
|
+
market_id: number
|
|
119
|
+
quantity_init: number
|
|
120
|
+
quantity_curr: number
|
|
121
|
+
price: number
|
|
122
|
+
account_name: string
|
|
123
|
+
order_side: number
|
|
124
|
+
order_type: number
|
|
125
|
+
status: string
|
|
126
|
+
created_at: string
|
|
127
|
+
updated_at: string
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface RawMarket {
|
|
131
|
+
market_id: number
|
|
132
|
+
order_min: number
|
|
133
|
+
status_code: number
|
|
134
|
+
maker_fee: number
|
|
135
|
+
taker_fee: number
|
|
136
|
+
bid_token: {
|
|
137
|
+
sym: string
|
|
138
|
+
contract: string
|
|
139
|
+
}
|
|
140
|
+
ask_token: {
|
|
141
|
+
quantity: string
|
|
142
|
+
contract: string
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface Market {
|
|
147
|
+
market_id: number
|
|
148
|
+
order_min: number
|
|
149
|
+
status_code: number
|
|
150
|
+
maker_fee: number
|
|
151
|
+
taker_fee: number
|
|
152
|
+
bid_token: ExtendedSymbol
|
|
153
|
+
ask_token: ExtendedAsset
|
|
154
|
+
bid_multiplier: number
|
|
155
|
+
ask_multiplier: number
|
|
156
|
+
}
|
|
@@ -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 * as z from 'zod'
|
|
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 * as z from 'zod'
|
|
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 * as z from 'zod'
|
|
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 * as z from 'zod'
|
|
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
|
+
}
|