@drift-labs/sdk 0.1.30-master.0 → 0.1.30-master.3

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 (82) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -2
  2. package/lib/accounts/bulkAccountLoader.js +21 -24
  3. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +15 -0
  4. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +50 -23
  5. package/lib/clearingHouse.d.ts +0 -1
  6. package/lib/clearingHouse.js +0 -14
  7. package/lib/constants/accounts.d.ts +15 -0
  8. package/lib/constants/accounts.js +18 -0
  9. package/lib/constants/markets.js +11 -8
  10. package/lib/factory/clearingHouse.d.ts +14 -4
  11. package/lib/factory/clearingHouse.js +23 -6
  12. package/lib/idl/clearing_house.json +2 -33
  13. package/lib/index.d.ts +0 -1
  14. package/lib/index.js +0 -1
  15. package/lib/math/amm.d.ts +20 -0
  16. package/lib/math/amm.js +151 -1
  17. package/lib/util/promiseTimeout.d.ts +1 -0
  18. package/lib/util/promiseTimeout.js +14 -0
  19. package/package.json +1 -1
  20. package/src/accounts/bulkAccountLoader.ts +22 -32
  21. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +73 -30
  22. package/src/clearingHouse.ts +0 -13
  23. package/src/constants/accounts.ts +26 -0
  24. package/src/constants/markets.ts +11 -8
  25. package/src/factory/clearingHouse.ts +47 -7
  26. package/src/idl/clearing_house.json +2 -33
  27. package/src/index.ts +0 -1
  28. package/src/math/amm.ts +212 -1
  29. package/src/util/promiseTimeout.ts +14 -0
  30. package/lib/math/repeg.d.ts +0 -32
  31. package/lib/math/repeg.js +0 -178
  32. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -210
  33. package/src/accounts/pollingClearingHouseAccountSubscriber.js.map +0 -1
  34. package/src/accounts/pollingOracleSubscriber.js +0 -65
  35. package/src/accounts/pollingOracleSubscriber.js.map +0 -1
  36. package/src/accounts/pollingTokenAccountSubscriber.js +0 -65
  37. package/src/accounts/pollingTokenAccountSubscriber.js.map +0 -1
  38. package/src/accounts/utils.js +0 -8
  39. package/src/accounts/utils.js.map +0 -1
  40. package/src/accounts/webSocketAccountSubscriber.js +0 -64
  41. package/src/accounts/webSocketAccountSubscriber.js.map +0 -1
  42. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -212
  43. package/src/accounts/webSocketClearingHouseAccountSubscriber.js.map +0 -1
  44. package/src/assert/assert.js +0 -10
  45. package/src/assert/assert.js.map +0 -1
  46. package/src/constants/markets.js +0 -167
  47. package/src/constants/markets.js.map +0 -1
  48. package/src/constants/numericConstants.js +0 -22
  49. package/src/constants/numericConstants.js.map +0 -1
  50. package/src/math/conversion.js +0 -16
  51. package/src/math/conversion.js.map +0 -1
  52. package/src/math/funding.js +0 -223
  53. package/src/math/funding.js.map +0 -1
  54. package/src/math/insuranceFund.js +0 -23
  55. package/src/math/insuranceFund.js.map +0 -1
  56. package/src/math/market.js +0 -30
  57. package/src/math/market.js.map +0 -1
  58. package/src/math/orders.js +0 -73
  59. package/src/math/orders.js.map +0 -1
  60. package/src/math/position.js +0 -121
  61. package/src/math/position.js.map +0 -1
  62. package/src/math/repeg.ts +0 -253
  63. package/src/math/trade.js +0 -182
  64. package/src/math/trade.js.map +0 -1
  65. package/src/math/utils.js +0 -27
  66. package/src/math/utils.js.map +0 -1
  67. package/src/oracles/switchboardClient.js +0 -60
  68. package/src/oracles/switchboardClient.js.map +0 -1
  69. package/src/oracles/types.js +0 -3
  70. package/src/oracles/types.js.map +0 -1
  71. package/src/token/index.js +0 -39
  72. package/src/token/index.js.map +0 -1
  73. package/src/tx/defaultTxSender.js +0 -13
  74. package/src/tx/defaultTxSender.js.map +0 -1
  75. package/src/tx/types.js +0 -3
  76. package/src/tx/types.js.map +0 -1
  77. package/src/tx/utils.js +0 -9
  78. package/src/tx/utils.js.map +0 -1
  79. package/src/util/computeUnits.js +0 -17
  80. package/src/util/computeUnits.js.map +0 -1
  81. package/src/util/tps.js +0 -17
  82. package/src/util/tps.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseTokenAccount = void 0;
