@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
package/src/constants.ts
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import { Coin, CoinWallet, initializeCoins, Wallet } from './coins'
|
|
2
2
|
|
|
3
3
|
export const WRAP_CONTRACT = 'proton.wrap'
|
|
4
|
+
export const WRAP_AUTH_ACTION = 'generateauth'
|
|
5
|
+
export const FEE_FACTOR = 10000
|
|
4
6
|
|
|
5
7
|
export const initializeConstants = (chain: string) => {
|
|
6
|
-
const { swapCoins, bridgeCoins, allEnabledCoins, allCoins } = initializeCoins(chain)
|
|
8
|
+
const { swapCoins, bridgeCoins, allEnabledCoins, allCoins, lendCoins, borrowCoins, loanCoins } = initializeCoins(chain)
|
|
7
9
|
|
|
8
10
|
const constants = {
|
|
9
11
|
SWAP_CONTRACT: 'proton.swaps',
|
|
10
|
-
|
|
12
|
+
DEX_CONTRACT: chain === 'proton'
|
|
13
|
+
? 'dex'
|
|
14
|
+
: 'dextest21',
|
|
15
|
+
FEE_FACTOR,
|
|
11
16
|
GOOGLE_MAPS_KEY: 'AIzaSyDb2_CrK032kSIqBXbkdwmaLKWELl0SxVs',
|
|
12
17
|
SWAP_URL: chain === 'proton'
|
|
13
18
|
? 'https://otc.protonswap.com'
|
|
14
19
|
: 'https://otc-test.protonswap.com',
|
|
15
20
|
WRAP_SERVER_URL: chain === 'proton'
|
|
16
|
-
? 'https://www.api.bloks.io/proton-wrap-
|
|
17
|
-
: 'https://www.api.bloks.io/proton-wrap-testnet-
|
|
21
|
+
? 'https://www.api.bloks.io/proton-wrap-public2'
|
|
22
|
+
: 'https://www.api.bloks.io/proton-wrap-testnet-public2',
|
|
18
23
|
WRAP_CONTRACT,
|
|
19
24
|
WRAP_ACTIONS: {
|
|
20
|
-
SAVE_ADDRESS: '
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
SAVE_ADDRESS: 'saveaddress2',
|
|
26
|
+
DELETE_ADDRESS: 'deladdress2',
|
|
27
|
+
WRAP_START: 'wrapstart2',
|
|
28
|
+
WRAP_FINISH: 'wrapfinish2',
|
|
29
|
+
WRAP_PROCESS: 'wrapprocess2',
|
|
30
|
+
WRAP_SET_CONF: 'wrapsetconf2',
|
|
25
31
|
},
|
|
26
32
|
WRAP_TABLES: {
|
|
27
|
-
ADDRESSES: '
|
|
28
|
-
WRAPS: '
|
|
33
|
+
ADDRESSES: 'addresses2',
|
|
34
|
+
WRAPS: 'wraps2'
|
|
29
35
|
},
|
|
30
36
|
ADDRESSES_INDEXES: {
|
|
31
37
|
BY_ACCOUNT: 2,
|
|
@@ -42,7 +48,8 @@ export const initializeConstants = (chain: string) => {
|
|
|
42
48
|
|
|
43
49
|
WEBHOOK_PERMISSION: 'webhook',
|
|
44
50
|
PUBLIC_PERMISSION: 'public',
|
|
45
|
-
|
|
51
|
+
LIGHT_PERMISSION: 'light',
|
|
52
|
+
WRAP_AUTH_ACTION: WRAP_AUTH_ACTION,
|
|
46
53
|
|
|
47
54
|
METAL_ENDPOINT: chain === 'proton'
|
|
48
55
|
? 'https://cirrus.metalpay.com'
|
|
@@ -52,9 +59,13 @@ export const initializeConstants = (chain: string) => {
|
|
|
52
59
|
? 'https://api.protonchain.com'
|
|
53
60
|
: 'https://api-dev.protonchain.com',
|
|
54
61
|
|
|
62
|
+
METAL_DEX_ENDPOINT: chain === 'proton'
|
|
63
|
+
? 'https://metallicus-dbapi-dev01.binfra.one'
|
|
64
|
+
: 'https://metallicus-dbapi-dev01.binfra.one',
|
|
65
|
+
|
|
55
66
|
PROTON_ENDPOINTS: chain === 'proton'
|
|
56
|
-
? ['https://proton.greymass.com', 'https://proton.eoscafeblock.com', 'https://proton.cryptolions.io', 'https://proton.eosusa.news']
|
|
57
|
-
: ['https://testnet.protonchain.com'],
|
|
67
|
+
? ['https://metal-proton-rpc.global.binfra.one', 'https://proton.greymass.com', 'https://proton.eoscafeblock.com', 'https://proton.cryptolions.io', 'https://proton.eosusa.news']
|
|
68
|
+
: ['https://metal-protontest-rpc.global.binfra.one', 'https://testnet.protonchain.com'],
|
|
58
69
|
|
|
59
70
|
CHAIN_ID: chain === 'proton'
|
|
60
71
|
? '384da888112027f0321850a169f737c33e53b388aad48b5adace4bab97f437e0'
|
|
@@ -65,11 +76,27 @@ export const initializeConstants = (chain: string) => {
|
|
|
65
76
|
SWAP_COINS: swapCoins,
|
|
66
77
|
BRIDGE_COINS: bridgeCoins,
|
|
67
78
|
ALL_ENABLED_COINS: allEnabledCoins,
|
|
79
|
+
LEND_COINS: lendCoins,
|
|
80
|
+
BORROW_COINS: borrowCoins,
|
|
81
|
+
LOAN_COINS: loanCoins,
|
|
68
82
|
ALL_COINS: allCoins,
|
|
69
83
|
|
|
84
|
+
findBridgeCoinWalletByXtokenAndChain (xtokenSymbol: string, chain: string): CoinWallet | undefined {
|
|
85
|
+
const bridgeCoin = constants.BRIDGE_COINS.find((bridgeCoin: Coin) => bridgeCoin.xtokenSymbol === xtokenSymbol)
|
|
86
|
+
if (!bridgeCoin) return undefined
|
|
87
|
+
const bridgeWallet = bridgeCoin.wallets.find((bridgeWallet: Wallet) => bridgeWallet.chain === chain)
|
|
88
|
+
if (!bridgeWallet) return undefined
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
...bridgeCoin,
|
|
92
|
+
...bridgeWallet
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
|
|
70
96
|
findBridgeCoinWallet (coin: string, wallet: string): CoinWallet | undefined {
|
|
71
97
|
const bridgeCoin = constants.BRIDGE_COINS.find((bridgeCoin: Coin) => bridgeCoin.coin === coin)
|
|
72
98
|
if (!bridgeCoin) return undefined
|
|
99
|
+
|
|
73
100
|
const bridgeWallet = bridgeCoin.wallets.find((bridgeWallet: Wallet) => bridgeWallet.wallet === wallet)
|
|
74
101
|
if (!bridgeWallet) return undefined
|
|
75
102
|
|
package/src/graph.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import cloneDeep from 'lodash.clonedeep'
|
|
2
|
+
|
|
3
|
+
export class INode <T> {
|
|
4
|
+
data: T = {} as T
|
|
5
|
+
constructor (public key: string, data?: T) {
|
|
6
|
+
if (data) {
|
|
7
|
+
this.data = data
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ILink <T> {
|
|
13
|
+
data: T = {} as T
|
|
14
|
+
constructor (public from: INode<T>, public to: INode<T>, data?: T) {
|
|
15
|
+
if (data) {
|
|
16
|
+
this.data = data
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class Graph <T> {
|
|
22
|
+
nodes: INode<T>[] = []
|
|
23
|
+
links: ILink<T>[] = []
|
|
24
|
+
lastPathFound: INode<T>[] = []
|
|
25
|
+
|
|
26
|
+
isEquals = (a: INode<T>, b: INode<T>) => a.key === b.key
|
|
27
|
+
|
|
28
|
+
addNode (k: string, v?: T): void {
|
|
29
|
+
const node = this.findNode(k)
|
|
30
|
+
if (!node) {
|
|
31
|
+
this.nodes.push(new INode(k, v))
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
addNodes (...nodes: (string | [string, T?])[]): void {
|
|
36
|
+
nodes.forEach(node => typeof node === "string" ? this.addNode(node) : this.addNode(node[0], node[1]))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
findNode (k: string): INode<T> | undefined {
|
|
40
|
+
const inode = new INode<T>(k)
|
|
41
|
+
return this.nodes.find(node => this.isEquals(node, inode))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
findNodes (...keys: string[]): (INode<T> | undefined)[] {
|
|
45
|
+
return keys.map(k => this.findNode(k))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
requireFindNodes (...keys: string[]): INode<T>[] {
|
|
49
|
+
const nodes = this.findNodes(...keys)
|
|
50
|
+
if (nodes.some(n => n === undefined)) {
|
|
51
|
+
throw new Error('One of the nodes does not exist')
|
|
52
|
+
}
|
|
53
|
+
return nodes as INode<T>[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
addLink (nodeA: string, nodeB: string, data?: T): void {
|
|
57
|
+
const [inodeA, inodeB] = this.requireFindNodes(nodeA, nodeB)
|
|
58
|
+
this.links.push(new ILink<T>(inodeA, inodeB, data))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addLinks (...links: [nodeA: string, nodeB: string, data?: T][]): void {
|
|
62
|
+
links.forEach(link => this.addLink(...link))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get all nodes linked
|
|
67
|
+
* to from `node`.
|
|
68
|
+
*/
|
|
69
|
+
findLinkedNodes (node: INode<T>) {
|
|
70
|
+
return this.links.reduce((acc, link) => {
|
|
71
|
+
if (this.isEquals(link.from, node)) {
|
|
72
|
+
acc.push(link.to)
|
|
73
|
+
}
|
|
74
|
+
return acc;
|
|
75
|
+
}, [] as INode<T>[]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
findAllPaths(from: string, to: string) {
|
|
79
|
+
const allPaths: INode<T>[][] = []
|
|
80
|
+
|
|
81
|
+
const [fromNode, toNode] = this.requireFindNodes(from, to)
|
|
82
|
+
|
|
83
|
+
const path: INode<T>[] = [fromNode]
|
|
84
|
+
let seen = new Set()
|
|
85
|
+
|
|
86
|
+
const stuck = (x: INode<T>) => {
|
|
87
|
+
if (this.isEquals(x, toNode)) {
|
|
88
|
+
return false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const y of this.findLinkedNodes(x)) {
|
|
92
|
+
if (!seen.has(y.key)) {
|
|
93
|
+
seen.add(y.key)
|
|
94
|
+
if (!stuck(y)) {
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return true
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const search = (x: INode<T>) => {
|
|
104
|
+
if (this.isEquals(x, toNode)) {
|
|
105
|
+
allPaths.push(cloneDeep(path))
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
seen = new Set(path.map(p => p.key))
|
|
109
|
+
if (stuck(x)) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const y of this.findLinkedNodes(x)) {
|
|
114
|
+
if (!path.includes(y)) {
|
|
115
|
+
path.push(y)
|
|
116
|
+
search(y)
|
|
117
|
+
path.pop()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
search(fromNode)
|
|
123
|
+
|
|
124
|
+
return allPaths
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/index.ts
CHANGED
package/src/math.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BigNumber as BN } from 'bignumber.js'
|
|
2
|
+
import { FEE_FACTOR } from './constants'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* XPR<>XUSDT (XPR -> XUSDT)
|
|
6
|
+
*
|
|
7
|
+
* pool1 * pool2
|
|
8
|
+
* term = pool2 - --------------
|
|
9
|
+
* pool1 + swap
|
|
10
|
+
*
|
|
11
|
+
* result = term - (term * fee)
|
|
12
|
+
*/
|
|
13
|
+
export const compute_transfer = (pool1: BN.Instance, pool2: BN.Instance, swap: BN.Instance, exchange_fee: number, precision: number): BN => {
|
|
14
|
+
const term1 = pool2
|
|
15
|
+
const term2over = pool1.multipliedBy(pool2)
|
|
16
|
+
const term2under = pool1.plus(swap)
|
|
17
|
+
const term2 = term2over.dividedBy(term2under).integerValue(BN.ROUND_DOWN)
|
|
18
|
+
const term = term1.minus(term2)
|
|
19
|
+
const fee = new BN(exchange_fee).dividedBy(FEE_FACTOR)
|
|
20
|
+
const result = term.minus(term.multipliedBy(fee))
|
|
21
|
+
|
|
22
|
+
return result.integerValue(BN.ROUND_DOWN).shiftedBy(-precision)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const compute_transfer_curve = (
|
|
26
|
+
reserve_in: number,
|
|
27
|
+
reserve_out: number,
|
|
28
|
+
amount_in: number,
|
|
29
|
+
exchange_fee: number,
|
|
30
|
+
precision: number,
|
|
31
|
+
amplifier: number
|
|
32
|
+
): BN => {
|
|
33
|
+
if (amplifier === 0) {
|
|
34
|
+
return compute_transfer(new BN(reserve_in), new BN(reserve_out), new BN(amount_in), exchange_fee, precision)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const MAX_ITERATIONS = 10
|
|
38
|
+
|
|
39
|
+
const sum = reserve_in + reserve_out
|
|
40
|
+
let D = sum;
|
|
41
|
+
let D_prev = 0
|
|
42
|
+
|
|
43
|
+
const F = (v: number) => {
|
|
44
|
+
return (v >= 0 ? 1 : -1) * Math.floor(Math.abs(v));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let i = MAX_ITERATIONS
|
|
48
|
+
while (D != D_prev && i--) {
|
|
49
|
+
const prod1 = F((F((D * D) / (reserve_in * 2)) * D) / (reserve_out * 2));
|
|
50
|
+
D_prev = D
|
|
51
|
+
D = F((2 * D * ((amplifier * sum) + prod1)) / ((2 * amplifier - 1) * D + 3 * prod1));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const b = ((reserve_in + amount_in) + F(D / (amplifier * 2))) - D;
|
|
55
|
+
|
|
56
|
+
const c = F(F((D * D) / ((reserve_in + amount_in) * 2)) * D / (amplifier * 4));
|
|
57
|
+
|
|
58
|
+
let x = D, x_prev = 0;
|
|
59
|
+
i = MAX_ITERATIONS;
|
|
60
|
+
while ( x != x_prev && i--) {
|
|
61
|
+
x_prev = F(x);
|
|
62
|
+
x = +new BN(x * x + c).dividedBy(2 * x + b).toFixed(0, BN.ROUND_DOWN)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (reserve_out <= x) {
|
|
66
|
+
throw new Error("curve: insufficient reserve out")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Amount out + Fee + 1
|
|
70
|
+
const amount_out_with_fee = new BN(reserve_out - x);
|
|
71
|
+
|
|
72
|
+
// Fee + 1
|
|
73
|
+
// +1 covers small precision issues
|
|
74
|
+
const fee = amount_out_with_fee.multipliedBy(exchange_fee).dividedBy(FEE_FACTOR).plus(1).toFixed(0, BN.ROUND_DOWN);
|
|
75
|
+
|
|
76
|
+
// Amount out
|
|
77
|
+
const amount_out = amount_out_with_fee.minus(fee)
|
|
78
|
+
|
|
79
|
+
return amount_out.integerValue(BN.ROUND_DOWN).shiftedBy(-precision)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const compute_liquidity = (amount_lt: BN.Instance, pool: BN.Instance, lt_supply: BN.Instance, precision: number): number => {
|
|
83
|
+
const over = amount_lt.multipliedBy(pool)
|
|
84
|
+
const under = lt_supply
|
|
85
|
+
const result = over.dividedBy(under).integerValue(BN.ROUND_DOWN)
|
|
86
|
+
|
|
87
|
+
return +(result.shiftedBy(-precision).toFixed(precision, BN.ROUND_DOWN))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const isInputInvalid = (data: string, value: string | number, pool: { xtokenPrecision: number }): boolean => {
|
|
91
|
+
value = String(value)
|
|
92
|
+
|
|
93
|
+
const isBackspace = data === null
|
|
94
|
+
const isNumber = !/[0-9]|\./.test(data)
|
|
95
|
+
const isDoubleDot = data === '.' && value.indexOf('.') !== value.length - 1
|
|
96
|
+
const isPrecisionTooHigh = value && value.indexOf('.') !== -1 && value.split('.')[1].length > pool.xtokenPrecision
|
|
97
|
+
const isInvalid = !isBackspace && Boolean(isNumber || isDoubleDot || isPrecisionTooHigh)
|
|
98
|
+
|
|
99
|
+
return isInvalid
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const applyDiscountToFee = (fee: number, staked: number): number => {
|
|
103
|
+
if (staked >= 10000000) {
|
|
104
|
+
return fee * 0
|
|
105
|
+
} else if (staked >= 1000000) {
|
|
106
|
+
return fee * 0.33
|
|
107
|
+
} else if (staked >= 100000) {
|
|
108
|
+
return fee * 0.66
|
|
109
|
+
} else {
|
|
110
|
+
return fee
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { accountParser, authorizationsParser } from './base'
|
|
3
|
+
|
|
4
|
+
const actionParser = z.object({
|
|
5
|
+
account: z.string(),
|
|
6
|
+
name: z.string(),
|
|
7
|
+
authorization: z.array(
|
|
8
|
+
z.object({
|
|
9
|
+
actor: z.string(),
|
|
10
|
+
permission: z.string(),
|
|
11
|
+
})
|
|
12
|
+
),
|
|
13
|
+
data: z.any(),
|
|
14
|
+
hex_data: z.string().optional()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const transactionExtensionsParser = z.array(z.number().or(z.string())).optional()
|
|
18
|
+
|
|
19
|
+
const rawTransactionParser = z.object({
|
|
20
|
+
expiration : z.string(),
|
|
21
|
+
ref_block_num : z.number(),
|
|
22
|
+
ref_block_prefix : z.number(),
|
|
23
|
+
max_net_usage_words : z.number(),
|
|
24
|
+
max_cpu_usage_ms : z.number(),
|
|
25
|
+
delay_sec : z.number(),
|
|
26
|
+
context_free_actions : z.array(actionParser),
|
|
27
|
+
transaction_extensions: z.array(transactionExtensionsParser)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const baseActionParser = <T extends z.ZodRawShape>(contract: string, action: string, data: T) => z.object({
|
|
31
|
+
account: contract === '*' ? accountParser : z.literal(contract),
|
|
32
|
+
name: z.literal(action),
|
|
33
|
+
data: z.object(data),
|
|
34
|
+
authorization: authorizationsParser
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export const baseActionSerializedParser = <T extends z.ZodRawShape>(contract: string, action: string, data: T) => z.object({
|
|
38
|
+
account: contract === '*' ? accountParser : z.literal(contract),
|
|
39
|
+
name: z.literal(action),
|
|
40
|
+
data: z.string().or(z.object(data)),
|
|
41
|
+
authorization: authorizationsParser
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const webauthActionParser = <T extends z.ZodRawShape>(contract: string, action: string, data: T) => z.object({
|
|
45
|
+
account: z.literal('webauthn'),
|
|
46
|
+
name: z.literal('exec'),
|
|
47
|
+
data: z.object({
|
|
48
|
+
account: accountParser,
|
|
49
|
+
key: z.object({
|
|
50
|
+
key: z.array(z.string().or(z.object({
|
|
51
|
+
modulus: z.string(),
|
|
52
|
+
exponent: z.string()
|
|
53
|
+
}))),
|
|
54
|
+
user_presence: z.number(),
|
|
55
|
+
rpid: z.string()
|
|
56
|
+
}),
|
|
57
|
+
nonce: z.number(),
|
|
58
|
+
permissions: authorizationsParser,
|
|
59
|
+
signature: z.object({
|
|
60
|
+
auth_data: z.string(),
|
|
61
|
+
client_json: z.string(),
|
|
62
|
+
signature: z.string()
|
|
63
|
+
}),
|
|
64
|
+
trx: rawTransactionParser.merge(
|
|
65
|
+
z.object({
|
|
66
|
+
actions: z.array(
|
|
67
|
+
baseActionSerializedParser(contract, action, data)
|
|
68
|
+
).length(1)
|
|
69
|
+
})
|
|
70
|
+
)
|
|
71
|
+
}),
|
|
72
|
+
authorization: authorizationsParser
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
export const singleActionTransactionParser = <T extends z.ZodRawShape>(contract: string, action: string, data: T) => {
|
|
76
|
+
const baseAction = baseActionParser(contract, action, data)
|
|
77
|
+
const webauthAction = webauthActionParser(contract, action, data)
|
|
78
|
+
|
|
79
|
+
return rawTransactionParser.merge(z.object({
|
|
80
|
+
actions: z.array(baseAction.or(webauthAction)).length(1)
|
|
81
|
+
}))
|
|
82
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { accountParser } from './base'
|
|
3
|
+
import { generateAuthParser } from './auth'
|
|
4
|
+
|
|
5
|
+
export const addressParser = z.object({
|
|
6
|
+
index : z.number(),
|
|
7
|
+
account : accountParser,
|
|
8
|
+
chain : z.string(),
|
|
9
|
+
address : z.string(),
|
|
10
|
+
address_hash: z.string(),
|
|
11
|
+
})
|
|
12
|
+
export type Address = z.infer<typeof addressParser>
|
|
13
|
+
|
|
14
|
+
export const generateAddressBodyParser = z.object({
|
|
15
|
+
coin: z.string(),
|
|
16
|
+
wallet: z.string(),
|
|
17
|
+
}).merge(generateAuthParser)
|
|
18
|
+
export type GenerateAddressBody = z.infer<typeof generateAddressBodyParser>
|
|
19
|
+
|
|
20
|
+
export const generateAddressResponse = z.object({
|
|
21
|
+
id : z.string(), // "2448834505708930950",
|
|
22
|
+
address: z.string(), // "0x617C03C1E2Bf81C062A4CEfbE312c070E1d86d18",
|
|
23
|
+
coin : z.string(), // "ETH",
|
|
24
|
+
wallet : z.string(), // "ETH",
|
|
25
|
+
memo : z.string().optional()
|
|
26
|
+
})
|
|
27
|
+
export type GenerateAddressResponse = z.infer<typeof generateAddressResponse>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { baseActionParser, singleActionTransactionParser } from './actions'
|
|
3
|
+
import { authorizationParser } from './base'
|
|
4
|
+
import { WRAP_CONTRACT, WRAP_AUTH_ACTION } from '../constants'
|
|
5
|
+
|
|
6
|
+
export const createAbstractAuthParser = (contract: string, action: string, data: z.ZodRawShape) => {
|
|
7
|
+
return z.object({
|
|
8
|
+
signer : authorizationParser,
|
|
9
|
+
signatures : z.array(z.string()).length(1),
|
|
10
|
+
transaction: singleActionTransactionParser(contract, action, data)
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const generateAuthData = {
|
|
15
|
+
time: z.string(),
|
|
16
|
+
protonAccount: z.string()
|
|
17
|
+
}
|
|
18
|
+
const generateAuthActionsBaseParser = baseActionParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData)
|
|
19
|
+
export type GenerateAuthBaseAction = z.infer<typeof generateAuthActionsBaseParser>
|
|
20
|
+
|
|
21
|
+
export const generateAuthParser = createAbstractAuthParser(WRAP_CONTRACT, WRAP_AUTH_ACTION, generateAuthData)
|
|
22
|
+
export type GenerateAuth = z.infer<typeof generateAuthParser>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as z from 'zod'
|
|
2
|
+
|
|
3
|
+
export const accountParser = z.string().regex(/^[.1-5a-z]{0,12}[.1-5a-j]?$/)
|
|
4
|
+
|
|
5
|
+
export const authorizationParser = z.object({
|
|
6
|
+
actor : accountParser,
|
|
7
|
+
permission: z.string()
|
|
8
|
+
})
|
|
9
|
+
export type Authorization = z.infer<typeof authorizationParser>
|
|
10
|
+
|
|
11
|
+
export const authorizationsParser = z.array(authorizationParser).min(1)
|
|
12
|
+
export type Authorizations = z.infer<typeof authorizationsParser>
|
|
13
|
+
|
|
14
|
+
export const ExtendedAssetParser = z.object({
|
|
15
|
+
quantity: z.string(),
|
|
16
|
+
contract: accountParser
|
|
17
|
+
})
|
|
18
|
+
export type ExtendedAsset = z.infer<typeof ExtendedAssetParser>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as z from 'zod'
|
|
2
|
+
|
|
3
|
+
export interface CurrencyStat {
|
|
4
|
+
supply : string;
|
|
5
|
+
max_supply: string;
|
|
6
|
+
issuer : string;
|
|
7
|
+
}
|
|
8
|
+
export interface CurrencyStats {
|
|
9
|
+
[key: string]: CurrencyStat;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const rateParser = z.object({
|
|
13
|
+
counterCurrency : z.string(),
|
|
14
|
+
price : z.number(),
|
|
15
|
+
priceChangePercent: z.number(),
|
|
16
|
+
marketCap : z.number(),
|
|
17
|
+
volume : z.number(),
|
|
18
|
+
timestamp : z.number()
|
|
19
|
+
})
|
|
20
|
+
export type Rate = z.infer<typeof rateParser>
|
|
21
|
+
|
|
22
|
+
export const exchangeRateParser = z.object({
|
|
23
|
+
contract: z.string(),
|
|
24
|
+
symbol : z.string(),
|
|
25
|
+
rank : z.number(),
|
|
26
|
+
rates : z.array(rateParser)
|
|
27
|
+
})
|
|
28
|
+
export type ExchangeRate = z.infer<typeof exchangeRateParser>
|
|
29
|
+
|
|
30
|
+
export const exchangeRatesParser = z.array(exchangeRateParser)
|
|
31
|
+
export type ExchangeRates = z.infer<typeof exchangeRatesParser>
|
|
32
|
+
|
|
33
|
+
export const bloksRatesParser = z.array(z.object({
|
|
34
|
+
contract: z.string(),
|
|
35
|
+
symbol : z.string(),
|
|
36
|
+
rank : z.number(),
|
|
37
|
+
rates : z.array(rateParser)
|
|
38
|
+
}))
|
|
39
|
+
|
|
40
|
+
export type BloksRate = {
|
|
41
|
+
key: string;
|
|
42
|
+
symbol: string;
|
|
43
|
+
account: string;
|
|
44
|
+
chain: string;
|
|
45
|
+
supply: {
|
|
46
|
+
circulating: number;
|
|
47
|
+
max: number;
|
|
48
|
+
precision: number;
|
|
49
|
+
last_update: string;
|
|
50
|
+
};
|
|
51
|
+
metadata: {
|
|
52
|
+
name: string;
|
|
53
|
+
website: string;
|
|
54
|
+
logo: string;
|
|
55
|
+
created_at: string;
|
|
56
|
+
desc: string;
|
|
57
|
+
};
|
|
58
|
+
pairs: [
|
|
59
|
+
{
|
|
60
|
+
id: string;
|
|
61
|
+
pair_base: string;
|
|
62
|
+
pair_quote: string;
|
|
63
|
+
exchange: string;
|
|
64
|
+
quote:{
|
|
65
|
+
price: number
|
|
66
|
+
volume_base_24h: number
|
|
67
|
+
volume_quote_24h: number
|
|
68
|
+
market_cap: number
|
|
69
|
+
price_usd: number
|
|
70
|
+
volume_usd_24h: number
|
|
71
|
+
},
|
|
72
|
+
percentage_daily_volume: number
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
price: {
|
|
76
|
+
quotes: {
|
|
77
|
+
[key: string]: number
|
|
78
|
+
},
|
|
79
|
+
usd: number;
|
|
80
|
+
volume_base_24h: number;
|
|
81
|
+
volume_usd_24h: number;
|
|
82
|
+
marketcap_usd: number;
|
|
83
|
+
change_24hr: number;
|
|
84
|
+
},
|
|
85
|
+
rank: number;
|
|
86
|
+
chain_rank: number;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type BloksRates = BloksRate[]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as z from 'zod'
|
|
2
|
+
|
|
3
|
+
export enum Type {
|
|
4
|
+
RECEIVE = 'receive',
|
|
5
|
+
SEND = 'send'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const depositBodyParser = z.object({
|
|
9
|
+
id : z.string(), // "0x000010203121388fac991"
|
|
10
|
+
type : z.nativeEnum(Type), // "receive" or "send"
|
|
11
|
+
hash : z.string(), // "0x000010203121388fac991"
|
|
12
|
+
coin : z.string(), // "ETH" or "XPR"
|
|
13
|
+
wallet : z.string(), // "ETH-ROPSTEN" or "XPR-MAINNET"
|
|
14
|
+
})
|
|
15
|
+
export type DepositBody = z.infer<typeof depositBodyParser>
|
|
16
|
+
|
|
17
|
+
export const transactionParser = z.object({
|
|
18
|
+
id : z.string(), // "2629304740076324677"
|
|
19
|
+
wallet : z.string(), // "ETH"
|
|
20
|
+
value : z.number(), // 10000000000000000
|
|
21
|
+
valueString : z.string(), // "10000000000000000"
|
|
22
|
+
address : z.string(), // "0x0000"
|
|
23
|
+
type : z.nativeEnum(Type), // "receive" or "send"
|
|
24
|
+
state : z.string(), // "confirmed"
|
|
25
|
+
confirmations : z.number(), // 1
|
|
26
|
+
hash : z.string(), // "b4781422be95fee8fbbf720e3e0fa9705ae834474ef25f5724cdd0f5d23211ed"
|
|
27
|
+
blockHash : z.string().optional().nullable(), // "000000000000000000089b270eb99f75107d6a9cde37ec944cb80a2998df7b43"
|
|
28
|
+
blockHeight : z.number().optional().nullable(), // 643159
|
|
29
|
+
})
|
|
30
|
+
export type Transaction = z.infer<typeof transactionParser>
|