@drift-labs/sdk 0.2.0-master.10 → 0.2.0-master.11
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/admin.d.ts +3 -3
- package/lib/admin.js +6 -6
- package/lib/clearingHouse.d.ts +15 -4
- package/lib/clearingHouse.js +200 -37
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +1 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +2 -1
- package/lib/idl/clearing_house.json +484 -103
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/types.d.ts +62 -13
- package/lib/types.js +12 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +1 -1
- package/src/admin.ts +7 -7
- package/src/clearingHouse.ts +335 -47
- package/src/clearingHouseUser.ts +12 -23
- package/src/config.ts +1 -1
- package/src/constants/banks.ts +1 -1
- package/src/constants/numericConstants.ts +1 -0
- package/src/idl/clearing_house.json +484 -103
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +98 -67
- package/src/index.ts +1 -1
- package/src/mockUSDCFaucet.js +276 -167
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/types.ts +63 -13
- package/src/util/computeUnits.ts +1 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"name": "
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"name": "token_faucet",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "initialize",
|
|
7
7
|
"accounts": [
|
|
8
8
|
{
|
|
9
|
-
"name": "
|
|
9
|
+
"name": "faucetConfig",
|
|
10
10
|
"isMut": true,
|
|
11
11
|
"isSigner": false
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"name": "admin",
|
|
15
|
-
"isMut":
|
|
15
|
+
"isMut": true,
|
|
16
16
|
"isSigner": true
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"name": "mintAccount",
|
|
20
|
-
"isMut":
|
|
20
|
+
"isMut": true,
|
|
21
21
|
"isSigner": false
|
|
22
22
|
},
|
|
23
23
|
{
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
"name": "systemProgram",
|
|
30
30
|
"isMut": false,
|
|
31
31
|
"isSigner": false
|
|
32
|
-
}
|
|
33
|
-
],
|
|
34
|
-
"args": [
|
|
32
|
+
},
|
|
35
33
|
{
|
|
36
|
-
"name": "
|
|
37
|
-
"
|
|
34
|
+
"name": "tokenProgram",
|
|
35
|
+
"isMut": false,
|
|
36
|
+
"isSigner": false
|
|
38
37
|
}
|
|
39
|
-
]
|
|
38
|
+
],
|
|
39
|
+
"args": []
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"name": "mintToUser",
|
|
43
43
|
"accounts": [
|
|
44
44
|
{
|
|
45
|
-
"name": "
|
|
45
|
+
"name": "faucetConfig",
|
|
46
46
|
"isMut": false,
|
|
47
47
|
"isSigner": false
|
|
48
48
|
},
|
|
@@ -73,11 +73,42 @@
|
|
|
73
73
|
"type": "u64"
|
|
74
74
|
}
|
|
75
75
|
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "transferMintAuthority",
|
|
79
|
+
"accounts": [
|
|
80
|
+
{
|
|
81
|
+
"name": "faucetConfig",
|
|
82
|
+
"isMut": false,
|
|
83
|
+
"isSigner": false
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"name": "admin",
|
|
87
|
+
"isMut": true,
|
|
88
|
+
"isSigner": true
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "mintAccount",
|
|
92
|
+
"isMut": true,
|
|
93
|
+
"isSigner": false
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"name": "mintAuthority",
|
|
97
|
+
"isMut": false,
|
|
98
|
+
"isSigner": false
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "tokenProgram",
|
|
102
|
+
"isMut": false,
|
|
103
|
+
"isSigner": false
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"args": []
|
|
76
107
|
}
|
|
77
108
|
],
|
|
78
109
|
"accounts": [
|
|
79
110
|
{
|
|
80
|
-
"name": "
|
|
111
|
+
"name": "FaucetConfig",
|
|
81
112
|
"type": {
|
|
82
113
|
"kind": "struct",
|
|
83
114
|
"fields": [
|
|
@@ -103,17 +134,9 @@
|
|
|
103
134
|
],
|
|
104
135
|
"errors": [
|
|
105
136
|
{
|
|
106
|
-
"code":
|
|
137
|
+
"code": 6000,
|
|
107
138
|
"name": "InvalidMintAccountAuthority",
|
|
108
139
|
"msg": "Program not mint authority"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"code": 301,
|
|
112
|
-
"name": "Unauthorized",
|
|
113
|
-
"msg": "Signer must be MockUSDCFaucet admin"
|
|
114
140
|
}
|
|
115
|
-
]
|
|
116
|
-
"metadata": {
|
|
117
|
-
"address": "2z2DLVD3tBWc86pbvvy5qN31v1NXprM6zA5MDr2FMx64"
|
|
118
|
-
}
|
|
141
|
+
]
|
|
119
142
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BN } from '@project-serum/anchor';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import pyth from '@pythnetwork/client';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './tokenFaucet';
|
|
5
5
|
export * from './oracles/types';
|
|
6
6
|
export * from './oracles/pythClient';
|
|
7
7
|
export * from './oracles/switchboardClient';
|
package/lib/index.js
CHANGED
|
@@ -24,7 +24,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
24
24
|
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return web3_js_1.PublicKey; } });
|
|
25
25
|
const client_1 = __importDefault(require("@pythnetwork/client"));
|
|
26
26
|
exports.pyth = client_1.default;
|
|
27
|
-
__exportStar(require("./
|
|
27
|
+
__exportStar(require("./tokenFaucet"), exports);
|
|
28
28
|
__exportStar(require("./oracles/types"), exports);
|
|
29
29
|
__exportStar(require("./oracles/pythClient"), exports);
|
|
30
30
|
__exportStar(require("./oracles/switchboardClient"), exports);
|
|
@@ -5,22 +5,24 @@ import { AccountInfo } from '@solana/spl-token';
|
|
|
5
5
|
import { ConfirmOptions, Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
6
6
|
import { BN } from '.';
|
|
7
7
|
import { IWallet } from './types';
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class TokenFaucet {
|
|
9
9
|
connection: Connection;
|
|
10
10
|
wallet: IWallet;
|
|
11
11
|
program: Program;
|
|
12
12
|
provider: AnchorProvider;
|
|
13
|
+
mint: PublicKey;
|
|
13
14
|
opts?: ConfirmOptions;
|
|
14
|
-
constructor(connection: Connection, wallet: IWallet, programId: PublicKey, opts?: ConfirmOptions);
|
|
15
|
-
|
|
15
|
+
constructor(connection: Connection, wallet: IWallet, programId: PublicKey, mint: PublicKey, opts?: ConfirmOptions);
|
|
16
|
+
getFaucetConfigPublicKeyAndNonce(): Promise<[
|
|
16
17
|
PublicKey,
|
|
17
18
|
number
|
|
18
19
|
]>;
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
getMintAuthority(): Promise<PublicKey>;
|
|
21
|
+
getFaucetConfigPublicKey(): Promise<PublicKey>;
|
|
21
22
|
initialize(): Promise<TransactionSignature>;
|
|
22
23
|
fetchState(): Promise<any>;
|
|
23
24
|
mintToUser(userTokenAccount: PublicKey, amount: BN): Promise<TransactionSignature>;
|
|
25
|
+
transferMintAuthority(): Promise<TransactionSignature>;
|
|
24
26
|
createAssociatedTokenAccountAndMintTo(userPublicKey: PublicKey, amount: BN): Promise<[PublicKey, TransactionSignature]>;
|
|
25
27
|
createAssociatedTokenAccountAndMintToInstructions(userPublicKey: PublicKey, amount: BN): Promise<[PublicKey, TransactionInstruction, TransactionInstruction]>;
|
|
26
28
|
getAssosciatedMockUSDMintAddress(props: {
|
|
@@ -26,74 +26,75 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.TokenFaucet = void 0;
|
|
30
30
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
31
31
|
const anchor_1 = require("@project-serum/anchor");
|
|
32
32
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
33
|
const web3_js_1 = require("@solana/web3.js");
|
|
34
|
-
const
|
|
35
|
-
class
|
|
36
|
-
constructor(connection, wallet, programId, opts) {
|
|
34
|
+
const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
|
|
35
|
+
class TokenFaucet {
|
|
36
|
+
constructor(connection, wallet, programId, mint, opts) {
|
|
37
37
|
this.connection = connection;
|
|
38
38
|
this.wallet = wallet;
|
|
39
39
|
this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
|
|
40
40
|
const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
|
|
41
41
|
this.provider = provider;
|
|
42
|
-
this.program = new anchor_1.Program(
|
|
42
|
+
this.program = new anchor_1.Program(token_faucet_json_1.default, programId, provider);
|
|
43
|
+
this.mint = mint;
|
|
43
44
|
}
|
|
44
|
-
async
|
|
45
|
-
return anchor.web3.PublicKey.findProgramAddress([
|
|
45
|
+
async getFaucetConfigPublicKeyAndNonce() {
|
|
46
|
+
return anchor.web3.PublicKey.findProgramAddress([
|
|
47
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('faucet_config')),
|
|
48
|
+
this.mint.toBuffer(),
|
|
49
|
+
], this.program.programId);
|
|
46
50
|
}
|
|
47
|
-
async
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
async getMintAuthority() {
|
|
52
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
53
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('mint_authority')),
|
|
54
|
+
this.mint.toBuffer(),
|
|
55
|
+
], this.program.programId))[0];
|
|
56
|
+
}
|
|
57
|
+
async getFaucetConfigPublicKey() {
|
|
58
|
+
return (await this.getFaucetConfigPublicKeyAndNonce())[0];
|
|
53
59
|
}
|
|
54
60
|
async initialize() {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
throw new Error('Faucet already initialized');
|
|
58
|
-
}
|
|
59
|
-
const fakeUSDCMint = anchor.web3.Keypair.generate();
|
|
60
|
-
const createUSDCMintAccountIx = web3_js_1.SystemProgram.createAccount({
|
|
61
|
-
fromPubkey: this.wallet.publicKey,
|
|
62
|
-
newAccountPubkey: fakeUSDCMint.publicKey,
|
|
63
|
-
lamports: await spl_token_1.Token.getMinBalanceRentForExemptMint(this.connection),
|
|
64
|
-
space: spl_token_1.MintLayout.span,
|
|
65
|
-
programId: spl_token_1.TOKEN_PROGRAM_ID,
|
|
66
|
-
});
|
|
67
|
-
const [mintAuthority, _mintAuthorityNonce] = await web3_js_1.PublicKey.findProgramAddress([fakeUSDCMint.publicKey.toBuffer()], this.program.programId);
|
|
68
|
-
const initUSDCMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, fakeUSDCMint.publicKey, 6, mintAuthority, null);
|
|
69
|
-
const [mockUSDCFaucetStatePublicKey, mockUSDCFaucetStateNonce] = await this.getMockUSDCFaucetStatePublicKeyAndNonce();
|
|
70
|
-
return await this.program.rpc.initialize(mockUSDCFaucetStateNonce, {
|
|
61
|
+
const [faucetConfigPublicKey] = await this.getFaucetConfigPublicKeyAndNonce();
|
|
62
|
+
return await this.program.rpc.initialize({
|
|
71
63
|
accounts: {
|
|
72
|
-
|
|
64
|
+
faucetConfig: faucetConfigPublicKey,
|
|
73
65
|
admin: this.wallet.publicKey,
|
|
74
|
-
mintAccount:
|
|
66
|
+
mintAccount: this.mint,
|
|
75
67
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
76
68
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
69
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
77
70
|
},
|
|
78
|
-
instructions: [createUSDCMintAccountIx, initUSDCMintIx],
|
|
79
|
-
signers: [fakeUSDCMint],
|
|
80
71
|
});
|
|
81
72
|
}
|
|
82
73
|
async fetchState() {
|
|
83
|
-
return await this.program.account.
|
|
74
|
+
return await this.program.account.faucetConfig.fetch(await this.getFaucetConfigPublicKey());
|
|
84
75
|
}
|
|
85
76
|
async mintToUser(userTokenAccount, amount) {
|
|
86
|
-
const state = await this.fetchState();
|
|
87
77
|
return await this.program.rpc.mintToUser(amount, {
|
|
88
78
|
accounts: {
|
|
89
|
-
|
|
90
|
-
mintAccount:
|
|
79
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
80
|
+
mintAccount: this.mint,
|
|
91
81
|
userTokenAccount,
|
|
92
|
-
mintAuthority:
|
|
82
|
+
mintAuthority: await this.getMintAuthority(),
|
|
93
83
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
94
84
|
},
|
|
95
85
|
});
|
|
96
86
|
}
|
|
87
|
+
async transferMintAuthority() {
|
|
88
|
+
return await this.program.rpc.transferMintAuthority({
|
|
89
|
+
accounts: {
|
|
90
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
91
|
+
mintAccount: this.mint,
|
|
92
|
+
mintAuthority: await this.getMintAuthority(),
|
|
93
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
94
|
+
admin: this.wallet.publicKey,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
97
98
|
async createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
|
|
98
99
|
const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = await this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
|
|
99
100
|
const tx = new web3_js_1.Transaction().add(createAssociatedAccountIx).add(mintToTx);
|
|
@@ -106,7 +107,7 @@ class MockUSDCFaucet {
|
|
|
106
107
|
const createAssociatedAccountIx = spl_token_1.Token.createAssociatedTokenAccountInstruction(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, associateTokenPublicKey, userPublicKey, this.wallet.publicKey);
|
|
107
108
|
const mintToIx = await this.program.instruction.mintToUser(amount, {
|
|
108
109
|
accounts: {
|
|
109
|
-
|
|
110
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
110
111
|
mintAccount: state.mint,
|
|
111
112
|
userTokenAccount: associateTokenPublicKey,
|
|
112
113
|
mintAuthority: state.mintAuthority,
|
|
@@ -143,4 +144,4 @@ class MockUSDCFaucet {
|
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
|
-
exports.
|
|
147
|
+
exports.TokenFaucet = TokenFaucet;
|
package/lib/types.d.ts
CHANGED
|
@@ -187,20 +187,66 @@ export declare type FundingPaymentRecord = {
|
|
|
187
187
|
};
|
|
188
188
|
export declare type LiquidationRecord = {
|
|
189
189
|
ts: BN;
|
|
190
|
-
recordId: BN;
|
|
191
|
-
userAuthority: PublicKey;
|
|
192
190
|
user: PublicKey;
|
|
193
|
-
partial: boolean;
|
|
194
|
-
baseAssetValue: BN;
|
|
195
|
-
baseAssetValueClosed: BN;
|
|
196
|
-
liquidationFee: BN;
|
|
197
|
-
feeToLiquidator: BN;
|
|
198
|
-
feeToInsuranceFund: BN;
|
|
199
191
|
liquidator: PublicKey;
|
|
192
|
+
liquidationType: LiquidationType;
|
|
193
|
+
marginRequirement: BN;
|
|
200
194
|
totalCollateral: BN;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
195
|
+
liquidatePerp: LiquidatePerpRecord;
|
|
196
|
+
liquidateBorrow: LiquidateBorrowRecord;
|
|
197
|
+
liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
|
|
198
|
+
liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
|
|
199
|
+
};
|
|
200
|
+
export declare class LiquidationType {
|
|
201
|
+
static readonly LIQUIDATE_PERP: {
|
|
202
|
+
liquidatePerp: {};
|
|
203
|
+
};
|
|
204
|
+
static readonly LIQUIDATE_BORROW: {
|
|
205
|
+
liquidateBorrow: {};
|
|
206
|
+
};
|
|
207
|
+
static readonly LIQUIDATE_BORROW_FOR_PERP_PNL: {
|
|
208
|
+
liquidateBorrowForPerpPnl: {};
|
|
209
|
+
};
|
|
210
|
+
static readonly LIQUIDATE_PERP_PNL_FOR_DEPOSIT: {
|
|
211
|
+
liquidatePerpPnlForDeposit: {};
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
export declare type LiquidatePerpRecord = {
|
|
215
|
+
marketIndex: BN;
|
|
216
|
+
orderIds: BN[];
|
|
217
|
+
oraclePrice: BN;
|
|
218
|
+
baseAssetAmount: BN;
|
|
219
|
+
quoteAssetAmount: BN;
|
|
220
|
+
userPnl: BN;
|
|
221
|
+
liquidatorPnl: BN;
|
|
222
|
+
canceledOrdersFee: BN;
|
|
223
|
+
userOrderId: BN;
|
|
224
|
+
liquidatorOrderId: BN;
|
|
225
|
+
fillRecordId: BN;
|
|
226
|
+
};
|
|
227
|
+
export declare type LiquidateBorrowRecord = {
|
|
228
|
+
assetBankIndex: BN;
|
|
229
|
+
assetPrice: BN;
|
|
230
|
+
assetTransfer: BN;
|
|
231
|
+
liabilityBankIndex: BN;
|
|
232
|
+
liabilityPrice: BN;
|
|
233
|
+
liabilityTransfer: BN;
|
|
234
|
+
};
|
|
235
|
+
export declare type LiquidateBorrowForPerpPnlRecord = {
|
|
236
|
+
marketIndex: BN;
|
|
237
|
+
marketOraclePrice: BN;
|
|
238
|
+
pnlTransfer: BN;
|
|
239
|
+
liabilityBankIndex: BN;
|
|
240
|
+
liabilityPrice: BN;
|
|
241
|
+
liabilityTransfer: BN;
|
|
242
|
+
};
|
|
243
|
+
export declare type LiquidatePerpPnlForDepositRecord = {
|
|
244
|
+
marketIndex: BN;
|
|
245
|
+
marketOraclePrice: BN;
|
|
246
|
+
pnlTransfer: BN;
|
|
247
|
+
assetBankIndex: BN;
|
|
248
|
+
assetPrice: BN;
|
|
249
|
+
assetTransfer: BN;
|
|
204
250
|
};
|
|
205
251
|
export declare type OrderRecord = {
|
|
206
252
|
ts: BN;
|
|
@@ -264,9 +310,9 @@ export declare type MarketAccount = {
|
|
|
264
310
|
openInterest: BN;
|
|
265
311
|
marginRatioInitial: number;
|
|
266
312
|
marginRatioMaintenance: number;
|
|
267
|
-
marginRatioPartial: number;
|
|
268
313
|
nextFillRecordId: BN;
|
|
269
314
|
pnlPool: PoolBalance;
|
|
315
|
+
liquidationFee: BN;
|
|
270
316
|
};
|
|
271
317
|
export declare type BankAccount = {
|
|
272
318
|
bankIndex: BN;
|
|
@@ -289,6 +335,7 @@ export declare type BankAccount = {
|
|
|
289
335
|
maintenanceAssetWeight: BN;
|
|
290
336
|
initialLiabilityWeight: BN;
|
|
291
337
|
maintenanceLiabilityWeight: BN;
|
|
338
|
+
liquidationFee: BN;
|
|
292
339
|
};
|
|
293
340
|
export declare type PoolBalance = {
|
|
294
341
|
balance: BN;
|
|
@@ -366,6 +413,7 @@ export declare type UserAccount = {
|
|
|
366
413
|
};
|
|
367
414
|
positions: UserPosition[];
|
|
368
415
|
orders: Order[];
|
|
416
|
+
beingLiquidated: boolean;
|
|
369
417
|
};
|
|
370
418
|
export declare type UserBankBalance = {
|
|
371
419
|
bankIndex: BN;
|
|
@@ -505,6 +553,7 @@ export declare type FeeStructure = {
|
|
|
505
553
|
makerRebateNumerator: BN;
|
|
506
554
|
makerRebateDenominator: BN;
|
|
507
555
|
fillerRewardStructure: OrderFillerRewardStructure;
|
|
556
|
+
cancelOrderFee: BN;
|
|
508
557
|
};
|
|
509
558
|
export declare type OracleGuardRails = {
|
|
510
559
|
priceDivergence: {
|
|
@@ -523,4 +572,4 @@ export declare type OrderFillerRewardStructure = {
|
|
|
523
572
|
rewardDenominator: BN;
|
|
524
573
|
timeBasedRewardLowerBound: BN;
|
|
525
574
|
};
|
|
526
|
-
export declare type MarginCategory = 'Initial' | '
|
|
575
|
+
export declare type MarginCategory = 'Initial' | 'Maintenance';
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultOrderParams = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
3
|
+
exports.DefaultOrderParams = exports.LiquidationType = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
// # Utility Types / Enums / Constants
|
|
6
6
|
class SwapDirection {
|
|
@@ -91,6 +91,17 @@ var TradeSide;
|
|
|
91
91
|
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
92
92
|
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
93
93
|
})(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
|
|
94
|
+
class LiquidationType {
|
|
95
|
+
}
|
|
96
|
+
exports.LiquidationType = LiquidationType;
|
|
97
|
+
LiquidationType.LIQUIDATE_PERP = { liquidatePerp: {} };
|
|
98
|
+
LiquidationType.LIQUIDATE_BORROW = { liquidateBorrow: {} };
|
|
99
|
+
LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
|
|
100
|
+
liquidateBorrowForPerpPnl: {},
|
|
101
|
+
};
|
|
102
|
+
LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
103
|
+
liquidatePerpPnlForDeposit: {},
|
|
104
|
+
};
|
|
94
105
|
exports.DefaultOrderParams = {
|
|
95
106
|
orderType: OrderType.MARKET,
|
|
96
107
|
userOrderId: 0,
|
package/lib/util/computeUnits.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.findComputeUnitConsumption = void 0;
|
|
|
4
4
|
async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
5
5
|
const tx = await connection.getTransaction(txSignature, { commitment });
|
|
6
6
|
const computeUnits = [];
|
|
7
|
-
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of
|
|
7
|
+
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
|
|
8
8
|
tx.meta.logMessages.forEach((logMessage) => {
|
|
9
9
|
const match = logMessage.match(regex);
|
|
10
10
|
if (match && match[1]) {
|
package/package.json
CHANGED
package/src/admin.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from './addresses/pda';
|
|
21
21
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
22
|
import { ClearingHouse } from './clearingHouse';
|
|
23
|
-
import { PEG_PRECISION } from './constants/numericConstants';
|
|
23
|
+
import { PEG_PRECISION, ZERO } from './constants/numericConstants';
|
|
24
24
|
import { calculateTargetPriceTrade } from './math/trade';
|
|
25
25
|
import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
|
|
26
26
|
|
|
@@ -86,7 +86,8 @@ export class Admin extends ClearingHouse {
|
|
|
86
86
|
maintenanceAssetWeight: BN,
|
|
87
87
|
initialLiabilityWeight: BN,
|
|
88
88
|
maintenanceLiabilityWeight: BN,
|
|
89
|
-
imfFactor = new BN(0)
|
|
89
|
+
imfFactor = new BN(0),
|
|
90
|
+
liquidationFee = ZERO
|
|
90
91
|
): Promise<TransactionSignature> {
|
|
91
92
|
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
92
93
|
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
@@ -111,6 +112,7 @@ export class Admin extends ClearingHouse {
|
|
|
111
112
|
initialLiabilityWeight,
|
|
112
113
|
maintenanceLiabilityWeight,
|
|
113
114
|
imfFactor,
|
|
115
|
+
liquidationFee,
|
|
114
116
|
{
|
|
115
117
|
accounts: {
|
|
116
118
|
admin: this.wallet.publicKey,
|
|
@@ -146,8 +148,8 @@ export class Admin extends ClearingHouse {
|
|
|
146
148
|
pegMultiplier: BN = PEG_PRECISION,
|
|
147
149
|
oracleSource: OracleSource = OracleSource.PYTH,
|
|
148
150
|
marginRatioInitial = 2000,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
marginRatioMaintenance = 500,
|
|
152
|
+
liquidationFee = ZERO
|
|
151
153
|
): Promise<TransactionSignature> {
|
|
152
154
|
const marketPublicKey = await getMarketPublicKey(
|
|
153
155
|
this.program.programId,
|
|
@@ -161,8 +163,8 @@ export class Admin extends ClearingHouse {
|
|
|
161
163
|
pegMultiplier,
|
|
162
164
|
oracleSource,
|
|
163
165
|
marginRatioInitial,
|
|
164
|
-
marginRatioPartial,
|
|
165
166
|
marginRatioMaintenance,
|
|
167
|
+
liquidationFee,
|
|
166
168
|
{
|
|
167
169
|
accounts: {
|
|
168
170
|
state: await this.getStatePublicKey(),
|
|
@@ -422,12 +424,10 @@ export class Admin extends ClearingHouse {
|
|
|
422
424
|
public async updateMarginRatio(
|
|
423
425
|
marketIndex: BN,
|
|
424
426
|
marginRatioInitial: number,
|
|
425
|
-
marginRatioPartial: number,
|
|
426
427
|
marginRatioMaintenance: number
|
|
427
428
|
): Promise<TransactionSignature> {
|
|
428
429
|
return await this.program.rpc.updateMarginRatio(
|
|
429
430
|
marginRatioInitial,
|
|
430
|
-
marginRatioPartial,
|
|
431
431
|
marginRatioMaintenance,
|
|
432
432
|
{
|
|
433
433
|
accounts: {
|