@drift-labs/sdk 0.1.25-master.0 → 0.1.28

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.
Files changed (121) hide show
  1. package/lib/accounts/pollingOracleSubscriber.d.ts +26 -0
  2. package/lib/accounts/pollingOracleSubscriber.js +79 -0
  3. package/lib/accounts/types.d.ts +14 -1
  4. package/lib/clearingHouse.d.ts +6 -4
  5. package/lib/clearingHouse.js +56 -7
  6. package/lib/constants/markets.d.ts +4 -2
  7. package/lib/constants/markets.js +76 -28
  8. package/lib/idl/clearing_house.json +65 -1
  9. package/lib/index.d.ts +1 -0
  10. package/lib/index.js +1 -0
  11. package/lib/math/market.d.ts +2 -0
  12. package/lib/math/market.js +6 -1
  13. package/lib/orderParams.d.ts +1 -1
  14. package/lib/orderParams.js +2 -2
  15. package/lib/orders.d.ts +3 -2
  16. package/lib/orders.js +11 -4
  17. package/lib/types.d.ts +3 -0
  18. package/lib/types.js +1 -0
  19. package/package.json +1 -1
  20. package/src/accounts/bulkAccountLoader.js +180 -0
  21. package/src/accounts/bulkAccountLoader.js.map +1 -0
  22. package/src/accounts/bulkUserSubscription.js +56 -0
  23. package/src/accounts/bulkUserSubscription.js.map +1 -0
  24. package/src/accounts/pollingClearingHouseAccountSubscriber.js +210 -0
  25. package/src/accounts/pollingClearingHouseAccountSubscriber.js.map +1 -0
  26. package/src/accounts/pollingOracleSubscriber.js +65 -0
  27. package/src/accounts/pollingOracleSubscriber.js.map +1 -0
  28. package/src/accounts/pollingOracleSubscriber.ts +103 -0
  29. package/src/accounts/pollingTokenAccountSubscriber.js +65 -0
  30. package/src/accounts/pollingTokenAccountSubscriber.js.map +1 -0
  31. package/src/accounts/pollingUserAccountSubscriber.js +139 -0
  32. package/src/accounts/pollingUserAccountSubscriber.js.map +1 -0
  33. package/src/accounts/types.js +1 -0
  34. package/src/accounts/types.js.map +1 -0
  35. package/src/accounts/types.ts +22 -1
  36. package/src/accounts/utils.js +1 -0
  37. package/src/accounts/utils.js.map +1 -0
  38. package/src/accounts/webSocketAccountSubscriber.js +15 -27
  39. package/src/accounts/webSocketAccountSubscriber.js.map +1 -0
  40. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +212 -0
  41. package/src/accounts/webSocketClearingHouseAccountSubscriber.js.map +1 -0
  42. package/src/accounts/webSocketUserAccountSubscriber.js +78 -0
  43. package/src/accounts/webSocketUserAccountSubscriber.js.map +1 -0
  44. package/src/addresses.js +20 -44
  45. package/src/addresses.js.map +1 -0
  46. package/src/admin.js +443 -0
  47. package/src/admin.js.map +1 -0
  48. package/src/assert/assert.js +10 -0
  49. package/src/assert/assert.js.map +1 -0
  50. package/src/clearingHouse.ts +85 -7
  51. package/src/clearingHouseUser.js +581 -0
  52. package/src/clearingHouseUser.js.map +1 -0
  53. package/src/config.js +37 -0
  54. package/src/config.js.map +1 -0
  55. package/src/constants/markets.js +167 -0
  56. package/src/constants/markets.js.map +1 -0
  57. package/src/constants/markets.ts +80 -30
  58. package/src/constants/numericConstants.js +22 -0
  59. package/src/constants/numericConstants.js.map +1 -0
  60. package/src/factory/clearingHouse.js +65 -0
  61. package/src/factory/clearingHouse.js.map +1 -0
  62. package/src/factory/clearingHouseUser.js +35 -0
  63. package/src/factory/clearingHouseUser.js.map +1 -0
  64. package/src/factory/oracleClient.js +17 -0
  65. package/src/factory/oracleClient.js.map +1 -0
  66. package/src/idl/clearing_house.json +65 -1
  67. package/src/index.js +56 -0
  68. package/src/index.js.map +1 -0
  69. package/src/index.ts +1 -0
  70. package/src/math/amm.js +285 -0
  71. package/src/math/amm.js.map +1 -0
  72. package/src/math/conversion.js +16 -0
  73. package/src/math/conversion.js.map +1 -0
  74. package/src/math/funding.js +223 -0
  75. package/src/math/funding.js.map +1 -0
  76. package/src/math/insuranceFund.js +23 -0
  77. package/src/math/insuranceFund.js.map +1 -0
  78. package/src/math/market.js +30 -0
  79. package/src/math/market.js.map +1 -0
  80. package/src/math/market.ts +9 -0
  81. package/src/math/orders.js +73 -0
  82. package/src/math/orders.js.map +1 -0
  83. package/src/math/position.js +121 -0
  84. package/src/math/position.js.map +1 -0
  85. package/src/math/trade.js +182 -0
  86. package/src/math/trade.js.map +1 -0
  87. package/src/math/utils.js +27 -0
  88. package/src/math/utils.js.map +1 -0
  89. package/src/mockUSDCFaucet.js +88 -116
  90. package/src/mockUSDCFaucet.js.map +1 -0
  91. package/src/oracles/pythClient.js +39 -0
  92. package/src/oracles/pythClient.js.map +1 -0
  93. package/src/oracles/switchboardClient.js +60 -0
  94. package/src/oracles/switchboardClient.js.map +1 -0
  95. package/src/oracles/types.js +3 -0
  96. package/src/oracles/types.js.map +1 -0
  97. package/src/orderParams.js +109 -0
  98. package/src/orderParams.js.map +1 -0
  99. package/src/orderParams.ts +3 -2
  100. package/src/orders.js +172 -0
  101. package/src/orders.js.map +1 -0
  102. package/src/orders.ts +17 -4
  103. package/src/token/index.js +39 -0
  104. package/src/token/index.js.map +1 -0
  105. package/src/tx/defaultTxSender.js +13 -0
  106. package/src/tx/defaultTxSender.js.map +1 -0
  107. package/src/tx/retryTxSender.js +137 -0
  108. package/src/tx/retryTxSender.js.map +1 -0
  109. package/src/tx/types.js +3 -0
  110. package/src/tx/types.js.map +1 -0
  111. package/src/tx/utils.js +9 -0
  112. package/src/tx/utils.js.map +1 -0
  113. package/src/types.js +1 -0
  114. package/src/types.js.map +1 -0
  115. package/src/types.ts +1 -0
  116. package/src/util/computeUnits.js +17 -0
  117. package/src/util/computeUnits.js.map +1 -0
  118. package/src/util/tps.js +17 -0
  119. package/src/util/tps.js.map +1 -0
  120. package/src/wallet.js +23 -0
  121. package/src/wallet.js.map +1 -0
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
23
  };
