@triadxyz/triad-protocol 4.1.8 → 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 +9 -2
- package/dist/customer.js +34 -6
- package/dist/index.d.ts +29 -0
- package/dist/index.js +135 -0
- package/dist/trade.d.ts +2 -2
- package/dist/trade.js +10 -6
- package/dist/types/customer.d.ts +9 -0
- package/dist/types/idl_triad_protocol.json +90 -1
- package/dist/types/trade.d.ts +2 -0
- package/dist/types/triad_protocol.d.ts +90 -1
- package/dist/utils/feeCalculator.d.ts +7 -5
- package/dist/utils/feeCalculator.js +16 -15
- package/dist/utils/helpers.d.ts +2 -1
- package/dist/utils/helpers.js +19 -1
- 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;
|
|
@@ -29,5 +29,12 @@ export default class Customer {
|
|
|
29
29
|
* @param args.feeRecipient - The fee recipient of the customer
|
|
30
30
|
* @param args.feeBps - The fee in basis points of the customer
|
|
31
31
|
*/
|
|
32
|
-
createCustomer({ id, name, authority, feeRecipient, feeBps }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
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
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const helpers_1 = require("./utils/helpers");
|
|
16
16
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
17
|
-
const pda_1 = require("./utils/pda");
|
|
18
17
|
class Customer {
|
|
19
18
|
constructor(program, rpcOptions) {
|
|
20
19
|
this.program = program;
|
|
@@ -52,9 +51,7 @@ class Customer {
|
|
|
52
51
|
*/
|
|
53
52
|
getCustomerById(customerId) {
|
|
54
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
|
|
56
|
-
const customer = yield this.program.account.customer.fetch(customerPDA, this.rpcOptions.commitment);
|
|
57
|
-
return (0, helpers_1.formatCustomer)(customer, customerPDA);
|
|
54
|
+
return (0, helpers_1.getCustomerById)(this.program, customerId);
|
|
58
55
|
});
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
@@ -65,11 +62,42 @@ class Customer {
|
|
|
65
62
|
* @param args.feeRecipient - The fee recipient of the customer
|
|
66
63
|
* @param args.feeBps - The fee in basis points of the customer
|
|
67
64
|
*/
|
|
68
|
-
createCustomer({ id, name, authority, feeRecipient, feeBps }) {
|
|
65
|
+
createCustomer({ id, name, authority, feeRecipient, feeBps, marketFeeBps, payoutFeeBps }) {
|
|
69
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
67
|
const ixs = [
|
|
71
68
|
yield this.program.methods
|
|
72
|
-
.createCustomer({
|
|
69
|
+
.createCustomer({
|
|
70
|
+
id,
|
|
71
|
+
name,
|
|
72
|
+
authority,
|
|
73
|
+
feeRecipient,
|
|
74
|
+
feeBps,
|
|
75
|
+
marketFeeBps,
|
|
76
|
+
payoutFeeBps
|
|
77
|
+
})
|
|
78
|
+
.accounts({
|
|
79
|
+
signer: this.program.provider.publicKey
|
|
80
|
+
})
|
|
81
|
+
.instruction()
|
|
82
|
+
];
|
|
83
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
84
|
+
});
|
|
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
|
+
})
|
|
73
101
|
.accounts({
|
|
74
102
|
signer: this.program.provider.publicKey
|
|
75
103
|
})
|
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/trade.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export default class Trade {
|
|
|
64
64
|
* @param args.amount - The amount of the Order
|
|
65
65
|
* @param args.orderDirection - The direction of the Order
|
|
66
66
|
*/
|
|
67
|
-
marketBidOrder({ marketId, amount, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
67
|
+
marketBidOrder({ marketId, amount, customerId, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
68
68
|
/**
|
|
69
69
|
* Market Ask Order
|
|
70
70
|
* @param args.marketId - The ID of the Market
|
|
@@ -72,7 +72,7 @@ export default class Trade {
|
|
|
72
72
|
* @param args.bookOrderBidId - The ID of the Bid Order
|
|
73
73
|
* @param args.orderDirection - The direction of the Order
|
|
74
74
|
*/
|
|
75
|
-
marketAskOrder({ marketId, shares, orderDirection }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
75
|
+
marketAskOrder({ marketId, shares, orderDirection, customerId }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
76
76
|
/**
|
|
77
77
|
* Payout Order
|
|
78
78
|
* @param args.marketId - The ID of the Market
|
package/dist/trade.js
CHANGED
|
@@ -196,11 +196,12 @@ class Trade {
|
|
|
196
196
|
* @param args.amount - The amount of the Order
|
|
197
197
|
* @param args.orderDirection - The direction of the Order
|
|
198
198
|
*/
|
|
199
|
-
marketBidOrder({ marketId, amount, orderDirection }) {
|
|
199
|
+
marketBidOrder({ marketId, amount, customerId, orderDirection }) {
|
|
200
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
201
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
202
202
|
const ixs = [];
|
|
203
203
|
const addressLookupTableAccounts = [];
|
|
204
|
+
const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
|
|
204
205
|
const orderBook = yield this.getOrderBook(marketId);
|
|
205
206
|
let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
|
|
206
207
|
const orders = Object.keys(orderDirection)[0] === 'hype'
|
|
@@ -215,7 +216,7 @@ class Trade {
|
|
|
215
216
|
}
|
|
216
217
|
const orderPrice = new bn_js_1.default(order.price);
|
|
217
218
|
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
218
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500);
|
|
219
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500, customer.marketFeeBps);
|
|
219
220
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
220
221
|
const maxSharesForPrice = remainingUSDC
|
|
221
222
|
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
@@ -244,7 +245,8 @@ class Trade {
|
|
|
244
245
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
245
246
|
bookOrderAskAuthority: new web3_js_1.PublicKey(order.authority),
|
|
246
247
|
order: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
247
|
-
oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
|
|
248
|
+
oppositeOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection)),
|
|
249
|
+
customer: (0, pda_1.getCustomerPDA)(this.program.programId, customerId)
|
|
248
250
|
})
|
|
249
251
|
.instruction());
|
|
250
252
|
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
@@ -262,11 +264,12 @@ class Trade {
|
|
|
262
264
|
* @param args.bookOrderBidId - The ID of the Bid Order
|
|
263
265
|
* @param args.orderDirection - The direction of the Order
|
|
264
266
|
*/
|
|
265
|
-
marketAskOrder({ marketId, shares, orderDirection }) {
|
|
267
|
+
marketAskOrder({ marketId, shares, orderDirection, customerId }) {
|
|
266
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
269
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
268
270
|
const ixs = [];
|
|
269
271
|
const addressLookupTableAccounts = [];
|
|
272
|
+
const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
|
|
270
273
|
const orderBook = yield this.getOrderBook(marketId);
|
|
271
274
|
const bidOrders = Object.keys(orderDirection)[0] === 'hype'
|
|
272
275
|
? orderBook.hype.bid
|
|
@@ -287,7 +290,7 @@ class Trade {
|
|
|
287
290
|
continue;
|
|
288
291
|
remainingShares = remainingShares.sub(sharesToSell);
|
|
289
292
|
const orderPrice = new bn_js_1.default(order.price);
|
|
290
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500);
|
|
293
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500, customer.marketFeeBps);
|
|
291
294
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
292
295
|
amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
|
|
293
296
|
ixs.push(yield this.program.methods
|
|
@@ -304,7 +307,8 @@ class Trade {
|
|
|
304
307
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
305
308
|
marketAta: (0, pda_1.getTokenATA)(marketPDA, constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID),
|
|
306
309
|
bidOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
307
|
-
askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
|
|
310
|
+
askOrder: (0, pda_1.getOrderPDA)(this.program.programId, this.program.provider.publicKey, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
311
|
+
customer: customer.address
|
|
308
312
|
})
|
|
309
313
|
.instruction());
|
|
310
314
|
}
|
package/dist/types/customer.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type Customer = {
|
|
|
7
7
|
feeBps: number;
|
|
8
8
|
isVerified: boolean;
|
|
9
9
|
address: string;
|
|
10
|
+
marketFeeBps: number;
|
|
11
|
+
payoutFeeBps: number;
|
|
10
12
|
};
|
|
11
13
|
export type CreateCustomerArgs = {
|
|
12
14
|
id: number;
|
|
@@ -14,4 +16,11 @@ export type CreateCustomerArgs = {
|
|
|
14
16
|
authority: PublicKey;
|
|
15
17
|
feeRecipient: PublicKey;
|
|
16
18
|
feeBps: number;
|
|
19
|
+
marketFeeBps: number;
|
|
20
|
+
payoutFeeBps: number;
|
|
21
|
+
};
|
|
22
|
+
export type UpdateCustomerArgs = {
|
|
23
|
+
customerId: number;
|
|
24
|
+
marketFeeBps?: number;
|
|
25
|
+
payoutFeeBps?: number;
|
|
17
26
|
};
|
|
@@ -1317,6 +1317,10 @@
|
|
|
1317
1317
|
"name": "order_book",
|
|
1318
1318
|
"writable": true
|
|
1319
1319
|
},
|
|
1320
|
+
{
|
|
1321
|
+
"name": "customer",
|
|
1322
|
+
"writable": true
|
|
1323
|
+
},
|
|
1320
1324
|
{
|
|
1321
1325
|
"name": "ask_order",
|
|
1322
1326
|
"writable": true
|
|
@@ -1412,6 +1416,10 @@
|
|
|
1412
1416
|
"name": "order_book",
|
|
1413
1417
|
"writable": true
|
|
1414
1418
|
},
|
|
1419
|
+
{
|
|
1420
|
+
"name": "customer",
|
|
1421
|
+
"writable": true
|
|
1422
|
+
},
|
|
1415
1423
|
{
|
|
1416
1424
|
"name": "order",
|
|
1417
1425
|
"writable": true
|
|
@@ -2137,6 +2145,47 @@
|
|
|
2137
2145
|
],
|
|
2138
2146
|
"args": []
|
|
2139
2147
|
},
|
|
2148
|
+
{
|
|
2149
|
+
"name": "update_customer",
|
|
2150
|
+
"discriminator": [158, 118, 103, 177, 241, 229, 169, 124],
|
|
2151
|
+
"accounts": [
|
|
2152
|
+
{
|
|
2153
|
+
"name": "signer",
|
|
2154
|
+
"writable": true,
|
|
2155
|
+
"signer": true
|
|
2156
|
+
},
|
|
2157
|
+
{
|
|
2158
|
+
"name": "customer",
|
|
2159
|
+
"writable": true,
|
|
2160
|
+
"pda": {
|
|
2161
|
+
"seeds": [
|
|
2162
|
+
{
|
|
2163
|
+
"kind": "const",
|
|
2164
|
+
"value": [99, 117, 115, 116, 111, 109, 101, 114]
|
|
2165
|
+
},
|
|
2166
|
+
{
|
|
2167
|
+
"kind": "arg",
|
|
2168
|
+
"path": "args.customer_id"
|
|
2169
|
+
}
|
|
2170
|
+
]
|
|
2171
|
+
}
|
|
2172
|
+
},
|
|
2173
|
+
{
|
|
2174
|
+
"name": "system_program",
|
|
2175
|
+
"address": "11111111111111111111111111111111"
|
|
2176
|
+
}
|
|
2177
|
+
],
|
|
2178
|
+
"args": [
|
|
2179
|
+
{
|
|
2180
|
+
"name": "args",
|
|
2181
|
+
"type": {
|
|
2182
|
+
"defined": {
|
|
2183
|
+
"name": "UpdateCustomerArgs"
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
]
|
|
2188
|
+
},
|
|
2140
2189
|
{
|
|
2141
2190
|
"name": "update_market_end",
|
|
2142
2191
|
"discriminator": [10, 188, 22, 219, 206, 83, 67, 31],
|
|
@@ -3131,6 +3180,14 @@
|
|
|
3131
3180
|
{
|
|
3132
3181
|
"name": "fee_bps",
|
|
3133
3182
|
"type": "u16"
|
|
3183
|
+
},
|
|
3184
|
+
{
|
|
3185
|
+
"name": "market_fee_bps",
|
|
3186
|
+
"type": "u16"
|
|
3187
|
+
},
|
|
3188
|
+
{
|
|
3189
|
+
"name": "payout_fee_bps",
|
|
3190
|
+
"type": "u16"
|
|
3134
3191
|
}
|
|
3135
3192
|
]
|
|
3136
3193
|
}
|
|
@@ -3272,10 +3329,18 @@
|
|
|
3272
3329
|
"name": "is_verified",
|
|
3273
3330
|
"type": "bool"
|
|
3274
3331
|
},
|
|
3332
|
+
{
|
|
3333
|
+
"name": "market_fee_bps",
|
|
3334
|
+
"type": "u16"
|
|
3335
|
+
},
|
|
3336
|
+
{
|
|
3337
|
+
"name": "payout_fee_bps",
|
|
3338
|
+
"type": "u16"
|
|
3339
|
+
},
|
|
3275
3340
|
{
|
|
3276
3341
|
"name": "padding",
|
|
3277
3342
|
"type": {
|
|
3278
|
-
"array": ["u8",
|
|
3343
|
+
"array": ["u8", 25]
|
|
3279
3344
|
}
|
|
3280
3345
|
}
|
|
3281
3346
|
]
|
|
@@ -4450,6 +4515,30 @@
|
|
|
4450
4515
|
]
|
|
4451
4516
|
}
|
|
4452
4517
|
},
|
|
4518
|
+
{
|
|
4519
|
+
"name": "UpdateCustomerArgs",
|
|
4520
|
+
"type": {
|
|
4521
|
+
"kind": "struct",
|
|
4522
|
+
"fields": [
|
|
4523
|
+
{
|
|
4524
|
+
"name": "customer_id",
|
|
4525
|
+
"type": "u16"
|
|
4526
|
+
},
|
|
4527
|
+
{
|
|
4528
|
+
"name": "market_fee_bps",
|
|
4529
|
+
"type": {
|
|
4530
|
+
"option": "u16"
|
|
4531
|
+
}
|
|
4532
|
+
},
|
|
4533
|
+
{
|
|
4534
|
+
"name": "payout_fee_bps",
|
|
4535
|
+
"type": {
|
|
4536
|
+
"option": "u16"
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
]
|
|
4540
|
+
}
|
|
4541
|
+
},
|
|
4453
4542
|
{
|
|
4454
4543
|
"name": "VerificationLevel",
|
|
4455
4544
|
"docs": [
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -35,10 +35,12 @@ export type CancelAskOrderArgs = {
|
|
|
35
35
|
export type MarketBidOrderArgs = {
|
|
36
36
|
marketId: number;
|
|
37
37
|
amount: number;
|
|
38
|
+
customerId: number;
|
|
38
39
|
orderDirection: OrderDirectionEncoded;
|
|
39
40
|
};
|
|
40
41
|
export type MarketAskOrderArgs = {
|
|
41
42
|
marketId: number;
|
|
42
43
|
shares: number;
|
|
44
|
+
customerId: number;
|
|
43
45
|
orderDirection: OrderDirectionEncoded;
|
|
44
46
|
};
|
|
@@ -1851,6 +1851,10 @@ export type TriadProtocol = {
|
|
|
1851
1851
|
name: 'orderBook';
|
|
1852
1852
|
writable: true;
|
|
1853
1853
|
},
|
|
1854
|
+
{
|
|
1855
|
+
name: 'customer';
|
|
1856
|
+
writable: true;
|
|
1857
|
+
},
|
|
1854
1858
|
{
|
|
1855
1859
|
name: 'askOrder';
|
|
1856
1860
|
writable: true;
|
|
@@ -1975,6 +1979,10 @@ export type TriadProtocol = {
|
|
|
1975
1979
|
name: 'orderBook';
|
|
1976
1980
|
writable: true;
|
|
1977
1981
|
},
|
|
1982
|
+
{
|
|
1983
|
+
name: 'customer';
|
|
1984
|
+
writable: true;
|
|
1985
|
+
},
|
|
1978
1986
|
{
|
|
1979
1987
|
name: 'order';
|
|
1980
1988
|
writable: true;
|
|
@@ -3043,6 +3051,47 @@ export type TriadProtocol = {
|
|
|
3043
3051
|
];
|
|
3044
3052
|
args: [];
|
|
3045
3053
|
},
|
|
3054
|
+
{
|
|
3055
|
+
name: 'updateCustomer';
|
|
3056
|
+
discriminator: [158, 118, 103, 177, 241, 229, 169, 124];
|
|
3057
|
+
accounts: [
|
|
3058
|
+
{
|
|
3059
|
+
name: 'signer';
|
|
3060
|
+
writable: true;
|
|
3061
|
+
signer: true;
|
|
3062
|
+
},
|
|
3063
|
+
{
|
|
3064
|
+
name: 'customer';
|
|
3065
|
+
writable: true;
|
|
3066
|
+
pda: {
|
|
3067
|
+
seeds: [
|
|
3068
|
+
{
|
|
3069
|
+
kind: 'const';
|
|
3070
|
+
value: [99, 117, 115, 116, 111, 109, 101, 114];
|
|
3071
|
+
},
|
|
3072
|
+
{
|
|
3073
|
+
kind: 'arg';
|
|
3074
|
+
path: 'args.customer_id';
|
|
3075
|
+
}
|
|
3076
|
+
];
|
|
3077
|
+
};
|
|
3078
|
+
},
|
|
3079
|
+
{
|
|
3080
|
+
name: 'systemProgram';
|
|
3081
|
+
address: '11111111111111111111111111111111';
|
|
3082
|
+
}
|
|
3083
|
+
];
|
|
3084
|
+
args: [
|
|
3085
|
+
{
|
|
3086
|
+
name: 'args';
|
|
3087
|
+
type: {
|
|
3088
|
+
defined: {
|
|
3089
|
+
name: 'updateCustomerArgs';
|
|
3090
|
+
};
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
];
|
|
3094
|
+
},
|
|
3046
3095
|
{
|
|
3047
3096
|
name: 'updateMarketEnd';
|
|
3048
3097
|
discriminator: [10, 188, 22, 219, 206, 83, 67, 31];
|
|
@@ -4135,6 +4184,14 @@ export type TriadProtocol = {
|
|
|
4135
4184
|
{
|
|
4136
4185
|
name: 'feeBps';
|
|
4137
4186
|
type: 'u16';
|
|
4187
|
+
},
|
|
4188
|
+
{
|
|
4189
|
+
name: 'marketFeeBps';
|
|
4190
|
+
type: 'u16';
|
|
4191
|
+
},
|
|
4192
|
+
{
|
|
4193
|
+
name: 'payoutFeeBps';
|
|
4194
|
+
type: 'u16';
|
|
4138
4195
|
}
|
|
4139
4196
|
];
|
|
4140
4197
|
};
|
|
@@ -4276,10 +4333,18 @@ export type TriadProtocol = {
|
|
|
4276
4333
|
name: 'isVerified';
|
|
4277
4334
|
type: 'bool';
|
|
4278
4335
|
},
|
|
4336
|
+
{
|
|
4337
|
+
name: 'marketFeeBps';
|
|
4338
|
+
type: 'u16';
|
|
4339
|
+
},
|
|
4340
|
+
{
|
|
4341
|
+
name: 'payoutFeeBps';
|
|
4342
|
+
type: 'u16';
|
|
4343
|
+
},
|
|
4279
4344
|
{
|
|
4280
4345
|
name: 'padding';
|
|
4281
4346
|
type: {
|
|
4282
|
-
array: ['u8',
|
|
4347
|
+
array: ['u8', 25];
|
|
4283
4348
|
};
|
|
4284
4349
|
}
|
|
4285
4350
|
];
|
|
@@ -5454,6 +5519,30 @@ export type TriadProtocol = {
|
|
|
5454
5519
|
];
|
|
5455
5520
|
};
|
|
5456
5521
|
},
|
|
5522
|
+
{
|
|
5523
|
+
name: 'updateCustomerArgs';
|
|
5524
|
+
type: {
|
|
5525
|
+
kind: 'struct';
|
|
5526
|
+
fields: [
|
|
5527
|
+
{
|
|
5528
|
+
name: 'customerId';
|
|
5529
|
+
type: 'u16';
|
|
5530
|
+
},
|
|
5531
|
+
{
|
|
5532
|
+
name: 'marketFeeBps';
|
|
5533
|
+
type: {
|
|
5534
|
+
option: 'u16';
|
|
5535
|
+
};
|
|
5536
|
+
},
|
|
5537
|
+
{
|
|
5538
|
+
name: 'payoutFeeBps';
|
|
5539
|
+
type: {
|
|
5540
|
+
option: 'u16';
|
|
5541
|
+
};
|
|
5542
|
+
}
|
|
5543
|
+
];
|
|
5544
|
+
};
|
|
5545
|
+
},
|
|
5457
5546
|
{
|
|
5458
5547
|
name: 'verificationLevel';
|
|
5459
5548
|
docs: [
|
|
@@ -2,32 +2,34 @@
|
|
|
2
2
|
* Calculate dynamic fee based on price
|
|
3
3
|
* Returns fee in basis points (bps)
|
|
4
4
|
*/
|
|
5
|
-
export declare function calculateDynamicFeeBps(price: number, feeBps: number): number;
|
|
5
|
+
export declare function calculateDynamicFeeBps(price: number, feeBps: number, customerMarketFeeBps: number): number;
|
|
6
6
|
/**
|
|
7
7
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
8
8
|
*/
|
|
9
|
-
export declare function applyBuyFee(price: number, feeBps: number): number;
|
|
9
|
+
export declare function applyBuyFee(price: number, feeBps: number, customerMarketFeeBps: number): number;
|
|
10
10
|
/**
|
|
11
11
|
* Apply dynamic fee to price for sell orders (subtracts fee)
|
|
12
12
|
*/
|
|
13
|
-
export declare function applySellFee(price: number, feeBps: number): number;
|
|
13
|
+
export declare function applySellFee(price: number, feeBps: number, customerMarketFeeBps: number): number;
|
|
14
14
|
/**
|
|
15
15
|
* Simulate a buy order with given amount and price
|
|
16
16
|
*/
|
|
17
|
-
export declare function simulateBuyOrder(amount: number, price: number, feeBps: number): {
|
|
17
|
+
export declare function simulateBuyOrder(amount: number, price: number, feeBps: number, customerMarketFeeBps: number): {
|
|
18
18
|
entryPrice: number;
|
|
19
19
|
effectivePrice: number;
|
|
20
20
|
sharesReceived: number;
|
|
21
21
|
feeAmount: number;
|
|
22
22
|
feePercentage: number;
|
|
23
|
+
realEntryPrice: number;
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
25
26
|
* Simulate a sell order with given shares and price
|
|
26
27
|
*/
|
|
27
|
-
export declare function simulateSellOrder(shares: number, price: number, feeBps: number): {
|
|
28
|
+
export declare function simulateSellOrder(shares: number, price: number, feeBps: number, customerMarketFeeBps: number): {
|
|
28
29
|
entryPrice: number;
|
|
29
30
|
effectivePrice: number;
|
|
30
31
|
sharesReceived: number;
|
|
31
32
|
feeAmount: number;
|
|
32
33
|
feePercentage: number;
|
|
34
|
+
realEntryPrice: number;
|
|
33
35
|
};
|
|
@@ -5,10 +5,10 @@ exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = ex
|
|
|
5
5
|
* Calculate dynamic fee based on price
|
|
6
6
|
* Returns fee in basis points (bps)
|
|
7
7
|
*/
|
|
8
|
-
function calculateDynamicFeeBps(price, feeBps) {
|
|
8
|
+
function calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps) {
|
|
9
9
|
const internalPrice = price * Math.pow(10, 6);
|
|
10
10
|
if (internalPrice < 900000) {
|
|
11
|
-
return feeBps;
|
|
11
|
+
return feeBps + customerMarketFeeBps;
|
|
12
12
|
}
|
|
13
13
|
return Math.max(Math.floor(((990000 - internalPrice) * 1900) / internalPrice), 90);
|
|
14
14
|
}
|
|
@@ -16,8 +16,8 @@ exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
|
|
|
16
16
|
/**
|
|
17
17
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
18
18
|
*/
|
|
19
|
-
function applyBuyFee(price, feeBps) {
|
|
20
|
-
const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps);
|
|
19
|
+
function applyBuyFee(price, feeBps, customerMarketFeeBps) {
|
|
20
|
+
const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps);
|
|
21
21
|
const internalPrice = Math.floor(price * 1000000);
|
|
22
22
|
const effectiveInternalPrice = Math.floor((internalPrice * (10000 + dynamicFeeBps)) / 10000);
|
|
23
23
|
const clampedPrice = Math.min(effectiveInternalPrice, 999999);
|
|
@@ -27,8 +27,8 @@ exports.applyBuyFee = applyBuyFee;
|
|
|
27
27
|
/**
|
|
28
28
|
* Apply dynamic fee to price for sell orders (subtracts fee)
|
|
29
29
|
*/
|
|
30
|
-
function applySellFee(price, feeBps) {
|
|
31
|
-
const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps);
|
|
30
|
+
function applySellFee(price, feeBps, customerMarketFeeBps) {
|
|
31
|
+
const dynamicFeeBps = calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps);
|
|
32
32
|
const internalPrice = Math.floor(price * 1000000);
|
|
33
33
|
const effectiveInternalPrice = Math.floor((internalPrice * (10000 - dynamicFeeBps)) / 10000);
|
|
34
34
|
const clampedPrice = Math.max(effectiveInternalPrice, 1);
|
|
@@ -38,36 +38,37 @@ exports.applySellFee = applySellFee;
|
|
|
38
38
|
/**
|
|
39
39
|
* Simulate a buy order with given amount and price
|
|
40
40
|
*/
|
|
41
|
-
function simulateBuyOrder(amount, price, feeBps) {
|
|
42
|
-
const effectivePrice = applyBuyFee(price, feeBps);
|
|
41
|
+
function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
|
|
42
|
+
const effectivePrice = applyBuyFee(price, feeBps, customerMarketFeeBps);
|
|
43
43
|
const sharesReceived = amount / effectivePrice;
|
|
44
44
|
const valueAtOriginalPrice = sharesReceived * price;
|
|
45
45
|
const feeAmount = amount - valueAtOriginalPrice;
|
|
46
|
-
const feePercentage = (feeAmount / amount) * 100;
|
|
47
46
|
return {
|
|
48
47
|
entryPrice: price,
|
|
49
48
|
effectivePrice,
|
|
50
49
|
sharesReceived,
|
|
51
50
|
feeAmount,
|
|
52
|
-
feePercentage
|
|
51
|
+
feePercentage: (feeAmount / amount) * 100,
|
|
52
|
+
realEntryPrice: amount / sharesReceived
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
exports.simulateBuyOrder = simulateBuyOrder;
|
|
56
56
|
/**
|
|
57
57
|
* Simulate a sell order with given shares and price
|
|
58
58
|
*/
|
|
59
|
-
function simulateSellOrder(shares, price, feeBps) {
|
|
60
|
-
const effectivePrice = applySellFee(price, feeBps);
|
|
61
|
-
const
|
|
59
|
+
function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
|
|
60
|
+
const effectivePrice = applySellFee(price, feeBps, customerMarketFeeBps);
|
|
61
|
+
const amountToReceiveBeforeFixed = shares * effectivePrice;
|
|
62
62
|
const valueAtOriginalPrice = shares * price;
|
|
63
|
+
const amountReceived = amountToReceiveBeforeFixed;
|
|
63
64
|
const feeAmount = valueAtOriginalPrice - amountReceived;
|
|
64
|
-
const feePercentage = (feeAmount / valueAtOriginalPrice) * 100;
|
|
65
65
|
return {
|
|
66
66
|
entryPrice: price,
|
|
67
67
|
effectivePrice,
|
|
68
68
|
sharesReceived: shares,
|
|
69
69
|
feeAmount,
|
|
70
|
-
feePercentage
|
|
70
|
+
feePercentage: (feeAmount / valueAtOriginalPrice) * 100,
|
|
71
|
+
realEntryPrice: amountReceived / shares
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
exports.simulateSellOrder = simulateSellOrder;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { BN, IdlAccounts } from '@coral-xyz/anchor';
|
|
2
|
+
import { BN, IdlAccounts, Program } from '@coral-xyz/anchor';
|
|
3
3
|
import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, OrderDirectionEncoded, OrderTypeEncoded, OrderSideEncoded, OrderStatusEncoded, Pool, BookOrder } from '../types';
|
|
4
4
|
import { Stake, StakeVault, Unstake } from '../types/stake';
|
|
5
5
|
import { Customer } from '../types/customer';
|
|
@@ -29,3 +29,4 @@ export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDir
|
|
|
29
29
|
export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
|
|
30
30
|
export declare const getPriceFeedAccountForProgram: (priceFeedId: string) => PublicKey;
|
|
31
31
|
export declare const getFeedIdFromHex: (input?: string) => PublicKey | null;
|
|
32
|
+
export declare const getCustomerById: (program: Program<TriadProtocol>, customerId: number) => Promise<Customer>;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFeedIdFromHex = exports.getPriceFeedAccountForProgram = exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
12
|
+
exports.getCustomerById = exports.getFeedIdFromHex = exports.getPriceFeedAccountForProgram = exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
13
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
14
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
15
|
const types_1 = require("../types");
|
|
16
|
+
const pda_1 = require("./pda");
|
|
7
17
|
const constants_1 = require("./constants");
|
|
8
18
|
const encodeString = (value, alloc = 32) => {
|
|
9
19
|
const buffer = Buffer.alloc(alloc, 32);
|
|
@@ -145,6 +155,8 @@ const formatCustomer = (account, publicKey) => {
|
|
|
145
155
|
name: account.name,
|
|
146
156
|
feeRecipient: account.feeRecipient.toString(),
|
|
147
157
|
feeBps: account.feeBps,
|
|
158
|
+
marketFeeBps: account.marketFeeBps,
|
|
159
|
+
payoutFeeBps: account.payoutFeeBps,
|
|
148
160
|
isVerified: account.isVerified,
|
|
149
161
|
address: publicKey.toString()
|
|
150
162
|
};
|
|
@@ -289,3 +301,9 @@ const getFeedIdFromHex = (input) => {
|
|
|
289
301
|
return new web3_js_1.PublicKey(feedId);
|
|
290
302
|
};
|
|
291
303
|
exports.getFeedIdFromHex = getFeedIdFromHex;
|
|
304
|
+
const getCustomerById = (program, customerId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
305
|
+
const customerPDA = (0, pda_1.getCustomerPDA)(program.programId, customerId);
|
|
306
|
+
const customer = yield program.account.customer.fetch(customerPDA, program.provider.connection.commitment);
|
|
307
|
+
return (0, exports.formatCustomer)(customer, customerPDA);
|
|
308
|
+
});
|
|
309
|
+
exports.getCustomerById = getCustomerById;
|