@triadxyz/triad-protocol 3.3.1-beta → 3.3.3-beta
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 +19 -13
- package/dist/index.js +50 -56
- package/dist/poseidon.d.ts +9 -0
- package/dist/poseidon.js +22 -0
- package/dist/types/idl_triad_protocol.json +149 -5
- package/dist/types/index.d.ts +4 -4
- package/dist/types/triad_protocol.d.ts +207 -5
- package/dist/utils/feeCalculator.d.ts +41 -0
- package/dist/utils/feeCalculator.js +95 -0
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.js +3 -2
- package/dist/utils/merkle.js +3 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
3
3
|
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
|
|
4
4
|
import BN from 'bn.js';
|
|
5
|
-
import { TriadProtocol } from './types/triad_protocol';
|
|
5
|
+
import { TriadProtocol as TriadProtocolIDL } from './types/triad_protocol';
|
|
6
6
|
import { OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, OrderDirection, CloseOrderArgs, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs } from './types';
|
|
7
7
|
import Stake from './stake';
|
|
8
8
|
import Poseidon from './poseidon';
|
|
@@ -10,11 +10,14 @@ import Claim from './claim';
|
|
|
10
10
|
export * from './types';
|
|
11
11
|
export * from './utils/helpers';
|
|
12
12
|
export * from './utils/merkle';
|
|
13
|
-
export
|
|
13
|
+
export * from './utils/feeCalculator';
|
|
14
|
+
export * from './utils/constants';
|
|
15
|
+
export * from './utils/pda';
|
|
16
|
+
export default class TriadProtocol {
|
|
14
17
|
private connection;
|
|
15
18
|
private wallet;
|
|
16
19
|
private rpcOptions;
|
|
17
|
-
program: Program<
|
|
20
|
+
program: Program<TriadProtocolIDL>;
|
|
18
21
|
provider: AnchorProvider;
|
|
19
22
|
stake: Stake;
|
|
20
23
|
poseidon: Poseidon;
|
|
@@ -37,9 +40,14 @@ export default class TriadProtocolClient {
|
|
|
37
40
|
*/
|
|
38
41
|
getUserOrdersByMarketId(wallet: PublicKey, marketId: number): Promise<import("./types").Order[]>;
|
|
39
42
|
/**
|
|
40
|
-
* Get User Book Orders
|
|
43
|
+
* Get all User Book Orders
|
|
44
|
+
* @param wallet - User wallet PublicKey
|
|
45
|
+
*/
|
|
46
|
+
getUserBookOrders(wallet: PublicKey): Promise<BookOrder[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Get User Book Orders By Market ID
|
|
41
49
|
*/
|
|
42
|
-
|
|
50
|
+
getUserBookOrdersByMarketId(wallet: PublicKey, marketId: number): Promise<BookOrder[]>;
|
|
43
51
|
/**
|
|
44
52
|
* Get Costumer By Wallet Address
|
|
45
53
|
* @param wallet - The wallet address of the customer
|
|
@@ -342,33 +350,32 @@ export default class TriadProtocolClient {
|
|
|
342
350
|
}>;
|
|
343
351
|
/**
|
|
344
352
|
* Place Bid Order
|
|
345
|
-
* @param args.marketId - The ID of the Market
|
|
346
353
|
* @param args.orders - Array of orders to execute
|
|
354
|
+
* @param args.orders.marketId - The ID of the Market
|
|
347
355
|
* @param args.orders.amount - The amount of the Order
|
|
348
356
|
* @param args.orders.price - The price of the Order
|
|
349
357
|
* @param args.orders.orderDirection - The direction of the Order
|
|
350
358
|
* @param args.mint - The mint of the Order
|
|
351
359
|
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
352
360
|
*/
|
|
353
|
-
placeBidOrder({
|
|
361
|
+
placeBidOrder({ orders, isTrdPayout }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
354
362
|
/**
|
|
355
363
|
* Place Ask Order
|
|
356
|
-
* @param args.marketId - The ID of the Market
|
|
357
364
|
* @param args.orders - Array of orders to execute
|
|
365
|
+
* @param args.orders.marketId - The ID of the Market
|
|
358
366
|
* @param args.orders.amount - The amount of the Order
|
|
359
367
|
* @param args.orders.price - The price of the Order
|
|
360
368
|
* @param args.orders.bidOrderId - The ID of the Bid Order
|
|
361
369
|
* @param args.orders.bidNonce - The nonce of the Bid Order
|
|
362
370
|
*/
|
|
363
|
-
placeAskOrder({
|
|
371
|
+
placeAskOrder({ orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
364
372
|
/**
|
|
365
373
|
* Cancel Bid Order
|
|
366
|
-
* @param args.marketId - The ID of the Market
|
|
367
374
|
* @param args.orders.orderId - The ID of the Order
|
|
368
375
|
* @param args.orders.userNonce - The nonce of the user
|
|
369
376
|
* @param args.orders.orderDirection - The direction of the Order
|
|
370
377
|
*/
|
|
371
|
-
cancelBidOrder({
|
|
378
|
+
cancelBidOrder({ orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
372
379
|
/**
|
|
373
380
|
* Cancel Ask Order
|
|
374
381
|
* @param args.marketId - The ID of the Market
|
|
@@ -394,9 +401,8 @@ export default class TriadProtocolClient {
|
|
|
394
401
|
* @param args.orders.userNonce - The nonce of the user
|
|
395
402
|
* @param args.orderDirection - The direction of the Order
|
|
396
403
|
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
397
|
-
* @param args.feeBps - The fee in basis points
|
|
398
404
|
*/
|
|
399
|
-
marketAskOrder({ marketId, orders, orderDirection, isTrdPayout
|
|
405
|
+
marketAskOrder({ marketId, orders, orderDirection, isTrdPayout }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
400
406
|
/**
|
|
401
407
|
* Get Orders By Market ID
|
|
402
408
|
* @param marketId - Market ID
|
package/dist/index.js
CHANGED
|
@@ -38,13 +38,17 @@ const helpers_2 = require("./utils/helpers");
|
|
|
38
38
|
const pda_1 = require("./utils/pda");
|
|
39
39
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
40
40
|
const swap_1 = require("./utils/swap");
|
|
41
|
+
const feeCalculator_1 = require("./utils/feeCalculator");
|
|
41
42
|
const stake_1 = __importDefault(require("./stake"));
|
|
42
43
|
const poseidon_1 = __importDefault(require("./poseidon"));
|
|
43
44
|
const claim_1 = __importDefault(require("./claim"));
|
|
44
45
|
__exportStar(require("./types"), exports);
|
|
45
46
|
__exportStar(require("./utils/helpers"), exports);
|
|
46
47
|
__exportStar(require("./utils/merkle"), exports);
|
|
47
|
-
|
|
48
|
+
__exportStar(require("./utils/feeCalculator"), exports);
|
|
49
|
+
__exportStar(require("./utils/constants"), exports);
|
|
50
|
+
__exportStar(require("./utils/pda"), exports);
|
|
51
|
+
class TriadProtocol {
|
|
48
52
|
constructor(connection, wallet, rpcOptions) {
|
|
49
53
|
this.connection = connection;
|
|
50
54
|
this.wallet = wallet;
|
|
@@ -99,14 +103,30 @@ class TriadProtocolClient {
|
|
|
99
103
|
});
|
|
100
104
|
}
|
|
101
105
|
/**
|
|
102
|
-
* Get User Book Orders
|
|
106
|
+
* Get all User Book Orders
|
|
107
|
+
* @param wallet - User wallet PublicKey
|
|
108
|
+
*/
|
|
109
|
+
getUserBookOrders(wallet) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const orderbooks = yield this.program.account.orderBook.all();
|
|
112
|
+
const bookOrders = orderbooks.map((orderbook) => {
|
|
113
|
+
return [...orderbook.account.hypeOrders, ...orderbook.account.flopOrders]
|
|
114
|
+
.map((order) => (0, helpers_2.formatBookOrder)(order, orderbook.account.marketId.toNumber()))
|
|
115
|
+
.filter((order) => order.authority === wallet.toBase58() &&
|
|
116
|
+
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
117
|
+
});
|
|
118
|
+
return bookOrders.flat();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get User Book Orders By Market ID
|
|
103
123
|
*/
|
|
104
|
-
|
|
124
|
+
getUserBookOrdersByMarketId(wallet, marketId) {
|
|
105
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
126
|
const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId));
|
|
107
127
|
const orders = [...orderBook.hypeOrders, ...orderBook.flopOrders];
|
|
108
128
|
return orders
|
|
109
|
-
.map((order) => (0, helpers_2.formatBookOrder)(order))
|
|
129
|
+
.map((order) => (0, helpers_2.formatBookOrder)(order, marketId))
|
|
110
130
|
.filter((order) => order.authority === wallet.toBase58() &&
|
|
111
131
|
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
112
132
|
});
|
|
@@ -723,20 +743,20 @@ class TriadProtocolClient {
|
|
|
723
743
|
}
|
|
724
744
|
/**
|
|
725
745
|
* Place Bid Order
|
|
726
|
-
* @param args.marketId - The ID of the Market
|
|
727
746
|
* @param args.orders - Array of orders to execute
|
|
747
|
+
* @param args.orders.marketId - The ID of the Market
|
|
728
748
|
* @param args.orders.amount - The amount of the Order
|
|
729
749
|
* @param args.orders.price - The price of the Order
|
|
730
750
|
* @param args.orders.orderDirection - The direction of the Order
|
|
731
751
|
* @param args.mint - The mint of the Order
|
|
732
752
|
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
733
753
|
*/
|
|
734
|
-
placeBidOrder({
|
|
754
|
+
placeBidOrder({ orders, isTrdPayout }) {
|
|
735
755
|
return __awaiter(this, void 0, void 0, function* () {
|
|
736
756
|
const ixs = [];
|
|
737
757
|
const addressLookupTableAccounts = [];
|
|
738
|
-
if (orders.length >
|
|
739
|
-
throw new Error('You can only place up to
|
|
758
|
+
if (orders.length > 5) {
|
|
759
|
+
throw new Error('You can only place up to 5 orders at a time');
|
|
740
760
|
}
|
|
741
761
|
let amountInUSDC = new bn_js_1.default(0);
|
|
742
762
|
let totalAmount = 0;
|
|
@@ -765,10 +785,6 @@ class TriadProtocolClient {
|
|
|
765
785
|
return;
|
|
766
786
|
}
|
|
767
787
|
}
|
|
768
|
-
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(orders[0].orderDirection)[0]);
|
|
769
|
-
if (userTradeIxs.length > 0) {
|
|
770
|
-
ixs.push(...userTradeIxs);
|
|
771
|
-
}
|
|
772
788
|
for (const order of orders) {
|
|
773
789
|
ixs.push(yield this.program.methods
|
|
774
790
|
.placeBidOrder({
|
|
@@ -778,9 +794,9 @@ class TriadProtocolClient {
|
|
|
778
794
|
})
|
|
779
795
|
.accounts({
|
|
780
796
|
signer: this.program.provider.publicKey,
|
|
781
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
782
|
-
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
783
|
-
userTrade:
|
|
797
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
798
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
799
|
+
userTrade: this.getUserPDA(this.program.provider.publicKey)
|
|
784
800
|
})
|
|
785
801
|
.instruction());
|
|
786
802
|
}
|
|
@@ -789,18 +805,18 @@ class TriadProtocolClient {
|
|
|
789
805
|
}
|
|
790
806
|
/**
|
|
791
807
|
* Place Ask Order
|
|
792
|
-
* @param args.marketId - The ID of the Market
|
|
793
808
|
* @param args.orders - Array of orders to execute
|
|
809
|
+
* @param args.orders.marketId - The ID of the Market
|
|
794
810
|
* @param args.orders.amount - The amount of the Order
|
|
795
811
|
* @param args.orders.price - The price of the Order
|
|
796
812
|
* @param args.orders.bidOrderId - The ID of the Bid Order
|
|
797
813
|
* @param args.orders.bidNonce - The nonce of the Bid Order
|
|
798
814
|
*/
|
|
799
|
-
placeAskOrder({
|
|
815
|
+
placeAskOrder({ orders }) {
|
|
800
816
|
return __awaiter(this, void 0, void 0, function* () {
|
|
801
817
|
const ixs = [];
|
|
802
|
-
if (orders.length >
|
|
803
|
-
throw new Error('You can only place up to
|
|
818
|
+
if (orders.length > 5) {
|
|
819
|
+
throw new Error('You can only place up to 5 orders at a time');
|
|
804
820
|
}
|
|
805
821
|
for (const order of orders) {
|
|
806
822
|
ixs.push(yield this.program.methods
|
|
@@ -811,8 +827,8 @@ class TriadProtocolClient {
|
|
|
811
827
|
})
|
|
812
828
|
.accounts({
|
|
813
829
|
signer: this.program.provider.publicKey,
|
|
814
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
815
|
-
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
830
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
831
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
816
832
|
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
817
833
|
})
|
|
818
834
|
.instruction());
|
|
@@ -822,12 +838,11 @@ class TriadProtocolClient {
|
|
|
822
838
|
}
|
|
823
839
|
/**
|
|
824
840
|
* Cancel Bid Order
|
|
825
|
-
* @param args.marketId - The ID of the Market
|
|
826
841
|
* @param args.orders.orderId - The ID of the Order
|
|
827
842
|
* @param args.orders.userNonce - The nonce of the user
|
|
828
843
|
* @param args.orders.orderDirection - The direction of the Order
|
|
829
844
|
*/
|
|
830
|
-
cancelBidOrder({
|
|
845
|
+
cancelBidOrder({ orders }) {
|
|
831
846
|
return __awaiter(this, void 0, void 0, function* () {
|
|
832
847
|
const ixs = [];
|
|
833
848
|
if (orders.length > 4) {
|
|
@@ -842,8 +857,8 @@ class TriadProtocolClient {
|
|
|
842
857
|
.accounts({
|
|
843
858
|
signer: this.program.provider.publicKey,
|
|
844
859
|
payer: this.rpcOptions.payer,
|
|
845
|
-
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
846
|
-
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
860
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
861
|
+
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
847
862
|
userTrade: this.getUserPDA(this.program.provider.publicKey, order.userNonce)
|
|
848
863
|
})
|
|
849
864
|
.instruction());
|
|
@@ -916,14 +931,8 @@ class TriadProtocolClient {
|
|
|
916
931
|
}
|
|
917
932
|
const orderPrice = new bn_js_1.default(order.price);
|
|
918
933
|
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
919
|
-
|
|
920
|
-
const
|
|
921
|
-
const fee = priceSpread
|
|
922
|
-
.mul(orderPrice)
|
|
923
|
-
.mul(new bn_js_1.default(700))
|
|
924
|
-
.div(new bn_js_1.default(10000))
|
|
925
|
-
.div(new bn_js_1.default(1000000));
|
|
926
|
-
adjustedPrice = orderPrice.add(fee);
|
|
934
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000);
|
|
935
|
+
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
927
936
|
const maxSharesForPrice = tempRemainingUSDC
|
|
928
937
|
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
929
938
|
.div(adjustedPrice);
|
|
@@ -964,14 +973,8 @@ class TriadProtocolClient {
|
|
|
964
973
|
}
|
|
965
974
|
const orderPrice = new bn_js_1.default(order.price);
|
|
966
975
|
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
967
|
-
|
|
968
|
-
const
|
|
969
|
-
const fee = priceSpread
|
|
970
|
-
.mul(orderPrice)
|
|
971
|
-
.mul(new bn_js_1.default(700))
|
|
972
|
-
.div(new bn_js_1.default(10000))
|
|
973
|
-
.div(new bn_js_1.default(1000000));
|
|
974
|
-
adjustedPrice = orderPrice.add(fee);
|
|
976
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000);
|
|
977
|
+
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
975
978
|
const maxSharesForPrice = remainingUSDC
|
|
976
979
|
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
977
980
|
.div(adjustedPrice);
|
|
@@ -1021,9 +1024,8 @@ class TriadProtocolClient {
|
|
|
1021
1024
|
* @param args.orders.userNonce - The nonce of the user
|
|
1022
1025
|
* @param args.orderDirection - The direction of the Order
|
|
1023
1026
|
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
1024
|
-
* @param args.feeBps - The fee in basis points
|
|
1025
1027
|
*/
|
|
1026
|
-
marketAskOrder({ marketId, orders, orderDirection, isTrdPayout
|
|
1028
|
+
marketAskOrder({ marketId, orders, orderDirection, isTrdPayout }) {
|
|
1027
1029
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1028
1030
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
1029
1031
|
const ixs = [];
|
|
@@ -1049,16 +1051,8 @@ class TriadProtocolClient {
|
|
|
1049
1051
|
continue;
|
|
1050
1052
|
remainingShares = remainingShares.sub(sharesToSell);
|
|
1051
1053
|
const orderPrice = new bn_js_1.default(order.price);
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
|
|
1055
|
-
const fee = priceSpread
|
|
1056
|
-
.mul(orderPrice)
|
|
1057
|
-
.mul(new bn_js_1.default(feeBps))
|
|
1058
|
-
.div(new bn_js_1.default(10000))
|
|
1059
|
-
.div(new bn_js_1.default(1000000));
|
|
1060
|
-
adjustedPrice = orderPrice.sub(fee);
|
|
1061
|
-
}
|
|
1054
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000);
|
|
1055
|
+
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
1062
1056
|
amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
|
|
1063
1057
|
ixs.push(yield this.program.methods
|
|
1064
1058
|
.marketAskOrder({
|
|
@@ -1125,10 +1119,10 @@ class TriadProtocolClient {
|
|
|
1125
1119
|
if (order.price.eq(new bn_js_1.default(0)))
|
|
1126
1120
|
continue;
|
|
1127
1121
|
if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
|
|
1128
|
-
data[side].bid.push((0, helpers_2.formatBookOrder)(order));
|
|
1122
|
+
data[side].bid.push((0, helpers_2.formatBookOrder)(order, marketId));
|
|
1129
1123
|
}
|
|
1130
1124
|
if ((0, helpers_2.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.ASK) {
|
|
1131
|
-
data[side].ask.push((0, helpers_2.formatBookOrder)(order));
|
|
1125
|
+
data[side].ask.push((0, helpers_2.formatBookOrder)(order, marketId));
|
|
1132
1126
|
}
|
|
1133
1127
|
}
|
|
1134
1128
|
};
|
|
@@ -1156,4 +1150,4 @@ class TriadProtocolClient {
|
|
|
1156
1150
|
});
|
|
1157
1151
|
}
|
|
1158
1152
|
}
|
|
1159
|
-
exports.default =
|
|
1153
|
+
exports.default = TriadProtocol;
|
package/dist/poseidon.d.ts
CHANGED
|
@@ -41,4 +41,13 @@ export default class Poseidon {
|
|
|
41
41
|
* @param poseidonAsset - Poseidon Asset
|
|
42
42
|
*/
|
|
43
43
|
removeTraderPoseidon(user: PublicKey, poseidonAsset: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
44
|
+
/**
|
|
45
|
+
* Update Metadata
|
|
46
|
+
* @param poseidons.uri - URI
|
|
47
|
+
* @param poseidons.asset - Asset
|
|
48
|
+
*/
|
|
49
|
+
updateMetadata(poseidons: {
|
|
50
|
+
uri: string;
|
|
51
|
+
asset: PublicKey;
|
|
52
|
+
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
44
53
|
}
|
package/dist/poseidon.js
CHANGED
|
@@ -130,5 +130,27 @@ class Poseidon {
|
|
|
130
130
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Update Metadata
|
|
135
|
+
* @param poseidons.uri - URI
|
|
136
|
+
* @param poseidons.asset - Asset
|
|
137
|
+
*/
|
|
138
|
+
updateMetadata(poseidons) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const ixs = [];
|
|
141
|
+
for (const poseidon of poseidons) {
|
|
142
|
+
ixs.push(yield this.program.methods
|
|
143
|
+
.updateMetadata(poseidon.uri)
|
|
144
|
+
.accounts({
|
|
145
|
+
signer: this.program.provider.publicKey,
|
|
146
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
147
|
+
poseidonCollection: (0, pda_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL),
|
|
148
|
+
poseidonAsset: poseidon.asset
|
|
149
|
+
})
|
|
150
|
+
.instruction());
|
|
151
|
+
}
|
|
152
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
133
155
|
}
|
|
134
156
|
exports.default = Poseidon;
|
|
@@ -852,6 +852,94 @@
|
|
|
852
852
|
],
|
|
853
853
|
"args": []
|
|
854
854
|
},
|
|
855
|
+
{
|
|
856
|
+
"name": "collect_remaining_liquidity",
|
|
857
|
+
"discriminator": [153, 107, 201, 83, 183, 195, 59, 186],
|
|
858
|
+
"accounts": [
|
|
859
|
+
{
|
|
860
|
+
"name": "signer",
|
|
861
|
+
"writable": true,
|
|
862
|
+
"signer": true
|
|
863
|
+
},
|
|
864
|
+
{
|
|
865
|
+
"name": "market",
|
|
866
|
+
"writable": true
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
"name": "mint",
|
|
870
|
+
"writable": true
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
"name": "market_ata",
|
|
874
|
+
"writable": true,
|
|
875
|
+
"pda": {
|
|
876
|
+
"seeds": [
|
|
877
|
+
{
|
|
878
|
+
"kind": "account",
|
|
879
|
+
"path": "market"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
"kind": "account",
|
|
883
|
+
"path": "token_program"
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
"kind": "account",
|
|
887
|
+
"path": "mint"
|
|
888
|
+
}
|
|
889
|
+
],
|
|
890
|
+
"program": {
|
|
891
|
+
"kind": "const",
|
|
892
|
+
"value": [
|
|
893
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
894
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
895
|
+
219, 233, 248, 89
|
|
896
|
+
]
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
"name": "signer_ata",
|
|
902
|
+
"writable": true,
|
|
903
|
+
"pda": {
|
|
904
|
+
"seeds": [
|
|
905
|
+
{
|
|
906
|
+
"kind": "account",
|
|
907
|
+
"path": "signer"
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
"kind": "account",
|
|
911
|
+
"path": "token_program"
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
"kind": "account",
|
|
915
|
+
"path": "mint"
|
|
916
|
+
}
|
|
917
|
+
],
|
|
918
|
+
"program": {
|
|
919
|
+
"kind": "const",
|
|
920
|
+
"value": [
|
|
921
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
922
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
923
|
+
219, 233, 248, 89
|
|
924
|
+
]
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
"name": "token_program",
|
|
930
|
+
"address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
"name": "associated_token_program",
|
|
934
|
+
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
"name": "system_program",
|
|
938
|
+
"address": "11111111111111111111111111111111"
|
|
939
|
+
}
|
|
940
|
+
],
|
|
941
|
+
"args": []
|
|
942
|
+
},
|
|
855
943
|
{
|
|
856
944
|
"name": "collect_royalty",
|
|
857
945
|
"discriminator": [189, 235, 7, 168, 255, 50, 30, 75],
|
|
@@ -1638,11 +1726,6 @@
|
|
|
1638
1726
|
"writable": true,
|
|
1639
1727
|
"signer": true
|
|
1640
1728
|
},
|
|
1641
|
-
{
|
|
1642
|
-
"name": "squads",
|
|
1643
|
-
"writable": true,
|
|
1644
|
-
"address": "Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4"
|
|
1645
|
-
},
|
|
1646
1729
|
{
|
|
1647
1730
|
"name": "user_trade",
|
|
1648
1731
|
"writable": true
|
|
@@ -2568,6 +2651,43 @@
|
|
|
2568
2651
|
}
|
|
2569
2652
|
]
|
|
2570
2653
|
},
|
|
2654
|
+
{
|
|
2655
|
+
"name": "update_metadata",
|
|
2656
|
+
"discriminator": [170, 182, 43, 239, 97, 78, 225, 186],
|
|
2657
|
+
"accounts": [
|
|
2658
|
+
{
|
|
2659
|
+
"name": "signer",
|
|
2660
|
+
"writable": true,
|
|
2661
|
+
"signer": true
|
|
2662
|
+
},
|
|
2663
|
+
{
|
|
2664
|
+
"name": "poseidon_collection",
|
|
2665
|
+
"writable": true
|
|
2666
|
+
},
|
|
2667
|
+
{
|
|
2668
|
+
"name": "poseidon_asset",
|
|
2669
|
+
"writable": true
|
|
2670
|
+
},
|
|
2671
|
+
{
|
|
2672
|
+
"name": "core_poseidon_collection",
|
|
2673
|
+
"writable": true
|
|
2674
|
+
},
|
|
2675
|
+
{
|
|
2676
|
+
"name": "core_program",
|
|
2677
|
+
"address": "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d"
|
|
2678
|
+
},
|
|
2679
|
+
{
|
|
2680
|
+
"name": "system_program",
|
|
2681
|
+
"address": "11111111111111111111111111111111"
|
|
2682
|
+
}
|
|
2683
|
+
],
|
|
2684
|
+
"args": [
|
|
2685
|
+
{
|
|
2686
|
+
"name": "uri",
|
|
2687
|
+
"type": "string"
|
|
2688
|
+
}
|
|
2689
|
+
]
|
|
2690
|
+
},
|
|
2571
2691
|
{
|
|
2572
2692
|
"name": "update_pool_question",
|
|
2573
2693
|
"discriminator": [248, 60, 128, 181, 157, 182, 51, 166],
|
|
@@ -2750,6 +2870,10 @@
|
|
|
2750
2870
|
"name": "MarketEvent",
|
|
2751
2871
|
"discriminator": [212, 67, 145, 23, 58, 104, 52, 83]
|
|
2752
2872
|
},
|
|
2873
|
+
{
|
|
2874
|
+
"name": "MarketFeeEvent",
|
|
2875
|
+
"discriminator": [191, 148, 93, 112, 63, 139, 16, 186]
|
|
2876
|
+
},
|
|
2753
2877
|
{
|
|
2754
2878
|
"name": "OrderEvent",
|
|
2755
2879
|
"discriminator": [209, 51, 146, 206, 88, 127, 112, 69]
|
|
@@ -3766,6 +3890,26 @@
|
|
|
3766
3890
|
]
|
|
3767
3891
|
}
|
|
3768
3892
|
},
|
|
3893
|
+
{
|
|
3894
|
+
"name": "MarketFeeEvent",
|
|
3895
|
+
"type": {
|
|
3896
|
+
"kind": "struct",
|
|
3897
|
+
"fields": [
|
|
3898
|
+
{
|
|
3899
|
+
"name": "market_id",
|
|
3900
|
+
"type": "u64"
|
|
3901
|
+
},
|
|
3902
|
+
{
|
|
3903
|
+
"name": "fee",
|
|
3904
|
+
"type": "u64"
|
|
3905
|
+
},
|
|
3906
|
+
{
|
|
3907
|
+
"name": "timestamp",
|
|
3908
|
+
"type": "i64"
|
|
3909
|
+
}
|
|
3910
|
+
]
|
|
3911
|
+
}
|
|
3912
|
+
},
|
|
3769
3913
|
{
|
|
3770
3914
|
"name": "MarketV2",
|
|
3771
3915
|
"type": {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -79,6 +79,7 @@ export type BookOrder = {
|
|
|
79
79
|
orderSide: OrderSide;
|
|
80
80
|
userNonce: string;
|
|
81
81
|
linkedBookOrderId: string;
|
|
82
|
+
marketId: number;
|
|
82
83
|
};
|
|
83
84
|
export declare enum WinningDirection {
|
|
84
85
|
HYPE = "Hype",
|
|
@@ -219,21 +220,21 @@ export interface MerkleProof {
|
|
|
219
220
|
proof: number[][];
|
|
220
221
|
}
|
|
221
222
|
export type PlaceBidOrderArgs = {
|
|
222
|
-
marketId: number;
|
|
223
223
|
orders: {
|
|
224
224
|
amount: number;
|
|
225
225
|
price: number;
|
|
226
226
|
orderDirection: OrderDirectionEncoded;
|
|
227
|
+
marketId: number;
|
|
227
228
|
}[];
|
|
228
229
|
isTrdPayout: boolean;
|
|
229
230
|
};
|
|
230
231
|
export type PlaceAskOrderArgs = {
|
|
231
|
-
marketId: number;
|
|
232
232
|
orders: {
|
|
233
233
|
amount: number;
|
|
234
234
|
price: number;
|
|
235
235
|
bidOrderId: number;
|
|
236
236
|
userNonce: number;
|
|
237
|
+
marketId: number;
|
|
237
238
|
}[];
|
|
238
239
|
};
|
|
239
240
|
export type InitializeMarketArgs = {
|
|
@@ -284,8 +285,8 @@ export type CreatePoolArgs = {
|
|
|
284
285
|
isFast?: boolean;
|
|
285
286
|
};
|
|
286
287
|
export type CancelBidOrderArgs = {
|
|
287
|
-
marketId: number;
|
|
288
288
|
orders: {
|
|
289
|
+
marketId: number;
|
|
289
290
|
orderId: number;
|
|
290
291
|
userNonce: number;
|
|
291
292
|
orderDirection: OrderDirectionEncoded;
|
|
@@ -314,7 +315,6 @@ export type MarketAskOrderArgs = {
|
|
|
314
315
|
}[];
|
|
315
316
|
orderDirection: OrderDirectionEncoded;
|
|
316
317
|
isTrdPayout: boolean;
|
|
317
|
-
feeBps: number;
|
|
318
318
|
};
|
|
319
319
|
export type CreateClaimVaultArgs = {
|
|
320
320
|
totalAmount: number;
|
|
@@ -1298,6 +1298,152 @@ export type TriadProtocol = {
|
|
|
1298
1298
|
];
|
|
1299
1299
|
args: [];
|
|
1300
1300
|
},
|
|
1301
|
+
{
|
|
1302
|
+
name: 'collectRemainingLiquidity';
|
|
1303
|
+
discriminator: [153, 107, 201, 83, 183, 195, 59, 186];
|
|
1304
|
+
accounts: [
|
|
1305
|
+
{
|
|
1306
|
+
name: 'signer';
|
|
1307
|
+
writable: true;
|
|
1308
|
+
signer: true;
|
|
1309
|
+
},
|
|
1310
|
+
{
|
|
1311
|
+
name: 'market';
|
|
1312
|
+
writable: true;
|
|
1313
|
+
},
|
|
1314
|
+
{
|
|
1315
|
+
name: 'mint';
|
|
1316
|
+
writable: true;
|
|
1317
|
+
},
|
|
1318
|
+
{
|
|
1319
|
+
name: 'marketAta';
|
|
1320
|
+
writable: true;
|
|
1321
|
+
pda: {
|
|
1322
|
+
seeds: [
|
|
1323
|
+
{
|
|
1324
|
+
kind: 'account';
|
|
1325
|
+
path: 'market';
|
|
1326
|
+
},
|
|
1327
|
+
{
|
|
1328
|
+
kind: 'account';
|
|
1329
|
+
path: 'tokenProgram';
|
|
1330
|
+
},
|
|
1331
|
+
{
|
|
1332
|
+
kind: 'account';
|
|
1333
|
+
path: 'mint';
|
|
1334
|
+
}
|
|
1335
|
+
];
|
|
1336
|
+
program: {
|
|
1337
|
+
kind: 'const';
|
|
1338
|
+
value: [
|
|
1339
|
+
140,
|
|
1340
|
+
151,
|
|
1341
|
+
37,
|
|
1342
|
+
143,
|
|
1343
|
+
78,
|
|
1344
|
+
36,
|
|
1345
|
+
137,
|
|
1346
|
+
241,
|
|
1347
|
+
187,
|
|
1348
|
+
61,
|
|
1349
|
+
16,
|
|
1350
|
+
41,
|
|
1351
|
+
20,
|
|
1352
|
+
142,
|
|
1353
|
+
13,
|
|
1354
|
+
131,
|
|
1355
|
+
11,
|
|
1356
|
+
90,
|
|
1357
|
+
19,
|
|
1358
|
+
153,
|
|
1359
|
+
218,
|
|
1360
|
+
255,
|
|
1361
|
+
16,
|
|
1362
|
+
132,
|
|
1363
|
+
4,
|
|
1364
|
+
142,
|
|
1365
|
+
123,
|
|
1366
|
+
216,
|
|
1367
|
+
219,
|
|
1368
|
+
233,
|
|
1369
|
+
248,
|
|
1370
|
+
89
|
|
1371
|
+
];
|
|
1372
|
+
};
|
|
1373
|
+
};
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
name: 'signerAta';
|
|
1377
|
+
writable: true;
|
|
1378
|
+
pda: {
|
|
1379
|
+
seeds: [
|
|
1380
|
+
{
|
|
1381
|
+
kind: 'account';
|
|
1382
|
+
path: 'signer';
|
|
1383
|
+
},
|
|
1384
|
+
{
|
|
1385
|
+
kind: 'account';
|
|
1386
|
+
path: 'tokenProgram';
|
|
1387
|
+
},
|
|
1388
|
+
{
|
|
1389
|
+
kind: 'account';
|
|
1390
|
+
path: 'mint';
|
|
1391
|
+
}
|
|
1392
|
+
];
|
|
1393
|
+
program: {
|
|
1394
|
+
kind: 'const';
|
|
1395
|
+
value: [
|
|
1396
|
+
140,
|
|
1397
|
+
151,
|
|
1398
|
+
37,
|
|
1399
|
+
143,
|
|
1400
|
+
78,
|
|
1401
|
+
36,
|
|
1402
|
+
137,
|
|
1403
|
+
241,
|
|
1404
|
+
187,
|
|
1405
|
+
61,
|
|
1406
|
+
16,
|
|
1407
|
+
41,
|
|
1408
|
+
20,
|
|
1409
|
+
142,
|
|
1410
|
+
13,
|
|
1411
|
+
131,
|
|
1412
|
+
11,
|
|
1413
|
+
90,
|
|
1414
|
+
19,
|
|
1415
|
+
153,
|
|
1416
|
+
218,
|
|
1417
|
+
255,
|
|
1418
|
+
16,
|
|
1419
|
+
132,
|
|
1420
|
+
4,
|
|
1421
|
+
142,
|
|
1422
|
+
123,
|
|
1423
|
+
216,
|
|
1424
|
+
219,
|
|
1425
|
+
233,
|
|
1426
|
+
248,
|
|
1427
|
+
89
|
|
1428
|
+
];
|
|
1429
|
+
};
|
|
1430
|
+
};
|
|
1431
|
+
},
|
|
1432
|
+
{
|
|
1433
|
+
name: 'tokenProgram';
|
|
1434
|
+
address: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
|
|
1435
|
+
},
|
|
1436
|
+
{
|
|
1437
|
+
name: 'associatedTokenProgram';
|
|
1438
|
+
address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
1439
|
+
},
|
|
1440
|
+
{
|
|
1441
|
+
name: 'systemProgram';
|
|
1442
|
+
address: '11111111111111111111111111111111';
|
|
1443
|
+
}
|
|
1444
|
+
];
|
|
1445
|
+
args: [];
|
|
1446
|
+
},
|
|
1301
1447
|
{
|
|
1302
1448
|
name: 'collectRoyalty';
|
|
1303
1449
|
discriminator: [189, 235, 7, 168, 255, 50, 30, 75];
|
|
@@ -2287,11 +2433,6 @@ export type TriadProtocol = {
|
|
|
2287
2433
|
writable: true;
|
|
2288
2434
|
signer: true;
|
|
2289
2435
|
},
|
|
2290
|
-
{
|
|
2291
|
-
name: 'squads';
|
|
2292
|
-
writable: true;
|
|
2293
|
-
address: 'Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4';
|
|
2294
|
-
},
|
|
2295
2436
|
{
|
|
2296
2437
|
name: 'userTrade';
|
|
2297
2438
|
writable: true;
|
|
@@ -3543,6 +3684,43 @@ export type TriadProtocol = {
|
|
|
3543
3684
|
}
|
|
3544
3685
|
];
|
|
3545
3686
|
},
|
|
3687
|
+
{
|
|
3688
|
+
name: 'updateMetadata';
|
|
3689
|
+
discriminator: [170, 182, 43, 239, 97, 78, 225, 186];
|
|
3690
|
+
accounts: [
|
|
3691
|
+
{
|
|
3692
|
+
name: 'signer';
|
|
3693
|
+
writable: true;
|
|
3694
|
+
signer: true;
|
|
3695
|
+
},
|
|
3696
|
+
{
|
|
3697
|
+
name: 'poseidonCollection';
|
|
3698
|
+
writable: true;
|
|
3699
|
+
},
|
|
3700
|
+
{
|
|
3701
|
+
name: 'poseidonAsset';
|
|
3702
|
+
writable: true;
|
|
3703
|
+
},
|
|
3704
|
+
{
|
|
3705
|
+
name: 'corePoseidonCollection';
|
|
3706
|
+
writable: true;
|
|
3707
|
+
},
|
|
3708
|
+
{
|
|
3709
|
+
name: 'coreProgram';
|
|
3710
|
+
address: 'CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d';
|
|
3711
|
+
},
|
|
3712
|
+
{
|
|
3713
|
+
name: 'systemProgram';
|
|
3714
|
+
address: '11111111111111111111111111111111';
|
|
3715
|
+
}
|
|
3716
|
+
];
|
|
3717
|
+
args: [
|
|
3718
|
+
{
|
|
3719
|
+
name: 'uri';
|
|
3720
|
+
type: 'string';
|
|
3721
|
+
}
|
|
3722
|
+
];
|
|
3723
|
+
},
|
|
3546
3724
|
{
|
|
3547
3725
|
name: 'updatePoolQuestion';
|
|
3548
3726
|
discriminator: [248, 60, 128, 181, 157, 182, 51, 166];
|
|
@@ -3737,6 +3915,10 @@ export type TriadProtocol = {
|
|
|
3737
3915
|
name: 'marketEvent';
|
|
3738
3916
|
discriminator: [212, 67, 145, 23, 58, 104, 52, 83];
|
|
3739
3917
|
},
|
|
3918
|
+
{
|
|
3919
|
+
name: 'marketFeeEvent';
|
|
3920
|
+
discriminator: [191, 148, 93, 112, 63, 139, 16, 186];
|
|
3921
|
+
},
|
|
3740
3922
|
{
|
|
3741
3923
|
name: 'orderEvent';
|
|
3742
3924
|
discriminator: [209, 51, 146, 206, 88, 127, 112, 69];
|
|
@@ -4753,6 +4935,26 @@ export type TriadProtocol = {
|
|
|
4753
4935
|
];
|
|
4754
4936
|
};
|
|
4755
4937
|
},
|
|
4938
|
+
{
|
|
4939
|
+
name: 'marketFeeEvent';
|
|
4940
|
+
type: {
|
|
4941
|
+
kind: 'struct';
|
|
4942
|
+
fields: [
|
|
4943
|
+
{
|
|
4944
|
+
name: 'marketId';
|
|
4945
|
+
type: 'u64';
|
|
4946
|
+
},
|
|
4947
|
+
{
|
|
4948
|
+
name: 'fee';
|
|
4949
|
+
type: 'u64';
|
|
4950
|
+
},
|
|
4951
|
+
{
|
|
4952
|
+
name: 'timestamp';
|
|
4953
|
+
type: 'i64';
|
|
4954
|
+
}
|
|
4955
|
+
];
|
|
4956
|
+
};
|
|
4957
|
+
},
|
|
4756
4958
|
{
|
|
4757
4959
|
name: 'marketV2';
|
|
4758
4960
|
type: {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate dynamic fee based on price
|
|
3
|
+
* Returns fee in basis points (bps)
|
|
4
|
+
*/
|
|
5
|
+
export declare function calculateDynamicFeeBps(price: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Apply dynamic fee to price for buy orders (adds fee)
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyBuyFee(price: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Apply dynamic fee to price for sell orders (subtracts fee)
|
|
12
|
+
*/
|
|
13
|
+
export declare function applySellFee(price: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Simulate a buy order with given amount and price
|
|
16
|
+
*/
|
|
17
|
+
export declare function simulateBuyOrder(amount: number, price: number): {
|
|
18
|
+
entryPrice: number;
|
|
19
|
+
effectivePrice: number;
|
|
20
|
+
sharesReceived: number;
|
|
21
|
+
feeAmount: number;
|
|
22
|
+
feePercentage: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Simulate a sell order with given shares and price
|
|
26
|
+
*/
|
|
27
|
+
export declare function simulateSellOrder(shares: number, price: number): {
|
|
28
|
+
entryPrice: number;
|
|
29
|
+
effectivePrice: number;
|
|
30
|
+
sharesReceived: number;
|
|
31
|
+
feeAmount: number;
|
|
32
|
+
feePercentage: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Generate fee curve data for visualization
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateFeeCurve(step?: number): Array<{
|
|
38
|
+
price: number;
|
|
39
|
+
feeBps: number;
|
|
40
|
+
feePercentage: number;
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateFeeCurve = exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.calculateDynamicFeeBps = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate dynamic fee based on price
|
|
6
|
+
* Returns fee in basis points (bps)
|
|
7
|
+
*/
|
|
8
|
+
function calculateDynamicFeeBps(price) {
|
|
9
|
+
const internalPrice = Math.floor(price * 1000000);
|
|
10
|
+
if (internalPrice <= 500000) {
|
|
11
|
+
return 190;
|
|
12
|
+
}
|
|
13
|
+
const priceAbove50 = internalPrice - 500000;
|
|
14
|
+
const feeReduction = Math.floor((priceAbove50 * 100) / 490000);
|
|
15
|
+
const calculatedFee = Math.max(0, 190 - feeReduction);
|
|
16
|
+
const maxPossibleFee = internalPrice < 999999
|
|
17
|
+
? Math.floor(((999999 - internalPrice) * 10000) / internalPrice)
|
|
18
|
+
: 0;
|
|
19
|
+
return Math.max(90, Math.min(calculatedFee, maxPossibleFee));
|
|
20
|
+
}
|
|
21
|
+
exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
|
|
22
|
+
/**
|
|
23
|
+
* Apply dynamic fee to price for buy orders (adds fee)
|
|
24
|
+
*/
|
|
25
|
+
function applyBuyFee(price) {
|
|
26
|
+
const feeBps = calculateDynamicFeeBps(price);
|
|
27
|
+
const internalPrice = Math.floor(price * 1000000);
|
|
28
|
+
const effectiveInternalPrice = Math.floor((internalPrice * (10000 + feeBps)) / 10000);
|
|
29
|
+
const clampedPrice = Math.min(effectiveInternalPrice, 999999);
|
|
30
|
+
return clampedPrice / 1000000;
|
|
31
|
+
}
|
|
32
|
+
exports.applyBuyFee = applyBuyFee;
|
|
33
|
+
/**
|
|
34
|
+
* Apply dynamic fee to price for sell orders (subtracts fee)
|
|
35
|
+
*/
|
|
36
|
+
function applySellFee(price) {
|
|
37
|
+
const feeBps = calculateDynamicFeeBps(price);
|
|
38
|
+
const internalPrice = Math.floor(price * 1000000);
|
|
39
|
+
const effectiveInternalPrice = Math.floor((internalPrice * (10000 - feeBps)) / 10000);
|
|
40
|
+
const clampedPrice = Math.max(effectiveInternalPrice, 1);
|
|
41
|
+
return clampedPrice / 1000000;
|
|
42
|
+
}
|
|
43
|
+
exports.applySellFee = applySellFee;
|
|
44
|
+
/**
|
|
45
|
+
* Simulate a buy order with given amount and price
|
|
46
|
+
*/
|
|
47
|
+
function simulateBuyOrder(amount, price) {
|
|
48
|
+
const effectivePrice = applyBuyFee(price);
|
|
49
|
+
const sharesReceived = amount / effectivePrice;
|
|
50
|
+
const valueAtOriginalPrice = sharesReceived * price;
|
|
51
|
+
const feeAmount = amount - valueAtOriginalPrice;
|
|
52
|
+
const feePercentage = (feeAmount / amount) * 100;
|
|
53
|
+
return {
|
|
54
|
+
entryPrice: price,
|
|
55
|
+
effectivePrice,
|
|
56
|
+
sharesReceived,
|
|
57
|
+
feeAmount,
|
|
58
|
+
feePercentage
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.simulateBuyOrder = simulateBuyOrder;
|
|
62
|
+
/**
|
|
63
|
+
* Simulate a sell order with given shares and price
|
|
64
|
+
*/
|
|
65
|
+
function simulateSellOrder(shares, price) {
|
|
66
|
+
const effectivePrice = applySellFee(price);
|
|
67
|
+
const amountReceived = shares * effectivePrice;
|
|
68
|
+
const valueAtOriginalPrice = shares * price;
|
|
69
|
+
const feeAmount = valueAtOriginalPrice - amountReceived;
|
|
70
|
+
const feePercentage = (feeAmount / valueAtOriginalPrice) * 100;
|
|
71
|
+
return {
|
|
72
|
+
entryPrice: price,
|
|
73
|
+
effectivePrice,
|
|
74
|
+
sharesReceived: shares,
|
|
75
|
+
feeAmount,
|
|
76
|
+
feePercentage
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.simulateSellOrder = simulateSellOrder;
|
|
80
|
+
/**
|
|
81
|
+
* Generate fee curve data for visualization
|
|
82
|
+
*/
|
|
83
|
+
function generateFeeCurve(step = 0.01) {
|
|
84
|
+
const curve = [];
|
|
85
|
+
for (let price = 0.01; price <= 0.99; price += step) {
|
|
86
|
+
const feeBps = calculateDynamicFeeBps(price);
|
|
87
|
+
curve.push({
|
|
88
|
+
price: Math.round(price * 100) / 100,
|
|
89
|
+
feeBps,
|
|
90
|
+
feePercentage: feeBps / 100
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return curve;
|
|
94
|
+
}
|
|
95
|
+
exports.generateFeeCurve = generateFeeCurve;
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const formatPool: (account: IdlAccounts<TriadProtocol>['pool'], a
|
|
|
11
11
|
export declare const formatMarket: (account: IdlAccounts<TriadProtocol>['marketV2'], address: PublicKey) => Market;
|
|
12
12
|
export declare const formatUserTrade: (account: IdlAccounts<TriadProtocol>['userTrade'], address: PublicKey) => UserTrade;
|
|
13
13
|
export declare const formatOrder: (order: IdlAccounts<TriadProtocol>['userTrade']['orders'][number], authority?: string) => Order;
|
|
14
|
-
export declare const formatBookOrder: (order: IdlAccounts<TriadProtocol>['orderBook']['hypeOrders'][number] | IdlAccounts<TriadProtocol>['orderBook']['flopOrders'][number]) => BookOrder;
|
|
14
|
+
export declare const formatBookOrder: (order: IdlAccounts<TriadProtocol>['orderBook']['hypeOrders'][number] | IdlAccounts<TriadProtocol>['orderBook']['flopOrders'][number], marketId: number) => BookOrder;
|
|
15
15
|
export declare const formatCustomer: (account: IdlAccounts<TriadProtocol>['customer'], publicKey: PublicKey) => Customer;
|
|
16
16
|
export declare const formatClaimVault: (account: IdlAccounts<TriadProtocol>['claimVault'], address: PublicKey) => ClaimVault;
|
|
17
17
|
export declare const formatClaimedUser: (account: IdlAccounts<TriadProtocol>['claimedUser'], address: PublicKey) => ClaimedUser;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -101,7 +101,7 @@ const formatMarket = (account, address) => {
|
|
|
101
101
|
payoutFee: account.payoutFee,
|
|
102
102
|
customer: account.customerId === 0 ? 'Triad' : account.customerId.toString(),
|
|
103
103
|
poolId: account.poolId.toNumber(),
|
|
104
|
-
feeRecipient: account.feeRecipient.toString()
|
|
104
|
+
feeRecipient: account.feeRecipient.toString()
|
|
105
105
|
};
|
|
106
106
|
};
|
|
107
107
|
exports.formatMarket = formatMarket;
|
|
@@ -134,7 +134,7 @@ const formatOrder = (order, authority) => {
|
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
exports.formatOrder = formatOrder;
|
|
137
|
-
const formatBookOrder = (order) => {
|
|
137
|
+
const formatBookOrder = (order, marketId) => {
|
|
138
138
|
return {
|
|
139
139
|
id: order.id.toString(),
|
|
140
140
|
price: order.price.toString(),
|
|
@@ -144,6 +144,7 @@ const formatBookOrder = (order) => {
|
|
|
144
144
|
orderDirection: (0, exports.getOrderDirectionFromNumber)(order.orderDirection),
|
|
145
145
|
orderSide: (0, exports.getOrderSideFromNumber)(order.orderSide),
|
|
146
146
|
userNonce: order.userNonce.toString(),
|
|
147
|
+
marketId,
|
|
147
148
|
linkedBookOrderId: order.linkedBookOrderId.toString()
|
|
148
149
|
};
|
|
149
150
|
};
|
package/dist/utils/merkle.js
CHANGED
|
@@ -61,6 +61,9 @@ class MerkleTree {
|
|
|
61
61
|
if (siblingIndex < this.tree[level].length) {
|
|
62
62
|
proof.push(this.tree[level][siblingIndex]);
|
|
63
63
|
}
|
|
64
|
+
else {
|
|
65
|
+
proof.push(this.tree[level][currentIndex]);
|
|
66
|
+
}
|
|
64
67
|
currentIndex = Math.floor(currentIndex / 2);
|
|
65
68
|
}
|
|
66
69
|
return proof.map((hash) => Array.from(hash));
|