@@ -46,126 +37,107 @@ class MockUSDCFaucet {
46
37
  this.provider = provider;
47
38
  this.program = new anchor_1.Program(mock_usdc_faucet_json_1.default, programId, provider);
48
39
  }
49
- getMockUSDCFaucetStatePublicKeyAndNonce() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('mock_usdc_faucet'))], this.program.programId);
52
- });
40
+ async getMockUSDCFaucetStatePublicKeyAndNonce() {
41
+ return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('mock_usdc_faucet'))], this.program.programId);
53
42
  }
54
- getMockUSDCFaucetStatePublicKey() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (this.mockUSDCFaucetStatePublicKey) {
57
- return this.mockUSDCFaucetStatePublicKey;
58
- }
59
- this.mockUSDCFaucetStatePublicKey = (yield this.getMockUSDCFaucetStatePublicKeyAndNonce())[0];
43
+ async getMockUSDCFaucetStatePublicKey() {
44
+ if (this.mockUSDCFaucetStatePublicKey) {
60
45
  return this.mockUSDCFaucetStatePublicKey;
61
- });
46
+ }
47
+ this.mockUSDCFaucetStatePublicKey = (await this.getMockUSDCFaucetStatePublicKeyAndNonce())[0];
48
+ return this.mockUSDCFaucetStatePublicKey;
62
49
  }
