@triadxyz/triad-protocol 1.6.6-beta → 1.6.7-beta-dev
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/trade.d.ts +53 -8
- package/dist/trade.js +51 -28
- package/dist/types/idl_triad_protocol.json +182 -140
- package/dist/types/trade.d.ts +17 -2
- package/dist/types/triad_protocol.d.ts +173 -131
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +10 -1
- package/dist/wheel.d.ts +1 -1
- package/dist/wheel.js +3 -3
- package/package.json +1 -1
- package/dist/local-test/index.d.ts +0 -1
- package/dist/local-test/index.js +0 -528
- package/dist/local-test/init-market.d.ts +0 -8
- package/dist/local-test/init-market.js +0 -63
- package/dist/local-test/simulate-market.d.ts +0 -54
- package/dist/local-test/simulate-market.js +0 -156
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import TriadProtocol from '..';
|
|
2
|
-
export declare class SimulateMarket {
|
|
3
|
-
private triadProtocol;
|
|
4
|
-
market: {
|
|
5
|
-
hypePrice: number;
|
|
6
|
-
flopPrice: number;
|
|
7
|
-
liquidity: number;
|
|
8
|
-
hypeLiquidity: number;
|
|
9
|
-
flopLiquidity: number;
|
|
10
|
-
hypeShares: number;
|
|
11
|
-
flopShares: number;
|
|
12
|
-
};
|
|
13
|
-
ordersOpen: {
|
|
14
|
-
id: number;
|
|
15
|
-
shares: number;
|
|
16
|
-
amount: number;
|
|
17
|
-
direction: 'hype' | 'flop';
|
|
18
|
-
price: number;
|
|
19
|
-
marketPrice: number;
|
|
20
|
-
}[];
|
|
21
|
-
ordersClosed: {
|
|
22
|
-
id: number;
|
|
23
|
-
shares: number;
|
|
24
|
-
amount: number;
|
|
25
|
-
direction: 'hype' | 'flop';
|
|
26
|
-
price: number;
|
|
27
|
-
priceWithImpact: number;
|
|
28
|
-
payout: number;
|
|
29
|
-
}[];
|
|
30
|
-
orders: {
|
|
31
|
-
amount: number;
|
|
32
|
-
direction: 'hype' | 'flop';
|
|
33
|
-
}[];
|
|
34
|
-
constructor(triadProtocol: TriadProtocol);
|
|
35
|
-
simulate: () => void;
|
|
36
|
-
openOrder: (order: {
|
|
37
|
-
amount: number;
|
|
38
|
-
direction: 'hype' | 'flop';
|
|
39
|
-
}) => {
|
|
40
|
-
shares: number;
|
|
41
|
-
priceWithImpact: number;
|
|
42
|
-
marketPrice: number;
|
|
43
|
-
};
|
|
44
|
-
closeOrder: (order: {
|
|
45
|
-
amount: number;
|
|
46
|
-
shares: number;
|
|
47
|
-
direction: 'hype' | 'flop';
|
|
48
|
-
}) => {
|
|
49
|
-
payout: number;
|
|
50
|
-
shares: number;
|
|
51
|
-
price: number;
|
|
52
|
-
priceWithImpact: number;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimulateMarket = void 0;
|
|
4
|
-
const MAKER_FEE = 0.035; // 1% fee
|
|
5
|
-
const TAKER_FEE = 0.035; // 1% fee
|
|
6
|
-
class SimulateMarket {
|
|
7
|
-
constructor(triadProtocol) {
|
|
8
|
-
this.triadProtocol = triadProtocol;
|
|
9
|
-
this.market = {
|
|
10
|
-
hypePrice: 0.55283,
|
|
11
|
-
flopPrice: 0.447170,
|
|
12
|
-
liquidity: 2236.286652,
|
|
13
|
-
hypeLiquidity: 1236.286652,
|
|
14
|
-
flopLiquidity: 1000,
|
|
15
|
-
hypeShares: 0,
|
|
16
|
-
flopShares: 0
|
|
17
|
-
};
|
|
18
|
-
this.ordersOpen = [];
|
|
19
|
-
this.ordersClosed = [];
|
|
20
|
-
this.orders = [];
|
|
21
|
-
this.simulate = () => {
|
|
22
|
-
for (const order of this.orders) {
|
|
23
|
-
const result = this.openOrder(order);
|
|
24
|
-
this.ordersOpen.push({
|
|
25
|
-
id: this.ordersOpen.length + 1,
|
|
26
|
-
shares: result.shares,
|
|
27
|
-
amount: order.amount,
|
|
28
|
-
direction: order.direction,
|
|
29
|
-
price: result.priceWithImpact,
|
|
30
|
-
marketPrice: result.marketPrice
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
console.table(this.ordersOpen);
|
|
34
|
-
const ordersToClose = [];
|
|
35
|
-
for (const order of this.ordersOpen) {
|
|
36
|
-
if (ordersToClose.includes(order.id)) {
|
|
37
|
-
const result = this.closeOrder(order);
|
|
38
|
-
this.ordersClosed.push({
|
|
39
|
-
id: order.id,
|
|
40
|
-
shares: result.shares,
|
|
41
|
-
amount: order.amount,
|
|
42
|
-
direction: order.direction,
|
|
43
|
-
price: result.price,
|
|
44
|
-
priceWithImpact: result.priceWithImpact,
|
|
45
|
-
payout: result.payout
|
|
46
|
-
});
|
|
47
|
-
this.ordersOpen = this.ordersOpen.filter((o) => o.id !== order.id);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (this.ordersClosed.length > 0) {
|
|
51
|
-
console.table(this.ordersClosed);
|
|
52
|
-
}
|
|
53
|
-
console.table(this.market);
|
|
54
|
-
};
|
|
55
|
-
this.openOrder = (order) => {
|
|
56
|
-
let currentPool = order.direction === 'hype'
|
|
57
|
-
? this.market.hypeLiquidity
|
|
58
|
-
: this.market.flopLiquidity;
|
|
59
|
-
let otherPool = order.direction === 'hype'
|
|
60
|
-
? this.market.flopLiquidity
|
|
61
|
-
: this.market.hypeLiquidity;
|
|
62
|
-
const newCurrentPool = currentPool + order.amount;
|
|
63
|
-
const marketsLiquidity = newCurrentPool + otherPool;
|
|
64
|
-
let marketPrice = newCurrentPool / marketsLiquidity;
|
|
65
|
-
let orderPrice = marketPrice * (1 + MAKER_FEE);
|
|
66
|
-
const shares = order.amount / orderPrice;
|
|
67
|
-
if (marketPrice < 0.000001) {
|
|
68
|
-
marketPrice = 0.000001;
|
|
69
|
-
}
|
|
70
|
-
if (marketPrice > 0.999999) {
|
|
71
|
-
marketPrice = 0.999999;
|
|
72
|
-
}
|
|
73
|
-
if (orderPrice < 0.000001) {
|
|
74
|
-
orderPrice = 0.000001;
|
|
75
|
-
}
|
|
76
|
-
if (orderPrice > 0.999999) {
|
|
77
|
-
orderPrice = 0.999999;
|
|
78
|
-
}
|
|
79
|
-
if (order.direction === 'hype') {
|
|
80
|
-
this.market.hypeLiquidity = newCurrentPool;
|
|
81
|
-
this.market.flopLiquidity = otherPool;
|
|
82
|
-
this.market.hypePrice = marketPrice;
|
|
83
|
-
this.market.flopPrice = 1 - marketPrice;
|
|
84
|
-
this.market.hypeShares += shares;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.market.flopLiquidity = newCurrentPool;
|
|
88
|
-
this.market.hypeLiquidity = otherPool;
|
|
89
|
-
this.market.flopPrice = marketPrice;
|
|
90
|
-
this.market.hypePrice = 1 - marketPrice;
|
|
91
|
-
this.market.flopShares += shares;
|
|
92
|
-
}
|
|
93
|
-
this.market.liquidity = marketsLiquidity;
|
|
94
|
-
return {
|
|
95
|
-
shares,
|
|
96
|
-
priceWithImpact: orderPrice,
|
|
97
|
-
marketPrice
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
this.closeOrder = (order) => {
|
|
101
|
-
let currentPool = order.direction === 'hype'
|
|
102
|
-
? this.market.hypeLiquidity
|
|
103
|
-
: this.market.flopLiquidity;
|
|
104
|
-
let otherPool = order.direction === 'hype'
|
|
105
|
-
? this.market.flopLiquidity
|
|
106
|
-
: this.market.hypeLiquidity;
|
|
107
|
-
let currentShares = order.direction === 'hype'
|
|
108
|
-
? this.market.hypeShares
|
|
109
|
-
: this.market.flopShares;
|
|
110
|
-
let otherShares = order.direction === 'hype'
|
|
111
|
-
? this.market.flopShares
|
|
112
|
-
: this.market.hypeShares;
|
|
113
|
-
const k = currentPool * otherPool;
|
|
114
|
-
const currentPrice = currentPool / (currentPool + otherPool);
|
|
115
|
-
const tokensOut = order.shares * currentPrice;
|
|
116
|
-
const tokensOutAfterFee = tokensOut * (1 - TAKER_FEE);
|
|
117
|
-
const newCurrentPool = currentPool - tokensOutAfterFee;
|
|
118
|
-
const newOtherPool = k / newCurrentPool;
|
|
119
|
-
const newPrice = newCurrentPool / (newCurrentPool + newOtherPool);
|
|
120
|
-
if (newPrice < 0.000001) {
|
|
121
|
-
throw new Error('Price too low');
|
|
122
|
-
}
|
|
123
|
-
if (newPrice > 0.999999) {
|
|
124
|
-
throw new Error('Price too high');
|
|
125
|
-
}
|
|
126
|
-
if (order.direction === 'hype') {
|
|
127
|
-
this.market.hypeLiquidity = newCurrentPool;
|
|
128
|
-
this.market.flopLiquidity = newOtherPool;
|
|
129
|
-
this.market.hypePrice = newPrice;
|
|
130
|
-
this.market.flopPrice = 1 - newPrice;
|
|
131
|
-
this.market.hypeShares -= order.shares;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
this.market.flopLiquidity = newCurrentPool;
|
|
135
|
-
this.market.hypeLiquidity = newOtherPool;
|
|
136
|
-
this.market.flopPrice = newPrice;
|
|
137
|
-
this.market.hypePrice = 1 - newPrice;
|
|
138
|
-
this.market.flopShares -= order.shares;
|
|
139
|
-
}
|
|
140
|
-
this.market.liquidity = newCurrentPool + newOtherPool;
|
|
141
|
-
return {
|
|
142
|
-
payout: tokensOutAfterFee,
|
|
143
|
-
shares: order.shares,
|
|
144
|
-
price: newPrice,
|
|
145
|
-
priceWithImpact: tokensOutAfterFee / order.shares
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
for (let i = 0; i < 1; i++) {
|
|
149
|
-
this.orders.push({
|
|
150
|
-
amount: 1000,
|
|
151
|
-
direction: 'hype'
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.SimulateMarket = SimulateMarket;
|