4
- const spl_token_1 = require("@solana/spl-token");
5
- const web3_js_1 = require("@solana/web3.js");
6
- function parseTokenAccount(data) {
7
- const accountInfo = spl_token_1.AccountLayout.decode(data);
8
- accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
9
- accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
10
- accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
11
- if (accountInfo.delegateOption === 0) {
12
- accountInfo.delegate = null;
13
- // eslint-disable-next-line new-cap
14
- accountInfo.delegatedAmount = new spl_token_1.u64(0);
15
- }
16
- else {
17
- accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
18
- accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
19
- }
20
- accountInfo.isInitialized = accountInfo.state !== 0;
21
- accountInfo.isFrozen = accountInfo.state === 2;
22
- if (accountInfo.isNativeOption === 1) {
23
- accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
24
- accountInfo.isNative = true;
25
- }
26
- else {
27
- accountInfo.rentExemptReserve = null;
28
- accountInfo.isNative = false;
29
- }
30
- if (accountInfo.closeAuthorityOption === 0) {
31
- accountInfo.closeAuthority = null;
32
- }
33
- else {
34
- accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
35
- }
36
- return accountInfo;
37
- }
38
- exports.parseTokenAccount = parseTokenAccount;
39
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,iDAAoE;AACpE,6CAA4C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QACN,WAAW,CAAC,cAAc,GAAG,IAAI,mBAAS,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;KACvE;IAED,OAAO,WAAW,CAAC;AACpB,CAAC;AAjCD,8CAiCC"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultTxSender = void 0;
4
- class DefaultTxSender {
5
- constructor(provider) {
6
- this.provider = provider;
7
- }
8
- send(tx, additionalSigners, opts) {
9
- return this.provider.send(tx, additionalSigners, opts);
10
- }
11
- }
12
- exports.DefaultTxSender = DefaultTxSender;
13
- //# sourceMappingURL=defaultTxSender.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultTxSender.js","sourceRoot":"","sources":["defaultTxSender.ts"],"names":[],"mappings":";;;AASA,MAAa,eAAe;IAG3B,YAAmB,QAAkB;QACpC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED,IAAI,CACH,EAAe,EACf,iBAAiC,EACjC,IAAqB;QAErB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;CACD;AAdD,0CAcC"}
package/src/tx/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":""}
package/src/tx/utils.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapInTx = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- function wrapInTx(instruction) {
6
- return new web3_js_1.Transaction().add(instruction);
7
- }
8
- exports.wrapInTx = wrapInTx;
9
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,6CAAsE;AAEtE,SAAgB,QAAQ,CAAC,WAAmC;IAC3D,OAAO,IAAI,qBAAW,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;AAC3C,CAAC;AAFD,4BAEC"}
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findComputeUnitConsumption = void 0;
4
- async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
5
- const tx = await connection.getTransaction(txSignature, { commitment });
6
- const computeUnits = [];
7
- const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of 200000 compute units`);
8
- tx.meta.logMessages.forEach((logMessage) => {
9
- const match = logMessage.match(regex);
10
- if (match && match[1]) {
11
- computeUnits.push(match[1]);
12
- }
13
- });
14
- return computeUnits;
15
- }
16
- exports.findComputeUnitConsumption = findComputeUnitConsumption;
17
- //# sourceMappingURL=computeUnits.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"computeUnits.js","sourceRoot":"","sources":["computeUnits.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,0BAA0B,CAC/C,SAAoB,EACpB,UAAsB,EACtB,WAAmB,EACnB,aAAuB,WAAW;IAElC,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,WAAW,SAAS,CAAC,QAAQ,EAAE,gDAAgD,CAC/E,CAAC;IACF,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;YACtB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5B;IACF,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACrB,CAAC;AAlBD,gEAkBC"}
package/src/util/tps.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.estimateTps = void 0;
4
- async function estimateTps(programId, connection, failed) {
5
- let signatures = await connection.getSignaturesForAddress(programId, undefined, 'finalized');
6
- if (failed) {
7
- signatures = signatures.filter((signature) => signature.err);
8
- }
9
- const numberOfSignatures = signatures.length;
10
- if (numberOfSignatures === 0) {
11
- return 0;
12
- }
13
- return (numberOfSignatures /
14
- (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
15
- }
16
- exports.estimateTps = estimateTps;
17
- //# sourceMappingURL=tps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tps.js","sourceRoot":"","sources":["tps.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,WAAW,CAChC,SAAoB,EACpB,UAAsB,EACtB,MAAe;IAEf,IAAI,UAAU,GAAG,MAAM,UAAU,CAAC,uBAAuB,CACxD,SAAS,EACT,SAAS,EACT,WAAW,CACX,CAAC;IACF,IAAI,MAAM,EAAE;QACX,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC7D;IAED,MAAM,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC;IAE7C,IAAI,kBAAkB,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,CAAC;KACT;IAED,OAAO,CACN,kBAAkB;QAClB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,UAAU,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CACxE,CAAC;AACH,CAAC;AAxBD,kCAwBC"}