63
- initialize() {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const stateAccountRPCResponse = yield this.connection.getParsedAccountInfo(yield this.getMockUSDCFaucetStatePublicKey());
66
- if (stateAccountRPCResponse.value !== null) {
67
- throw new Error('Faucet already initialized');
68
- }
69
- const fakeUSDCMint = anchor.web3.Keypair.generate();
70
- const createUSDCMintAccountIx = web3_js_1.SystemProgram.createAccount({
71
- fromPubkey: this.wallet.publicKey,
72
- newAccountPubkey: fakeUSDCMint.publicKey,
73
- lamports: yield spl_token_1.Token.getMinBalanceRentForExemptMint(this.connection),
74
- space: spl_token_1.MintLayout.span,
75
- programId: spl_token_1.TOKEN_PROGRAM_ID,
76
- });
77
- const [mintAuthority, _mintAuthorityNonce] = yield web3_js_1.PublicKey.findProgramAddress([fakeUSDCMint.publicKey.toBuffer()], this.program.programId);
78
- const initUSDCMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, fakeUSDCMint.publicKey, 6, mintAuthority, null);
79
- const [mockUSDCFaucetStatePublicKey, mockUSDCFaucetStateNonce] = yield this.getMockUSDCFaucetStatePublicKeyAndNonce();
80
- return yield this.program.rpc.initialize(mockUSDCFaucetStateNonce, {
81
- accounts: {
82
- mockUsdcFaucetState: mockUSDCFaucetStatePublicKey,
83
- admin: this.wallet.publicKey,
84
- mintAccount: fakeUSDCMint.publicKey,
85
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
86
- systemProgram: anchor.web3.SystemProgram.programId,
87
- },
88
- instructions: [createUSDCMintAccountIx, initUSDCMintIx],
89
- signers: [fakeUSDCMint],
90
- });
50
+ async initialize() {
51
+ const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getMockUSDCFaucetStatePublicKey());
52
+ if (stateAccountRPCResponse.value !== null) {
53
+ throw new Error('Faucet already initialized');
54
+ }
55
+ const fakeUSDCMint = anchor.web3.Keypair.generate();
56
+ const createUSDCMintAccountIx = web3_js_1.SystemProgram.createAccount({
57
+ fromPubkey: this.wallet.publicKey,
58
+ newAccountPubkey: fakeUSDCMint.publicKey,
59
+ lamports: await spl_token_1.Token.getMinBalanceRentForExemptMint(this.connection),
60
+ space: spl_token_1.MintLayout.span,
61
+ programId: spl_token_1.TOKEN_PROGRAM_ID,
91
62
  });
92
- }
93
- fetchState() {
94
- return __awaiter(this, void 0, void 0, function* () {
95
- return yield this.program.account.mockUsdcFaucetState.fetch(yield this.getMockUSDCFaucetStatePublicKey());
63
+ const [mintAuthority, _mintAuthorityNonce] = await web3_js_1.PublicKey.findProgramAddress([fakeUSDCMint.publicKey.toBuffer()], this.program.programId);
64
+ const initUSDCMintIx = spl_token_1.Token.createInitMintInstruction(spl_token_1.TOKEN_PROGRAM_ID, fakeUSDCMint.publicKey, 6, mintAuthority, null);
65
+ const [mockUSDCFaucetStatePublicKey, mockUSDCFaucetStateNonce] = await this.getMockUSDCFaucetStatePublicKeyAndNonce();
66
+ return await this.program.rpc.initialize(mockUSDCFaucetStateNonce, {
67
+ accounts: {
68
+ mockUsdcFaucetState: mockUSDCFaucetStatePublicKey,
69
+ admin: this.wallet.publicKey,
70
+ mintAccount: fakeUSDCMint.publicKey,
71
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
72
+ systemProgram: anchor.web3.SystemProgram.programId,
73
+ },
74
+ instructions: [createUSDCMintAccountIx, initUSDCMintIx],
75
+ signers: [fakeUSDCMint],
96
76
  });
97
77
  }
98
- mintToUser(userTokenAccount, amount) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const state = yield this.fetchState();
101
- return yield this.program.rpc.mintToUser(amount, {
102
- accounts: {
103
- mockUsdcFaucetState: yield this.getMockUSDCFaucetStatePublicKey(),
104
- mintAccount: state.mint,
105
- userTokenAccount,
106
- mintAuthority: state.mintAuthority,
107
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
108
- },
109
- });
110
- });
78
+ async fetchState() {
79
+ return await this.program.account.mockUsdcFaucetState.fetch(await this.getMockUSDCFaucetStatePublicKey());
111
80
  }
