@triadxyz/triad-protocol 1.6.7-beta → 1.6.8-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/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/stake.d.ts +1 -9
- package/dist/stake.js +4 -10
- package/dist/trade.d.ts +92 -33
- package/dist/trade.js +277 -92
- package/dist/types/idl_triad_protocol.json +449 -605
- package/dist/types/trade.d.ts +76 -25
- package/dist/types/trade.js +25 -1
- package/dist/types/triad_protocol.d.ts +415 -629
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/helpers.d.ts +32 -3
- package/dist/utils/helpers.js +73 -18
- 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
- package/dist/wheel.d.ts +0 -62
- package/dist/wheel.js +0 -149
|
@@ -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;
|
package/dist/wheel.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
2
|
-
import { Keypair } from '@solana/web3.js';
|
|
3
|
-
import { TriadProtocol } from './types/triad_protocol';
|
|
4
|
-
import { RpcOptions } from './types';
|
|
5
|
-
export default class Wheel {
|
|
6
|
-
private program;
|
|
7
|
-
private provider;
|
|
8
|
-
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
9
|
-
/**
|
|
10
|
-
* Add Whell Prize
|
|
11
|
-
* @param args.rangeMin - Range min to get prize
|
|
12
|
-
* @param args.rangeMax - Range max to get prize
|
|
13
|
-
* @param args.prize - Prize number it's indentifier
|
|
14
|
-
* @param args.availableQuantity - Amount available to get
|
|
15
|
-
* @param args.amount - Amount to send
|
|
16
|
-
*
|
|
17
|
-
* @param options - RPC options
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }: {
|
|
21
|
-
rangeMin: number;
|
|
22
|
-
rangeMax: number;
|
|
23
|
-
prize: number;
|
|
24
|
-
availableQuantity: number;
|
|
25
|
-
amount: number;
|
|
26
|
-
}, options?: RpcOptions): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Claim Wheel Token
|
|
29
|
-
* @param amount - Amount of tokens to claim
|
|
30
|
-
* @param verifier - Verifier keypair
|
|
31
|
-
*
|
|
32
|
-
* @param options - RPC options
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
claimWheelToken(amount: number, verifier: Keypair, options?: RpcOptions): Promise<string>;
|
|
36
|
-
/**
|
|
37
|
-
* Spin Wheel
|
|
38
|
-
* @param args.isSol - Whether to pay with SOL or token
|
|
39
|
-
* @param args.verifier - Verifier keypair
|
|
40
|
-
* @param args.prize - Prize number
|
|
41
|
-
*
|
|
42
|
-
* @param options - RPC options
|
|
43
|
-
*
|
|
44
|
-
*/
|
|
45
|
-
spinWheel(args: {
|
|
46
|
-
isSol: boolean;
|
|
47
|
-
prizes: number[];
|
|
48
|
-
verifier: Keypair;
|
|
49
|
-
}, options?: RpcOptions): Promise<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Get Spin Wheel
|
|
52
|
-
*
|
|
53
|
-
*/
|
|
54
|
-
getSpinWheel(amount: number): Promise<number[]>;
|
|
55
|
-
/**
|
|
56
|
-
* Swap Wheel Token
|
|
57
|
-
* @param amount - Amount of tokens to buy
|
|
58
|
-
* @param options - RPC options
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
swapWheelToken(amount: number, options?: RpcOptions): Promise<string>;
|
|
62
|
-
}
|
package/dist/wheel.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
|
-
const pda_1 = require("./utils/pda");
|
|
17
|
-
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
18
|
-
const constants_1 = require("./utils/constants");
|
|
19
|
-
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
20
|
-
class Wheel {
|
|
21
|
-
constructor(program, provider) {
|
|
22
|
-
this.program = program;
|
|
23
|
-
this.provider = provider;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Add Whell Prize
|
|
27
|
-
* @param args.rangeMin - Range min to get prize
|
|
28
|
-
* @param args.rangeMax - Range max to get prize
|
|
29
|
-
* @param args.prize - Prize number it's indentifier
|
|
30
|
-
* @param args.availableQuantity - Amount available to get
|
|
31
|
-
* @param args.amount - Amount to send
|
|
32
|
-
*
|
|
33
|
-
* @param options - RPC options
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }, options) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const method = this.program.methods
|
|
39
|
-
.addWheelPrize({
|
|
40
|
-
name: constants_1.VALENT_SPIN_NAME,
|
|
41
|
-
rangeMin: new anchor_1.BN(rangeMin),
|
|
42
|
-
rangeMax: new anchor_1.BN(rangeMax),
|
|
43
|
-
prize: new anchor_1.BN(prize),
|
|
44
|
-
availableQuantity: new anchor_1.BN(availableQuantity),
|
|
45
|
-
amount: new anchor_1.BN(amount)
|
|
46
|
-
})
|
|
47
|
-
.accounts({
|
|
48
|
-
signer: this.provider.wallet.publicKey
|
|
49
|
-
});
|
|
50
|
-
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Claim Wheel Token
|
|
55
|
-
* @param amount - Amount of tokens to claim
|
|
56
|
-
* @param verifier - Verifier keypair
|
|
57
|
-
*
|
|
58
|
-
* @param options - RPC options
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
claimWheelToken(amount, verifier, options) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const ix = yield this.program.methods
|
|
64
|
-
.claimWheelToken({
|
|
65
|
-
name: constants_1.VALENT_SPIN_NAME,
|
|
66
|
-
amount: new anchor_1.BN(amount * Math.pow(10, 6))
|
|
67
|
-
})
|
|
68
|
-
.accounts({
|
|
69
|
-
signer: this.provider.wallet.publicKey,
|
|
70
|
-
verifier: verifier.publicKey,
|
|
71
|
-
mint: constants_1.WHEEL_MINT
|
|
72
|
-
})
|
|
73
|
-
.instruction();
|
|
74
|
-
return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, undefined, [], verifier);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Spin Wheel
|
|
79
|
-
* @param args.isSol - Whether to pay with SOL or token
|
|
80
|
-
* @param args.verifier - Verifier keypair
|
|
81
|
-
* @param args.prize - Prize number
|
|
82
|
-
*
|
|
83
|
-
* @param options - RPC options
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
spinWheel(args, options) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const wheelPDA = (0, pda_1.getWheelPDA)(this.program.programId, constants_1.VALENT_SPIN_NAME);
|
|
89
|
-
let ixs = [];
|
|
90
|
-
for (const prize of args.prizes) {
|
|
91
|
-
ixs.push(yield this.program.methods
|
|
92
|
-
.spinWheel({
|
|
93
|
-
isSol: args.isSol,
|
|
94
|
-
prize: new anchor_1.BN(prize)
|
|
95
|
-
})
|
|
96
|
-
.accounts({
|
|
97
|
-
signer: this.provider.wallet.publicKey,
|
|
98
|
-
verifier: constants_1.VERIFIER,
|
|
99
|
-
wheel: wheelPDA,
|
|
100
|
-
mint: constants_1.WHEEL_MINT
|
|
101
|
-
})
|
|
102
|
-
.instruction());
|
|
103
|
-
}
|
|
104
|
-
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, [], args.verifier);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get Spin Wheel
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
getSpinWheel(amount) {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const [wheel] = yield this.program.account.wheel.all();
|
|
114
|
-
const prizes = [];
|
|
115
|
-
for (let i = 0; i < amount; i++) {
|
|
116
|
-
const randomNumber = Math.floor(Math.random() * 1000000) + 1;
|
|
117
|
-
const prize = wheel.account.prizes.find((p) => randomNumber >= p.rangeMin.toNumber() &&
|
|
118
|
-
randomNumber <= p.rangeMax.toNumber() &&
|
|
119
|
-
p.status.claimed);
|
|
120
|
-
if (!prize) {
|
|
121
|
-
prizes.push(999);
|
|
122
|
-
}
|
|
123
|
-
prizes.push(prize.prize.toNumber());
|
|
124
|
-
}
|
|
125
|
-
return prizes;
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Swap Wheel Token
|
|
130
|
-
* @param amount - Amount of tokens to buy
|
|
131
|
-
* @param options - RPC options
|
|
132
|
-
*
|
|
133
|
-
*/
|
|
134
|
-
swapWheelToken(amount, options) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const method = this.program.methods
|
|
137
|
-
.swapWheelToken({
|
|
138
|
-
name: constants_1.VALENT_SPIN_NAME,
|
|
139
|
-
amount: new anchor_1.BN(amount)
|
|
140
|
-
})
|
|
141
|
-
.accounts({
|
|
142
|
-
signer: this.provider.wallet.publicKey,
|
|
143
|
-
mint: constants_1.WHEEL_MINT
|
|
144
|
-
});
|
|
145
|
-
return (0, sendTransactionWithOptions_1.default)(method, options);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
exports.default = Wheel;
|