@triadxyz/triad-protocol 4.1.9 → 4.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/customer.d.ts +8 -1
- package/dist/customer.js +23 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +135 -0
- package/dist/types/customer.d.ts +5 -0
- package/dist/types/idl_triad_protocol.json +6 -3
- package/dist/types/triad_protocol.d.ts +6 -3
- package/dist/utils/feeCalculator.d.ts +0 -8
- package/dist/utils/feeCalculator.js +3 -32
- package/package.json +1 -1
package/dist/customer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { PublicKey } from '@solana/web3.js';
|
|
|
2
2
|
import { Program } from '@coral-xyz/anchor';
|
|
3
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
4
4
|
import { RpcOptions } from './types';
|
|
5
|
-
import { CreateCustomerArgs } from './types/customer';
|
|
5
|
+
import { CreateCustomerArgs, UpdateCustomerArgs } from './types/customer';
|
|
6
6
|
export default class Customer {
|
|
7
7
|
private program;
|
|
8
8
|
private rpcOptions;
|
|
@@ -30,4 +30,11 @@ export default class Customer {
|
|
|
30
30
|
* @param args.feeBps - The fee in basis points of the customer
|
|
31
31
|
*/
|
|
32
32
|
createCustomer({ id, name, authority, feeRecipient, feeBps, marketFeeBps, payoutFeeBps }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
33
|
+
/**
|
|
34
|
+
* Update Customer
|
|
35
|
+
* @param args.customerId - The ID of the customer
|
|
36
|
+
* @param args.marketFeeBps - The market fee in basis points of the customer
|
|
37
|
+
* @param args.payoutFeeBps - The payout fee in basis points of the customer
|
|
38
|
+
*/
|
|
39
|
+
updateCustomer({ customerId, marketFeeBps, payoutFeeBps }: UpdateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
33
40
|
}
|
package/dist/customer.js
CHANGED
|
@@ -83,5 +83,28 @@ class Customer {
|
|
|
83
83
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Update Customer
|
|
88
|
+
* @param args.customerId - The ID of the customer
|
|
89
|
+
* @param args.marketFeeBps - The market fee in basis points of the customer
|
|
90
|
+
* @param args.payoutFeeBps - The payout fee in basis points of the customer
|
|
91
|
+
*/
|
|
92
|
+
updateCustomer({ customerId, marketFeeBps, payoutFeeBps }) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const ixs = [
|
|
95
|
+
yield this.program.methods
|
|
96
|
+
.updateCustomer({
|
|
97
|
+
customerId,
|
|
98
|
+
marketFeeBps: marketFeeBps ? marketFeeBps : null,
|
|
99
|
+
payoutFeeBps: payoutFeeBps ? payoutFeeBps : null
|
|
100
|
+
})
|
|
101
|
+
.accounts({
|
|
102
|
+
signer: this.program.provider.publicKey
|
|
103
|
+
})
|
|
104
|
+
.instruction()
|
|
105
|
+
];
|
|
106
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
86
109
|
}
|
|
87
110
|
exports.default = Customer;
|
package/dist/index.d.ts
CHANGED
|
@@ -190,4 +190,33 @@ export default class TriadProtocol {
|
|
|
190
190
|
* @param amount - Amount to burn
|
|
191
191
|
*/
|
|
192
192
|
burnTriad(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
193
|
+
/**
|
|
194
|
+
* Create and Resolve Pyth Market
|
|
195
|
+
* @param toResolve - Market to resolve
|
|
196
|
+
* @param toResolve.marketId - Market ID
|
|
197
|
+
* @param toResolve.winningDirection - Winning direction
|
|
198
|
+
* @param toResolve.poolId - Pool ID
|
|
199
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
200
|
+
* @param market - Market to create
|
|
201
|
+
* @param market.marketId - Market ID
|
|
202
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
203
|
+
* @param market.direction - Direction of the market
|
|
204
|
+
* @param market.customer - The customer of the market
|
|
205
|
+
* @param market.poolId - The ID of the pool
|
|
206
|
+
*/
|
|
207
|
+
createAndResolvePythMarket(toResolve: UpdateMarketWinningDirectionArgs['markets'][0], market: CreateMarketPythArgs['markets'][0]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
208
|
+
/**
|
|
209
|
+
* Create and Resolve Market
|
|
210
|
+
* @param toResolve - Market to resolve
|
|
211
|
+
* @param toResolve.marketId - Market ID
|
|
212
|
+
* @param toResolve.winningDirection - Winning direction
|
|
213
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
214
|
+
* @param market - Market to create
|
|
215
|
+
* @param market.marketId - Market ID
|
|
216
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
217
|
+
* @param market.direction - Direction of the market
|
|
218
|
+
* @param market.customer - The customer of the market
|
|
219
|
+
* @param market.poolId - The ID of the pool
|
|
220
|
+
*/
|
|
221
|
+
createAndResolveMarket(toResolve: UpdateMarketWinningDirectionArgs['markets'][0], market: CreateMarketArgs['markets'][0], customer: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
193
222
|
}
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const bn_js_1 = __importDefault(require("bn.js"));
|
|
|
32
32
|
const bs58_1 = __importDefault(require("bs58"));
|
|
33
33
|
const helpers_1 = require("./utils/helpers");
|
|
34
34
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
35
|
+
const types_1 = require("./types");
|
|
35
36
|
const constants_1 = require("./utils/constants");
|
|
36
37
|
const helpers_2 = require("./utils/helpers");
|
|
37
38
|
const pda_1 = require("./utils/pda");
|
|
@@ -577,5 +578,139 @@ class TriadProtocol {
|
|
|
577
578
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
578
579
|
});
|
|
579
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Create and Resolve Pyth Market
|
|
583
|
+
* @param toResolve - Market to resolve
|
|
584
|
+
* @param toResolve.marketId - Market ID
|
|
585
|
+
* @param toResolve.winningDirection - Winning direction
|
|
586
|
+
* @param toResolve.poolId - Pool ID
|
|
587
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
588
|
+
* @param market - Market to create
|
|
589
|
+
* @param market.marketId - Market ID
|
|
590
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
591
|
+
* @param market.direction - Direction of the market
|
|
592
|
+
* @param market.customer - The customer of the market
|
|
593
|
+
* @param market.poolId - The ID of the pool
|
|
594
|
+
*/
|
|
595
|
+
createAndResolvePythMarket(toResolve, market) {
|
|
596
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
+
const ixs = [];
|
|
598
|
+
const marketInfo = yield this.getMarketById(toResolve.marketId);
|
|
599
|
+
if (marketInfo.winningDirection === types_1.WinningDirection.NONE) {
|
|
600
|
+
ixs.push(yield this.program.methods
|
|
601
|
+
.updateMarketWinningDirection(toResolve.winningDirection)
|
|
602
|
+
.accounts({
|
|
603
|
+
signer: this.program.provider.publicKey,
|
|
604
|
+
pool: toResolve.poolId
|
|
605
|
+
? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
|
|
606
|
+
: null,
|
|
607
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
|
|
608
|
+
})
|
|
609
|
+
.instruction());
|
|
610
|
+
if (toResolve.withPayout) {
|
|
611
|
+
ixs.push(yield this.program.methods
|
|
612
|
+
.updateMarketPayout(true)
|
|
613
|
+
.accounts({
|
|
614
|
+
signer: this.program.provider.publicKey,
|
|
615
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
|
|
616
|
+
})
|
|
617
|
+
.instruction());
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
const feedPDA = (0, helpers_2.getPriceFeedAccountForProgram)(market.feedId);
|
|
621
|
+
ixs.push(yield this.program.methods
|
|
622
|
+
.createMarketPyth({
|
|
623
|
+
marketId: new bn_js_1.default(market.marketId),
|
|
624
|
+
resolveIn: new bn_js_1.default(market.resolveIn),
|
|
625
|
+
direction: market.direction
|
|
626
|
+
})
|
|
627
|
+
.accounts({
|
|
628
|
+
signer: this.program.provider.publicKey,
|
|
629
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
630
|
+
pool: market.poolId
|
|
631
|
+
? (0, pda_1.getPoolPDA)(this.program.programId, market.poolId)
|
|
632
|
+
: null,
|
|
633
|
+
customer: market.customer,
|
|
634
|
+
priceUpdate: feedPDA
|
|
635
|
+
})
|
|
636
|
+
.instruction());
|
|
637
|
+
ixs.push(yield this.program.methods
|
|
638
|
+
.createOrderBook(new bn_js_1.default(market.marketId))
|
|
639
|
+
.accounts({
|
|
640
|
+
signer: this.program.provider.publicKey,
|
|
641
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
642
|
+
})
|
|
643
|
+
.instruction());
|
|
644
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Create and Resolve Market
|
|
649
|
+
* @param toResolve - Market to resolve
|
|
650
|
+
* @param toResolve.marketId - Market ID
|
|
651
|
+
* @param toResolve.winningDirection - Winning direction
|
|
652
|
+
* @param toResolve.withPayout - Whether to update market payout
|
|
653
|
+
* @param market - Market to create
|
|
654
|
+
* @param market.marketId - Market ID
|
|
655
|
+
* @param market.resolveIn - Time to add for resolver the market in seconds
|
|
656
|
+
* @param market.direction - Direction of the market
|
|
657
|
+
* @param market.customer - The customer of the market
|
|
658
|
+
* @param market.poolId - The ID of the pool
|
|
659
|
+
*/
|
|
660
|
+
createAndResolveMarket(toResolve, market, customer) {
|
|
661
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
662
|
+
const ixs = [];
|
|
663
|
+
const marketInfo = yield this.getMarketById(toResolve.marketId);
|
|
664
|
+
if (marketInfo.winningDirection === types_1.WinningDirection.NONE) {
|
|
665
|
+
ixs.push(yield this.program.methods
|
|
666
|
+
.updateMarketWinningDirection(toResolve.winningDirection)
|
|
667
|
+
.accounts({
|
|
668
|
+
signer: this.program.provider.publicKey,
|
|
669
|
+
pool: toResolve.poolId
|
|
670
|
+
? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
|
|
671
|
+
: null,
|
|
672
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
|
|
673
|
+
})
|
|
674
|
+
.instruction());
|
|
675
|
+
if (toResolve.withPayout) {
|
|
676
|
+
ixs.push(yield this.program.methods
|
|
677
|
+
.updateMarketPayout(true)
|
|
678
|
+
.accounts({
|
|
679
|
+
signer: this.program.provider.publicKey,
|
|
680
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, toResolve.marketId)
|
|
681
|
+
})
|
|
682
|
+
.instruction());
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
ixs.push(yield this.program.methods
|
|
686
|
+
.createMarket({
|
|
687
|
+
marketId: new bn_js_1.default(market.marketId),
|
|
688
|
+
question: (0, helpers_1.encodeString)(market.question, 80),
|
|
689
|
+
marketStart: new bn_js_1.default(market.startTime),
|
|
690
|
+
marketEnd: new bn_js_1.default(market.endTime),
|
|
691
|
+
feeBps: market.feeBps,
|
|
692
|
+
payoutFee: market.payoutFee,
|
|
693
|
+
preMarketEndTs: new bn_js_1.default(0),
|
|
694
|
+
preOrdersAvailable: new bn_js_1.default(0)
|
|
695
|
+
})
|
|
696
|
+
.accounts({
|
|
697
|
+
signer: this.program.provider.publicKey,
|
|
698
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
699
|
+
pool: toResolve.poolId
|
|
700
|
+
? (0, pda_1.getPoolPDA)(this.program.programId, toResolve.poolId)
|
|
701
|
+
: null,
|
|
702
|
+
customer
|
|
703
|
+
})
|
|
704
|
+
.instruction());
|
|
705
|
+
ixs.push(yield this.program.methods
|
|
706
|
+
.createOrderBook(new bn_js_1.default(market.marketId))
|
|
707
|
+
.accounts({
|
|
708
|
+
signer: this.program.provider.publicKey,
|
|
709
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, market.marketId)
|
|
710
|
+
})
|
|
711
|
+
.instruction());
|
|
712
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
580
715
|
}
|
|
581
716
|
exports.default = TriadProtocol;
|
package/dist/types/customer.d.ts
CHANGED
|
@@ -2164,9 +2164,8 @@
|
|
|
2164
2164
|
"value": [99, 117, 115, 116, 111, 109, 101, 114]
|
|
2165
2165
|
},
|
|
2166
2166
|
{
|
|
2167
|
-
"kind": "
|
|
2168
|
-
"path": "
|
|
2169
|
-
"account": "Customer"
|
|
2167
|
+
"kind": "arg",
|
|
2168
|
+
"path": "args.customer_id"
|
|
2170
2169
|
}
|
|
2171
2170
|
]
|
|
2172
2171
|
}
|
|
@@ -4521,6 +4520,10 @@
|
|
|
4521
4520
|
"type": {
|
|
4522
4521
|
"kind": "struct",
|
|
4523
4522
|
"fields": [
|
|
4523
|
+
{
|
|
4524
|
+
"name": "customer_id",
|
|
4525
|
+
"type": "u16"
|
|
4526
|
+
},
|
|
4524
4527
|
{
|
|
4525
4528
|
"name": "market_fee_bps",
|
|
4526
4529
|
"type": {
|
|
@@ -3070,9 +3070,8 @@ export type TriadProtocol = {
|
|
|
3070
3070
|
value: [99, 117, 115, 116, 111, 109, 101, 114];
|
|
3071
3071
|
},
|
|
3072
3072
|
{
|
|
3073
|
-
kind: '
|
|
3074
|
-
path: '
|
|
3075
|
-
account: 'customer';
|
|
3073
|
+
kind: 'arg';
|
|
3074
|
+
path: 'args.customer_id';
|
|
3076
3075
|
}
|
|
3077
3076
|
];
|
|
3078
3077
|
};
|
|
@@ -5525,6 +5524,10 @@ export type TriadProtocol = {
|
|
|
5525
5524
|
type: {
|
|
5526
5525
|
kind: 'struct';
|
|
5527
5526
|
fields: [
|
|
5527
|
+
{
|
|
5528
|
+
name: 'customerId';
|
|
5529
|
+
type: 'u16';
|
|
5530
|
+
},
|
|
5528
5531
|
{
|
|
5529
5532
|
name: 'marketFeeBps';
|
|
5530
5533
|
type: {
|
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
* Returns fee in basis points (bps)
|
|
4
4
|
*/
|
|
5
5
|
export declare function calculateDynamicFeeBps(price: number, feeBps: number, customerMarketFeeBps: number): number;
|
|
6
|
-
/**
|
|
7
|
-
* Calculate tiered fixed fee based on entry amount (USDC)
|
|
8
|
-
*/
|
|
9
|
-
export declare function calculateFixedFee(amount: number): number;
|
|
10
6
|
/**
|
|
11
7
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
12
8
|
*/
|
|
@@ -24,8 +20,6 @@ export declare function simulateBuyOrder(amount: number, price: number, feeBps:
|
|
|
24
20
|
sharesReceived: number;
|
|
25
21
|
feeAmount: number;
|
|
26
22
|
feePercentage: number;
|
|
27
|
-
fixedFee: number;
|
|
28
|
-
volumeFee: number;
|
|
29
23
|
realEntryPrice: number;
|
|
30
24
|
};
|
|
31
25
|
/**
|
|
@@ -37,7 +31,5 @@ export declare function simulateSellOrder(shares: number, price: number, feeBps:
|
|
|
37
31
|
sharesReceived: number;
|
|
38
32
|
feeAmount: number;
|
|
39
33
|
feePercentage: number;
|
|
40
|
-
fixedFee: number;
|
|
41
|
-
volumeFee: number;
|
|
42
34
|
realEntryPrice: number;
|
|
43
35
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.
|
|
3
|
+
exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.calculateDynamicFeeBps = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Calculate dynamic fee based on price
|
|
6
6
|
* Returns fee in basis points (bps)
|
|
@@ -13,28 +13,6 @@ function calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps) {
|
|
|
13
13
|
return Math.max(Math.floor(((990000 - internalPrice) * 1900) / internalPrice), 90);
|
|
14
14
|
}
|
|
15
15
|
exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
|
|
16
|
-
/**
|
|
17
|
-
* Calculate tiered fixed fee based on entry amount (USDC)
|
|
18
|
-
*/
|
|
19
|
-
function calculateFixedFee(amount) {
|
|
20
|
-
const internalAmount = Math.floor(amount * 1000000);
|
|
21
|
-
if (internalAmount >= 100000000) {
|
|
22
|
-
return 2.5;
|
|
23
|
-
}
|
|
24
|
-
else if (internalAmount >= 50000000) {
|
|
25
|
-
return 1.5;
|
|
26
|
-
}
|
|
27
|
-
else if (internalAmount >= 20000000) {
|
|
28
|
-
return 0.75;
|
|
29
|
-
}
|
|
30
|
-
else if (internalAmount >= 5000000) {
|
|
31
|
-
return 0.3;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return 0.15;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.calculateFixedFee = calculateFixedFee;
|
|
38
16
|
/**
|
|
39
17
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
40
18
|
*/
|
|
@@ -61,10 +39,8 @@ exports.applySellFee = applySellFee;
|
|
|
61
39
|
* Simulate a buy order with given amount and price
|
|
62
40
|
*/
|
|
63
41
|
function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
|
|
64
|
-
const fixedFee = calculateFixedFee(amount);
|
|
65
|
-
const amountAfterFixedFee = amount - fixedFee;
|
|
66
42
|
const effectivePrice = applyBuyFee(price, feeBps, customerMarketFeeBps);
|
|
67
|
-
const sharesReceived =
|
|
43
|
+
const sharesReceived = amount / effectivePrice;
|
|
68
44
|
const valueAtOriginalPrice = sharesReceived * price;
|
|
69
45
|
const feeAmount = amount - valueAtOriginalPrice;
|
|
70
46
|
return {
|
|
@@ -73,8 +49,6 @@ function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
|
|
|
73
49
|
sharesReceived,
|
|
74
50
|
feeAmount,
|
|
75
51
|
feePercentage: (feeAmount / amount) * 100,
|
|
76
|
-
fixedFee,
|
|
77
|
-
volumeFee: feeAmount - fixedFee,
|
|
78
52
|
realEntryPrice: amount / sharesReceived
|
|
79
53
|
};
|
|
80
54
|
}
|
|
@@ -86,8 +60,7 @@ function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
|
|
|
86
60
|
const effectivePrice = applySellFee(price, feeBps, customerMarketFeeBps);
|
|
87
61
|
const amountToReceiveBeforeFixed = shares * effectivePrice;
|
|
88
62
|
const valueAtOriginalPrice = shares * price;
|
|
89
|
-
const
|
|
90
|
-
const amountReceived = amountToReceiveBeforeFixed - fixedFee;
|
|
63
|
+
const amountReceived = amountToReceiveBeforeFixed;
|
|
91
64
|
const feeAmount = valueAtOriginalPrice - amountReceived;
|
|
92
65
|
return {
|
|
93
66
|
entryPrice: price,
|
|
@@ -95,8 +68,6 @@ function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
|
|
|
95
68
|
sharesReceived: shares,
|
|
96
69
|
feeAmount,
|
|
97
70
|
feePercentage: (feeAmount / valueAtOriginalPrice) * 100,
|
|
98
|
-
fixedFee,
|
|
99
|
-
volumeFee: feeAmount - fixedFee,
|
|
100
71
|
realEntryPrice: amountReceived / shares
|
|
101
72
|
};
|
|
102
73
|
}
|