112
- createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = yield this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
115
- const tx = new web3_js_1.Transaction().add(createAssociatedAccountIx).add(mintToTx);
116
- const txSig = yield this.program.provider.send(tx, [], this.opts);
117
- return [associatedTokenPublicKey, txSig];
81
+ async mintToUser(userTokenAccount, amount) {
82
+ const state = await this.fetchState();
83
+ return await this.program.rpc.mintToUser(amount, {
84
+ accounts: {
85
+ mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
86
+ mintAccount: state.mint,
87
+ userTokenAccount,
88
+ mintAuthority: state.mintAuthority,
89
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
90
+ },
118
91
  });
119
92
  }
120
- createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- const state = yield this.fetchState();
123
- const associateTokenPublicKey = yield this.getAssosciatedMockUSDMintAddress({ userPubKey: userPublicKey });
124
- 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);
125
- const mintToIx = yield this.program.instruction.mintToUser(amount, {
126
- accounts: {
127
- mockUsdcFaucetState: yield this.getMockUSDCFaucetStatePublicKey(),
128
- mintAccount: state.mint,
129
- userTokenAccount: associateTokenPublicKey,
130
- mintAuthority: state.mintAuthority,
131
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
132
- },
133
- });
134
- return [associateTokenPublicKey, createAssociatedAccountIx, mintToIx];
135
- });
93
+ async createAssociatedTokenAccountAndMintTo(userPublicKey, amount) {
94
+ const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] = await this.createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount);
95
+ const tx = new web3_js_1.Transaction().add(createAssociatedAccountIx).add(mintToTx);
96
+ const txSig = await this.program.provider.send(tx, [], this.opts);
97
+ return [associatedTokenPublicKey, txSig];
136
98
  }
137
- getAssosciatedMockUSDMintAddress(props) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- const state = yield this.fetchState();
140
- return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, props.userPubKey);
99
+ async createAssociatedTokenAccountAndMintToInstructions(userPublicKey, amount) {
100
+ const state = await this.fetchState();
101
+ const associateTokenPublicKey = await this.getAssosciatedMockUSDMintAddress({ userPubKey: userPublicKey });
102
+ 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);
103
+ const mintToIx = await this.program.instruction.mintToUser(amount, {
104
+ accounts: {
105
+ mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
106
+ mintAccount: state.mint,
107
+ userTokenAccount: associateTokenPublicKey,
108
+ mintAuthority: state.mintAuthority,
109
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
110
+ },
141
111
  });
112
+ return [associateTokenPublicKey, createAssociatedAccountIx, mintToIx];
142
113
  }
143
- getTokenAccountInfo(props) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const assosciatedKey = yield this.getAssosciatedMockUSDMintAddress(props);
146
- const state = yield this.fetchState();
147
- const token = new spl_token_1.Token(this.connection, state.mint, spl_token_1.TOKEN_PROGRAM_ID,
148
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
149
- // @ts-ignore
150
- this.provider.payer);
151
- return yield token.getAccountInfo(assosciatedKey);
152
- });
114
+ async getAssosciatedMockUSDMintAddress(props) {
115
+ const state = await this.fetchState();
116
+ return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, state.mint, props.userPubKey);
153
117
  }
