@drift-labs/sdk 2.20.0-beta.2 → 2.20.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/lib/constants/perpMarkets.js +20 -0
- package/lib/driftClient.d.ts +2 -2
- package/lib/driftClient.js +27 -20
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/constants/perpMarkets.ts +20 -0
- package/src/driftClient.ts +32 -22
- package/src/idl/drift.json +1 -1
|
@@ -54,6 +54,16 @@ exports.DevnetPerpMarkets = [
|
|
|
54
54
|
launchTs: 1677068931000,
|
|
55
55
|
oracleSource: __1.OracleSource.PYTH_1M,
|
|
56
56
|
},
|
|
57
|
+
{
|
|
58
|
+
fullName: 'Polygon',
|
|
59
|
+
category: ['L2', 'Infra'],
|
|
60
|
+
symbol: 'MATIC-PERP',
|
|
61
|
+
baseAssetSymbol: 'MATIC',
|
|
62
|
+
marketIndex: 5,
|
|
63
|
+
oracle: new web3_js_1.PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
|
|
64
|
+
launchTs: 1677690149000,
|
|
65
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
66
|
+
},
|
|
57
67
|
];
|
|
58
68
|
exports.MainnetPerpMarkets = [
|
|
59
69
|
{
|
|
@@ -106,6 +116,16 @@ exports.MainnetPerpMarkets = [
|
|
|
106
116
|
launchTs: 1677690149000,
|
|
107
117
|
oracleSource: __1.OracleSource.PYTH_1M,
|
|
108
118
|
},
|
|
119
|
+
{
|
|
120
|
+
fullName: 'Polygon',
|
|
121
|
+
category: ['L2', 'Infra'],
|
|
122
|
+
symbol: 'MATIC-PERP',
|
|
123
|
+
baseAssetSymbol: 'MATIC',
|
|
124
|
+
marketIndex: 5,
|
|
125
|
+
oracle: new web3_js_1.PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
|
|
126
|
+
launchTs: 1677690149000,
|
|
127
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
128
|
+
},
|
|
109
129
|
];
|
|
110
130
|
exports.PerpMarkets = {
|
|
111
131
|
devnet: exports.DevnetPerpMarkets,
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -200,8 +200,8 @@ export declare class DriftClient {
|
|
|
200
200
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
201
201
|
forceCancelOrders(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
|
|
202
202
|
getForceCancelOrdersIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
|
|
203
|
-
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
204
|
-
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
203
|
+
placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
204
|
+
getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
205
205
|
placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
|
206
206
|
getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
207
207
|
placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
|
package/lib/driftClient.js
CHANGED
|
@@ -1587,42 +1587,49 @@ class DriftClient {
|
|
|
1587
1587
|
orderParams = this.getOrderParams(orderParams, types_1.MarketType.PERP);
|
|
1588
1588
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1589
1589
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1590
|
+
makerInfo = Array.isArray(makerInfo)
|
|
1591
|
+
? makerInfo
|
|
1592
|
+
: makerInfo
|
|
1593
|
+
? [makerInfo]
|
|
1594
|
+
: [];
|
|
1590
1595
|
const userAccounts = [this.getUserAccount()];
|
|
1591
|
-
|
|
1592
|
-
userAccounts.push(
|
|
1596
|
+
for (const maker of makerInfo) {
|
|
1597
|
+
userAccounts.push(maker.makerUserAccount);
|
|
1593
1598
|
}
|
|
1594
1599
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1595
1600
|
userAccounts,
|
|
1596
1601
|
useMarketLastSlotCache: true,
|
|
1597
1602
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
1598
1603
|
});
|
|
1599
|
-
|
|
1600
|
-
if (makerInfo) {
|
|
1601
|
-
makerOrderId = makerInfo.order.orderId;
|
|
1602
|
-
remainingAccounts.push({
|
|
1603
|
-
pubkey: makerInfo.maker,
|
|
1604
|
-
isSigner: false,
|
|
1605
|
-
isWritable: true,
|
|
1606
|
-
});
|
|
1607
|
-
remainingAccounts.push({
|
|
1608
|
-
pubkey: makerInfo.makerStats,
|
|
1609
|
-
isSigner: false,
|
|
1610
|
-
isWritable: true,
|
|
1611
|
-
});
|
|
1612
|
-
}
|
|
1613
|
-
if (referrerInfo) {
|
|
1604
|
+
for (const maker of makerInfo) {
|
|
1614
1605
|
remainingAccounts.push({
|
|
1615
|
-
pubkey:
|
|
1606
|
+
pubkey: maker.maker,
|
|
1616
1607
|
isWritable: true,
|
|
1617
1608
|
isSigner: false,
|
|
1618
1609
|
});
|
|
1619
1610
|
remainingAccounts.push({
|
|
1620
|
-
pubkey:
|
|
1611
|
+
pubkey: maker.makerStats,
|
|
1621
1612
|
isWritable: true,
|
|
1622
1613
|
isSigner: false,
|
|
1623
1614
|
});
|
|
1624
1615
|
}
|
|
1625
|
-
|
|
1616
|
+
if (referrerInfo) {
|
|
1617
|
+
const referrerIsMaker = makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
|
|
1618
|
+
undefined;
|
|
1619
|
+
if (!referrerIsMaker) {
|
|
1620
|
+
remainingAccounts.push({
|
|
1621
|
+
pubkey: referrerInfo.referrer,
|
|
1622
|
+
isWritable: true,
|
|
1623
|
+
isSigner: false,
|
|
1624
|
+
});
|
|
1625
|
+
remainingAccounts.push({
|
|
1626
|
+
pubkey: referrerInfo.referrerStats,
|
|
1627
|
+
isWritable: true,
|
|
1628
|
+
isSigner: false,
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
return await this.program.instruction.placeAndTakePerpOrder(orderParams, null, {
|
|
1626
1633
|
accounts: {
|
|
1627
1634
|
state: await this.getStatePublicKey(),
|
|
1628
1635
|
user: userAccountPublicKey,
|
package/lib/idl/drift.json
CHANGED
package/package.json
CHANGED
|
@@ -64,6 +64,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
64
64
|
launchTs: 1677068931000,
|
|
65
65
|
oracleSource: OracleSource.PYTH_1M,
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
fullName: 'Polygon',
|
|
69
|
+
category: ['L2', 'Infra'],
|
|
70
|
+
symbol: 'MATIC-PERP',
|
|
71
|
+
baseAssetSymbol: 'MATIC',
|
|
72
|
+
marketIndex: 5,
|
|
73
|
+
oracle: new PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
|
|
74
|
+
launchTs: 1677690149000, //todo
|
|
75
|
+
oracleSource: OracleSource.PYTH,
|
|
76
|
+
},
|
|
67
77
|
];
|
|
68
78
|
|
|
69
79
|
export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
@@ -117,6 +127,16 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
117
127
|
launchTs: 1677690149000,
|
|
118
128
|
oracleSource: OracleSource.PYTH_1M,
|
|
119
129
|
},
|
|
130
|
+
{
|
|
131
|
+
fullName: 'Polygon',
|
|
132
|
+
category: ['L2', 'Infra'],
|
|
133
|
+
symbol: 'MATIC-PERP',
|
|
134
|
+
baseAssetSymbol: 'MATIC',
|
|
135
|
+
marketIndex: 5,
|
|
136
|
+
oracle: new PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
|
|
137
|
+
launchTs: 1677690149000, //todo
|
|
138
|
+
oracleSource: OracleSource.PYTH,
|
|
139
|
+
},
|
|
120
140
|
];
|
|
121
141
|
|
|
122
142
|
export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
|
package/src/driftClient.ts
CHANGED
|
@@ -2736,7 +2736,7 @@ export class DriftClient {
|
|
|
2736
2736
|
|
|
2737
2737
|
public async placeAndTakePerpOrder(
|
|
2738
2738
|
orderParams: OptionalOrderParams,
|
|
2739
|
-
makerInfo?: MakerInfo,
|
|
2739
|
+
makerInfo?: MakerInfo | MakerInfo[],
|
|
2740
2740
|
referrerInfo?: ReferrerInfo,
|
|
2741
2741
|
txParams?: TxParams
|
|
2742
2742
|
): Promise<TransactionSignature> {
|
|
@@ -2759,54 +2759,64 @@ export class DriftClient {
|
|
|
2759
2759
|
|
|
2760
2760
|
public async getPlaceAndTakePerpOrderIx(
|
|
2761
2761
|
orderParams: OptionalOrderParams,
|
|
2762
|
-
makerInfo?: MakerInfo,
|
|
2762
|
+
makerInfo?: MakerInfo | MakerInfo[],
|
|
2763
2763
|
referrerInfo?: ReferrerInfo
|
|
2764
2764
|
): Promise<TransactionInstruction> {
|
|
2765
2765
|
orderParams = this.getOrderParams(orderParams, MarketType.PERP);
|
|
2766
2766
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2767
2767
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2768
2768
|
|
|
2769
|
+
makerInfo = Array.isArray(makerInfo)
|
|
2770
|
+
? makerInfo
|
|
2771
|
+
: makerInfo
|
|
2772
|
+
? [makerInfo]
|
|
2773
|
+
: [];
|
|
2774
|
+
|
|
2769
2775
|
const userAccounts = [this.getUserAccount()];
|
|
2770
|
-
|
|
2771
|
-
userAccounts.push(
|
|
2776
|
+
for (const maker of makerInfo) {
|
|
2777
|
+
userAccounts.push(maker.makerUserAccount);
|
|
2772
2778
|
}
|
|
2779
|
+
|
|
2773
2780
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2774
2781
|
userAccounts,
|
|
2775
2782
|
useMarketLastSlotCache: true,
|
|
2776
2783
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
2777
2784
|
});
|
|
2778
2785
|
|
|
2779
|
-
|
|
2780
|
-
if (makerInfo) {
|
|
2781
|
-
makerOrderId = makerInfo.order.orderId;
|
|
2786
|
+
for (const maker of makerInfo) {
|
|
2782
2787
|
remainingAccounts.push({
|
|
2783
|
-
pubkey:
|
|
2784
|
-
isSigner: false,
|
|
2788
|
+
pubkey: maker.maker,
|
|
2785
2789
|
isWritable: true,
|
|
2790
|
+
isSigner: false,
|
|
2786
2791
|
});
|
|
2787
2792
|
remainingAccounts.push({
|
|
2788
|
-
pubkey:
|
|
2789
|
-
isSigner: false,
|
|
2793
|
+
pubkey: maker.makerStats,
|
|
2790
2794
|
isWritable: true,
|
|
2795
|
+
isSigner: false,
|
|
2791
2796
|
});
|
|
2792
2797
|
}
|
|
2793
2798
|
|
|
2794
2799
|
if (referrerInfo) {
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2800
|
+
const referrerIsMaker =
|
|
2801
|
+
makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
|
|
2802
|
+
undefined;
|
|
2803
|
+
if (!referrerIsMaker) {
|
|
2804
|
+
remainingAccounts.push({
|
|
2805
|
+
pubkey: referrerInfo.referrer,
|
|
2806
|
+
isWritable: true,
|
|
2807
|
+
isSigner: false,
|
|
2808
|
+
});
|
|
2809
|
+
remainingAccounts.push({
|
|
2810
|
+
pubkey: referrerInfo.referrerStats,
|
|
2811
|
+
isWritable: true,
|
|
2812
|
+
isSigner: false,
|
|
2813
|
+
});
|
|
2814
|
+
}
|
|
2805
2815
|
}
|
|
2806
2816
|
|
|
2807
2817
|
return await this.program.instruction.placeAndTakePerpOrder(
|
|
2808
2818
|
orderParams,
|
|
2809
|
-
|
|
2819
|
+
null,
|
|
2810
2820
|
{
|
|
2811
2821
|
accounts: {
|
|
2812
2822
|
state: await this.getStatePublicKey(),
|
package/src/idl/drift.json
CHANGED