154
- subscribeToTokenAccount(props) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- try {
157
- const tokenAccountKey = yield this.getAssosciatedMockUSDMintAddress(props);
158
- props.callback(yield this.getTokenAccountInfo(props));
159
- // Couldn't find a way to do it using anchor framework subscription, someone on serum discord recommended this way
160
- this.connection.onAccountChange(tokenAccountKey, (_accountInfo /* accountInfo is a buffer which we don't know how to deserialize */) => __awaiter(this, void 0, void 0, function* () {
161
- props.callback(yield this.getTokenAccountInfo(props));
162
- }));
163
- return true;
164
- }
165
- catch (e) {
166
- return false;
167
- }
168
- });
118
+ async getTokenAccountInfo(props) {
119
+ const assosciatedKey = await this.getAssosciatedMockUSDMintAddress(props);
120
+ const state = await this.fetchState();
121
+ const token = new spl_token_1.Token(this.connection, state.mint, spl_token_1.TOKEN_PROGRAM_ID,
122
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
123
+ // @ts-ignore
124
+ this.provider.payer);
125
+ return await token.getAccountInfo(assosciatedKey);
126
+ }
127
+ async subscribeToTokenAccount(props) {
128
+ try {
129
+ const tokenAccountKey = await this.getAssosciatedMockUSDMintAddress(props);
130
+ props.callback(await this.getTokenAccountInfo(props));
131
+ // Couldn't find a way to do it using anchor framework subscription, someone on serum discord recommended this way
132
+ this.connection.onAccountChange(tokenAccountKey, async (_accountInfo /* accountInfo is a buffer which we don't know how to deserialize */) => {
133
+ props.callback(await this.getTokenAccountInfo(props));
134
+ });
135
+ return true;
136
+ }
137
+ catch (e) {
138
+ return false;
139
+ }
169
140
  }
170
141
  }
171
142
  exports.MockUSDCFaucet = MockUSDCFaucet;
143
+ //# sourceMappingURL=mockUSDCFaucet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockUSDCFaucet.js","sourceRoot":"","sources":["mockUSDCFaucet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgD;AAChD,kDAA+D;AAC/D,iDAM2B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AAQ,CAAC,KAAK,CACnB,CAAC;QAEF,OAAO,MAAM,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,uBAAuB,CAAC,KAGpC;QACA,IAAI;YACH,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,gCAAgC,CAClE,KAAK,CACL,CAAC;YAEF,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;YAEtD,kHAAkH;YAClH,IAAI,CAAC,UAAU,CAAC,eAAe,CAC9B,eAAe,EACf,KAAK,EACJ,YAAY,CAAC,oEAAoE,EAChF,EAAE;gBACH,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;YACvD,CAAC,CACD,CAAC;YAEF,OAAO,IAAI,CAAC;SACZ;QAAC,OAAO,CAAC,EAAE;YACX,OAAO,KAAK,CAAC;SACb;IACF,CAAC;CACD;AAtND,wCAsNC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertPythPrice = exports.PythClient = void 0;
4
+ const client_1 = require("@pythnetwork/client");
5
+ const anchor_1 = require("@project-serum/anchor");
6
+ const numericConstants_1 = require("../constants/numericConstants");
7
+ class PythClient {
8
+ constructor(connection) {
9
+ this.connection = connection;
10
+ }
11
+ async getPriceData(pricePublicKey) {
12
+ const account = await this.connection.getAccountInfo(pricePublicKey);
13
+ return (0, client_1.parsePriceData)(account.data);
14
+ }
15
+ async getOraclePriceData(pricePublicKey) {
16
+ const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
17
+ return this.getOraclePriceDataFromBuffer(accountInfo.data);
18
+ }
19
+ async getOraclePriceDataFromBuffer(buffer) {
20
+ const priceData = (0, client_1.parsePriceData)(buffer);
21
+ return {
22
+ price: convertPythPrice(priceData.price, priceData.exponent),
23
+ slot: new anchor_1.BN(priceData.lastSlot.toString()),
24
+ confidence: convertPythPrice(priceData.confidence, priceData.exponent),
25
+ twap: convertPythPrice(priceData.twap.value, priceData.exponent),
26
+ twapConfidence: convertPythPrice(priceData.twac.value, priceData.exponent),
27
+ };
28
+ }
29
+ }
30
+ exports.PythClient = PythClient;
31
+ function convertPythPrice(price, exponent) {
32
+ exponent = Math.abs(exponent);
33
+ const pythPrecision = numericConstants_1.TEN.pow(new anchor_1.BN(exponent).abs());
34
+ return new anchor_1.BN(price * Math.pow(10, exponent))
35
+ .mul(numericConstants_1.MARK_PRICE_PRECISION)
36
+ .div(pythPrecision);
37
+ }
38
+ exports.convertPythPrice = convertPythPrice;
39
+ //# sourceMappingURL=pythClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pythClient.js","sourceRoot":"","sources":["pythClient.ts"],"names":[],"mappings":";;;AAAA,gDAAgE;AAGhE,kDAA2C;AAC3C,oEAA0E;AAE1E,MAAa,UAAU;IAGtB,YAAmB,UAAsB;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,cAAyB;QAClD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACrE,OAAO,IAAA,uBAAc,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC9B,cAAyB;QAEzB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACzE,OAAO,IAAI,CAAC,4BAA4B,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,4BAA4B,CACxC,MAAc;QAEd,MAAM,SAAS,GAAG,IAAA,uBAAc,EAAC,MAAM,CAAC,CAAC;QACzC,OAAO;YACN,KAAK,EAAE,gBAAgB,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC;YAC5D,IAAI,EAAE,IAAI,WAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC3C,UAAU,EAAE,gBAAgB,CAAC,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC;YACtE,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC;YAChE,cAAc,EAAE,gBAAgB,CAC/B,SAAS,CAAC,IAAI,CAAC,KAAK,EACpB,SAAS,CAAC,QAAQ,CAClB;SACD,CAAC;IACH,CAAC;CACD;AAlCD,gCAkCC;AAED,SAAgB,gBAAgB,CAAC,KAAa,EAAE,QAAgB;IAC/D,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,MAAM,aAAa,GAAG,sBAAG,CAAC,GAAG,CAAC,IAAI,WAAE,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IACtD,OAAO,IAAI,WAAE,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;SAC3C,GAAG,CAAC,uCAAoB,CAAC;SACzB,GAAG,CAAC,aAAa,CAAC,CAAC;AACtB,CAAC;AAND,4CAMC"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SwitchboardClient = void 0;
7
+ const switchboard_v2_1 = require("@switchboard-xyz/switchboard-v2");
8
+ const web3_js_1 = require("@solana/web3.js");
9
+ const anchor_1 = require("@project-serum/anchor");
10
+ const numericConstants_1 = require("../constants/numericConstants");
11
+ const wallet_1 = require("../wallet");
12
+ const switchboard_v2_json_1 = __importDefault(require("../idl/switchboard_v2.json"));
13
+ // cache switchboard program for every client object since itll always be the same
14
+ const programMap = new Map();
15
+ class SwitchboardClient {
16
+ constructor(connection, env) {
17
+ this.connection = connection;
18
+ this.env = env;
19
+ }
20
+ async getOraclePriceData(pricePublicKey) {
21
+ const accountInfo = await this.connection.getAccountInfo(pricePublicKey);
22
+ return this.getOraclePriceDataFromBuffer(accountInfo.data);
23
+ }
24
+ async getOraclePriceDataFromBuffer(buffer) {
25
+ const program = await this.getProgram();
26
+ const aggregatorAccountData = program.account.aggregatorAccountData.coder.accounts.decode('AggregatorAccountData', buffer);
27
+ const price = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound.result);
28
+ const confidence = convertSwitchboardDecimal(aggregatorAccountData.latestConfirmedRound
29
+ .stdDeviation);
30
+ const slot = aggregatorAccountData.latestConfirmedRound.roundOpenSlot;
31
+ return {
32
+ price,
33
+ slot,
34
+ confidence,
35
+ };
36
+ }
37
+ async getProgram() {
38
+ if (programMap.has(this.env)) {
39
+ return programMap.get(this.env);
40
+ }
41
+ const program = await getSwitchboardProgram(this.env, this.connection);
42
+ programMap.set(this.env, program);
43
+ return program;
44
+ }
45
+ }
46
+ exports.SwitchboardClient = SwitchboardClient;
47
+ async function getSwitchboardProgram(env, connection) {
48
+ const DEFAULT_KEYPAIR = web3_js_1.Keypair.fromSeed(new Uint8Array(32).fill(1));
49
+ const programId = (0, switchboard_v2_1.getSwitchboardPid)(env);
50
+ const wallet = new wallet_1.Wallet(DEFAULT_KEYPAIR);
51
+ const provider = new anchor_1.Provider(connection, wallet, {});
52
+ return new anchor_1.Program(switchboard_v2_json_1.default, programId, provider);
53
+ }
54
+ function convertSwitchboardDecimal(switchboardDecimal) {
55
+ const switchboardPrecision = numericConstants_1.TEN.pow(new anchor_1.BN(switchboardDecimal.scale));
56
+ return switchboardDecimal.mantissa
57
+ .mul(numericConstants_1.MARK_PRICE_PRECISION)
58
+ .div(switchboardPrecision);
59
+ }
60
+ //# sourceMappingURL=switchboardClient.js.map
@@ -0,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YAC7B,OAAO,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChC;QAED,MAAM,OAAO,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACvE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAClC,OAAO,OAAO,CAAC;IAChB,CAAC;CACD;AApDD,8CAoDC;AAED,KAAK,UAAU,qBAAqB,CACnC,GAAa,EACb,UAAsB;IAEtB,MAAM,eAAe,GAAG,iBAAO,CAAC,QAAQ,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,IAAA,kCAAiB,EAAC,GAAG,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAI,iBAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAEtD,OAAO,IAAI,gBAAO,CAAC,6BAAuB,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,yBAAyB,CAAC,kBAAsC;IACxE,MAAM,oBAAoB,GAAG,sBAAG,CAAC,GAAG,CAAC,IAAI,WAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO,kBAAkB,CAAC,QAAQ;SAChC,GAAG,CAAC,uCAAoB,CAAC;SACzB,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
4
+ const types_1 = require("./types");
5
+ const numericConstants_1 = require("./constants/numericConstants");
6
+ function getLimitOrderParams(marketIndex, direction, baseAssetAmount, price, reduceOnly, discountToken = false, referrer = false, userOrderId = 0, postOnly = false, oraclePriceOffset = numericConstants_1.ZERO) {
7
+ return {
8
+ orderType: types_1.OrderType.LIMIT,
9
+ userOrderId,
10
+ marketIndex,
11
+ direction,
12
+ quoteAssetAmount: numericConstants_1.ZERO,
13
+ baseAssetAmount,
14
+ price,
15
+ reduceOnly,
16
+ postOnly,
17
+ immediateOrCancel: false,
18
+ positionLimit: numericConstants_1.ZERO,
19
+ padding0: true,
20
+ padding1: numericConstants_1.ZERO,
21
+ optionalAccounts: {
22
+ discountToken,
23
+ referrer,
24
+ },
25
+ triggerCondition: types_1.OrderTriggerCondition.ABOVE,
26
+ triggerPrice: numericConstants_1.ZERO,
27
+ oraclePriceOffset,
28
+ };
29
+ }
30
+ exports.getLimitOrderParams = getLimitOrderParams;
31
+ function getTriggerMarketOrderParams(marketIndex, direction, baseAssetAmount, triggerPrice, triggerCondition, reduceOnly, discountToken = false, referrer = false, userOrderId = 0) {
32
+ return {
33
+ orderType: types_1.OrderType.TRIGGER_MARKET,
34
+ userOrderId,
35
+ marketIndex,
36
+ direction,
37
+ quoteAssetAmount: numericConstants_1.ZERO,
38
+ baseAssetAmount,
39
+ price: numericConstants_1.ZERO,
40
+ reduceOnly,
41
+ postOnly: false,
42
+ immediateOrCancel: false,
43
+ positionLimit: numericConstants_1.ZERO,
44
+ padding0: true,
45
+ padding1: numericConstants_1.ZERO,
46
+ optionalAccounts: {
47
+ discountToken,
48
+ referrer,
49
+ },
50
+ triggerCondition,
51
+ triggerPrice,
52
+ oraclePriceOffset: numericConstants_1.ZERO,
53
+ };
54
+ }
55
+ exports.getTriggerMarketOrderParams = getTriggerMarketOrderParams;
56
+ function getTriggerLimitOrderParams(marketIndex, direction, baseAssetAmount, price, triggerPrice, triggerCondition, reduceOnly, discountToken = false, referrer = false, userOrderId = 0) {
57
+ return {
58
+ orderType: types_1.OrderType.TRIGGER_LIMIT,
59
+ userOrderId,
60
+ marketIndex,
61
+ direction,
62
+ quoteAssetAmount: numericConstants_1.ZERO,
63
+ baseAssetAmount,
64
+ price,
65
+ reduceOnly,
66
+ postOnly: false,
67
+ immediateOrCancel: false,
68
+ positionLimit: numericConstants_1.ZERO,
69
+ padding0: true,
70
+ padding1: numericConstants_1.ZERO,
71
+ optionalAccounts: {
72
+ discountToken,
73
+ referrer,
74
+ },
75
+ triggerCondition,
76
+ triggerPrice,
77
+ oraclePriceOffset: numericConstants_1.ZERO,
78
+ };
79
+ }
80
+ exports.getTriggerLimitOrderParams = getTriggerLimitOrderParams;
81
+ function getMarketOrderParams(marketIndex, direction, quoteAssetAmount, baseAssetAmount, reduceOnly, price = numericConstants_1.ZERO, discountToken = false, referrer = false) {
82
+ if (baseAssetAmount.eq(numericConstants_1.ZERO) && quoteAssetAmount.eq(numericConstants_1.ZERO)) {
83
+ throw Error('baseAssetAmount or quoteAssetAmount must be zero');
84
+ }
85
+ return {
86
+ orderType: types_1.OrderType.MARKET,
87
+ userOrderId: 0,
88
+ marketIndex,
89
+ direction,
90
+ quoteAssetAmount,
91
+ baseAssetAmount,
92
+ price,
93
+ reduceOnly,
94
+ postOnly: false,
95
+ immediateOrCancel: false,
96
+ positionLimit: numericConstants_1.ZERO,
97
+ padding0: true,
98
+ padding1: numericConstants_1.ZERO,
99
+ optionalAccounts: {
100
+ discountToken,
101
+ referrer,
102
+ },
103
+ triggerCondition: types_1.OrderTriggerCondition.ABOVE,
104
+ triggerPrice: numericConstants_1.ZERO,
105
+ oraclePriceOffset: numericConstants_1.ZERO,
106
+ };
107
+ }
108
+ exports.getMarketOrderParams = getMarketOrderParams;
109
+ //# sourceMappingURL=orderParams.js.map
@@ -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,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,uBAAI;QACd,gBAAgB,EAAE;YACjB,aAAa;YACb,QAAQ;SACR;QACD,gBAAgB,EAAE,6BAAqB,CAAC,KAAK;QAC7C,YAAY,EAAE,uBAAI;QAClB,iBAAiB,EAAE,uBAAI;KACvB,CAAC;AACH,CAAC;AApCD,oDAoCC"}
@@ -16,7 +16,8 @@ export function getLimitOrderParams(
16
16
  discountToken = false,
17
17
  referrer = false,
18
18
  userOrderId = 0,
19
- postOnly = false
19
+ postOnly = false,
20
+ oraclePriceOffset = ZERO
20
21
  ): OrderParams {
21
22
  return {
22
23
  orderType: OrderType.LIMIT,
@@ -38,7 +39,7 @@ export function getLimitOrderParams(
38
39
  },
39
40
  triggerCondition: OrderTriggerCondition.ABOVE,
40
41
  triggerPrice: ZERO,
41
- oraclePriceOffset: ZERO,
42
+ oraclePriceOffset,
42
43
  };
43
44
  }
44
45