@acta-markets/ts-sdk 0.0.1-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/README.md +308 -0
- package/dist/actaClient.d.ts +46 -0
- package/dist/actaClient.js +99 -0
- package/dist/chain/client.d.ts +65 -0
- package/dist/chain/client.js +82 -0
- package/dist/chain/fetch.d.ts +204 -0
- package/dist/chain/fetch.js +392 -0
- package/dist/chain/fetch.test.d.ts +1 -0
- package/dist/chain/fetch.test.js +158 -0
- package/dist/chain/flows/index.d.ts +1 -0
- package/dist/chain/flows/index.js +1 -0
- package/dist/chain/flows/openPosition.d.ts +48 -0
- package/dist/chain/flows/openPosition.js +78 -0
- package/dist/chain/flows/openPosition.test.d.ts +1 -0
- package/dist/chain/flows/openPosition.test.js +43 -0
- package/dist/chain/helpers.d.ts +16 -0
- package/dist/chain/helpers.js +60 -0
- package/dist/chain/index.d.ts +9 -0
- package/dist/chain/index.js +9 -0
- package/dist/chain/instructions.admin.d.ts +44 -0
- package/dist/chain/instructions.admin.js +113 -0
- package/dist/chain/instructions.d.ts +5 -0
- package/dist/chain/instructions.js +5 -0
- package/dist/chain/instructions.maker.d.ts +34 -0
- package/dist/chain/instructions.maker.js +86 -0
- package/dist/chain/instructions.market.d.ts +39 -0
- package/dist/chain/instructions.market.js +107 -0
- package/dist/chain/instructions.oracle.d.ts +38 -0
- package/dist/chain/instructions.oracle.js +63 -0
- package/dist/chain/instructions.position.d.ts +82 -0
- package/dist/chain/instructions.position.js +240 -0
- package/dist/chain/instructions.resolve.test.d.ts +1 -0
- package/dist/chain/instructions.resolve.test.js +32 -0
- package/dist/chain/instructions.shared.d.ts +23 -0
- package/dist/chain/instructions.shared.js +55 -0
- package/dist/chain/orders.d.ts +40 -0
- package/dist/chain/orders.js +117 -0
- package/dist/chain/orders.test.d.ts +1 -0
- package/dist/chain/orders.test.js +67 -0
- package/dist/chain/signers.d.ts +9 -0
- package/dist/chain/signers.js +19 -0
- package/dist/chain/signers.test.d.ts +1 -0
- package/dist/chain/signers.test.js +13 -0
- package/dist/chain/token.d.ts +59 -0
- package/dist/chain/token.js +136 -0
- package/dist/chain/token.test.d.ts +1 -0
- package/dist/chain/token.test.js +69 -0
- package/dist/chain/tx.d.ts +72 -0
- package/dist/chain/tx.js +97 -0
- package/dist/cjs/actaClient.js +103 -0
- package/dist/cjs/chain/client.js +119 -0
- package/dist/cjs/chain/fetch.js +431 -0
- package/dist/cjs/chain/fetch.test.js +160 -0
- package/dist/cjs/chain/flows/index.js +17 -0
- package/dist/cjs/chain/flows/openPosition.js +81 -0
- package/dist/cjs/chain/flows/openPosition.test.js +45 -0
- package/dist/cjs/chain/helpers.js +67 -0
- package/dist/cjs/chain/index.js +48 -0
- package/dist/cjs/chain/instructions.admin.js +119 -0
- package/dist/cjs/chain/instructions.js +21 -0
- package/dist/cjs/chain/instructions.maker.js +92 -0
- package/dist/cjs/chain/instructions.market.js +112 -0
- package/dist/cjs/chain/instructions.oracle.js +70 -0
- package/dist/cjs/chain/instructions.position.js +247 -0
- package/dist/cjs/chain/instructions.resolve.test.js +34 -0
- package/dist/cjs/chain/instructions.shared.js +64 -0
- package/dist/cjs/chain/orders.js +126 -0
- package/dist/cjs/chain/orders.test.js +69 -0
- package/dist/cjs/chain/signers.js +22 -0
- package/dist/cjs/chain/signers.test.js +15 -0
- package/dist/cjs/chain/token.js +147 -0
- package/dist/cjs/chain/token.test.js +71 -0
- package/dist/cjs/chain/tx.js +103 -0
- package/dist/cjs/constants.js +6 -0
- package/dist/cjs/constants.test.js +31 -0
- package/dist/cjs/events.js +75 -0
- package/dist/cjs/events.test.js +384 -0
- package/dist/cjs/generated/accounts/config.js +79 -0
- package/dist/cjs/generated/accounts/index.js +28 -0
- package/dist/cjs/generated/accounts/maker.js +71 -0
- package/dist/cjs/generated/accounts/market.js +93 -0
- package/dist/cjs/generated/accounts/oracle.js +85 -0
- package/dist/cjs/generated/accounts/position.js +89 -0
- package/dist/cjs/generated/errors/actaContract.js +154 -0
- package/dist/cjs/generated/errors/index.js +24 -0
- package/dist/cjs/generated/index.js +28 -0
- package/dist/cjs/generated/instructions/changeOracleSource.js +81 -0
- package/dist/cjs/generated/instructions/closeMarket.js +83 -0
- package/dist/cjs/generated/instructions/closeOracle.js +79 -0
- package/dist/cjs/generated/instructions/createMarket.js +116 -0
- package/dist/cjs/generated/instructions/createOracle.js +99 -0
- package/dist/cjs/generated/instructions/depositFundsToPosition.js +101 -0
- package/dist/cjs/generated/instructions/depositPremium.js +96 -0
- package/dist/cjs/generated/instructions/finalizeMarket.js +91 -0
- package/dist/cjs/generated/instructions/index.js +43 -0
- package/dist/cjs/generated/instructions/initializeConfig.js +108 -0
- package/dist/cjs/generated/instructions/liquidatePosition.js +107 -0
- package/dist/cjs/generated/instructions/openPosition.js +154 -0
- package/dist/cjs/generated/instructions/registerMaker.js +90 -0
- package/dist/cjs/generated/instructions/setOracleConfig.js +80 -0
- package/dist/cjs/generated/instructions/settlePosition.js +104 -0
- package/dist/cjs/generated/instructions/topupFeeFund.js +96 -0
- package/dist/cjs/generated/instructions/updateConfig.js +86 -0
- package/dist/cjs/generated/instructions/updateMakerQuoteSigning.js +79 -0
- package/dist/cjs/generated/instructions/updateMarketOracles.js +96 -0
- package/dist/cjs/generated/instructions/updateOraclePrice.js +89 -0
- package/dist/cjs/generated/instructions/withdrawFromFeeFund.js +96 -0
- package/dist/cjs/generated/instructions/withdrawPremium.js +96 -0
- package/dist/cjs/generated/programs/actaContract.js +108 -0
- package/dist/cjs/generated/programs/index.js +24 -0
- package/dist/cjs/generated/shared/index.js +94 -0
- package/dist/cjs/generated/types/actaEvent.js +342 -0
- package/dist/cjs/generated/types/eventKind.js +45 -0
- package/dist/cjs/generated/types/index.js +27 -0
- package/dist/cjs/generated/types/positionStatus.js +31 -0
- package/dist/cjs/generated/types/positionType.js +28 -0
- package/dist/cjs/idl/acta_contract.json +2329 -0
- package/dist/cjs/idl/hash.js +4 -0
- package/dist/cjs/index.js +84 -0
- package/dist/cjs/nonce.js +93 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/types/index.js +18 -0
- package/dist/cjs/types/orderId.js +40 -0
- package/dist/cjs/types/orders.js +10 -0
- package/dist/cjs/ws/apy.js +106 -0
- package/dist/cjs/ws/apy.test.js +29 -0
- package/dist/cjs/ws/auth.js +104 -0
- package/dist/cjs/ws/client.handshake.integration.test.js +69 -0
- package/dist/cjs/ws/client.js +861 -0
- package/dist/cjs/ws/client.test.js +230 -0
- package/dist/cjs/ws/discovery.js +48 -0
- package/dist/cjs/ws/flows.js +101 -0
- package/dist/cjs/ws/flows.test.js +85 -0
- package/dist/cjs/ws/index.js +23 -0
- package/dist/cjs/ws/sponsoredTx.js +95 -0
- package/dist/cjs/ws/types.js +14 -0
- package/dist/cjs/ws/wirePolicy.js +34 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +3 -0
- package/dist/constants.test.d.ts +1 -0
- package/dist/constants.test.js +29 -0
- package/dist/events.d.ts +15 -0
- package/dist/events.js +64 -0
- package/dist/events.test.d.ts +1 -0
- package/dist/events.test.js +382 -0
- package/dist/generated/accounts/config.d.ts +47 -0
- package/dist/generated/accounts/config.js +68 -0
- package/dist/generated/accounts/index.d.ts +12 -0
- package/dist/generated/accounts/index.js +12 -0
- package/dist/generated/accounts/maker.d.ts +39 -0
- package/dist/generated/accounts/maker.js +60 -0
- package/dist/generated/accounts/market.d.ts +61 -0
- package/dist/generated/accounts/market.js +82 -0
- package/dist/generated/accounts/oracle.d.ts +53 -0
- package/dist/generated/accounts/oracle.js +74 -0
- package/dist/generated/accounts/position.d.ts +57 -0
- package/dist/generated/accounts/position.js +78 -0
- package/dist/generated/errors/actaContract.d.ts +103 -0
- package/dist/generated/errors/actaContract.js +149 -0
- package/dist/generated/errors/index.d.ts +8 -0
- package/dist/generated/errors/index.js +8 -0
- package/dist/generated/index.d.ts +12 -0
- package/dist/generated/index.js +12 -0
- package/dist/generated/instructions/changeOracleSource.d.ts +50 -0
- package/dist/generated/instructions/changeOracleSource.js +72 -0
- package/dist/generated/instructions/closeMarket.d.ts +58 -0
- package/dist/generated/instructions/closeMarket.js +74 -0
- package/dist/generated/instructions/closeOracle.d.ts +48 -0
- package/dist/generated/instructions/closeOracle.js +70 -0
- package/dist/generated/instructions/createMarket.d.ts +90 -0
- package/dist/generated/instructions/createMarket.js +107 -0
- package/dist/generated/instructions/createOracle.d.ts +71 -0
- package/dist/generated/instructions/createOracle.js +90 -0
- package/dist/generated/instructions/depositFundsToPosition.d.ts +73 -0
- package/dist/generated/instructions/depositFundsToPosition.js +92 -0
- package/dist/generated/instructions/depositPremium.d.ts +62 -0
- package/dist/generated/instructions/depositPremium.js +87 -0
- package/dist/generated/instructions/finalizeMarket.d.ts +63 -0
- package/dist/generated/instructions/finalizeMarket.js +82 -0
- package/dist/generated/instructions/index.d.ts +27 -0
- package/dist/generated/instructions/index.js +27 -0
- package/dist/generated/instructions/initializeConfig.d.ts +75 -0
- package/dist/generated/instructions/initializeConfig.js +99 -0
- package/dist/generated/instructions/liquidatePosition.d.ts +78 -0
- package/dist/generated/instructions/liquidatePosition.js +98 -0
- package/dist/generated/instructions/openPosition.d.ts +130 -0
- package/dist/generated/instructions/openPosition.js +145 -0
- package/dist/generated/instructions/registerMaker.d.ts +57 -0
- package/dist/generated/instructions/registerMaker.js +81 -0
- package/dist/generated/instructions/setOracleConfig.d.ts +53 -0
- package/dist/generated/instructions/setOracleConfig.js +71 -0
- package/dist/generated/instructions/settlePosition.d.ts +78 -0
- package/dist/generated/instructions/settlePosition.js +95 -0
- package/dist/generated/instructions/topupFeeFund.d.ts +67 -0
- package/dist/generated/instructions/topupFeeFund.js +87 -0
- package/dist/generated/instructions/updateConfig.d.ts +58 -0
- package/dist/generated/instructions/updateConfig.js +77 -0
- package/dist/generated/instructions/updateMakerQuoteSigning.d.ts +47 -0
- package/dist/generated/instructions/updateMakerQuoteSigning.js +70 -0
- package/dist/generated/instructions/updateMarketOracles.d.ts +65 -0
- package/dist/generated/instructions/updateMarketOracles.js +87 -0
- package/dist/generated/instructions/updateOraclePrice.d.ts +55 -0
- package/dist/generated/instructions/updateOraclePrice.js +80 -0
- package/dist/generated/instructions/withdrawFromFeeFund.d.ts +62 -0
- package/dist/generated/instructions/withdrawFromFeeFund.js +87 -0
- package/dist/generated/instructions/withdrawPremium.d.ts +62 -0
- package/dist/generated/instructions/withdrawPremium.js +87 -0
- package/dist/generated/programs/actaContract.d.ts +83 -0
- package/dist/generated/programs/actaContract.js +104 -0
- package/dist/generated/programs/index.d.ts +8 -0
- package/dist/generated/programs/index.js +8 -0
- package/dist/generated/shared/index.d.ts +49 -0
- package/dist/generated/shared/index.js +86 -0
- package/dist/generated/types/actaEvent.d.ts +249 -0
- package/dist/generated/types/actaEvent.js +335 -0
- package/dist/generated/types/eventKind.d.ts +33 -0
- package/dist/generated/types/eventKind.js +39 -0
- package/dist/generated/types/index.d.ts +11 -0
- package/dist/generated/types/index.js +11 -0
- package/dist/generated/types/positionStatus.d.ts +19 -0
- package/dist/generated/types/positionStatus.js +25 -0
- package/dist/generated/types/positionType.d.ts +16 -0
- package/dist/generated/types/positionType.js +22 -0
- package/dist/idl/acta_contract.json +2329 -0
- package/dist/idl/hash.d.ts +1 -0
- package/dist/idl/hash.js +1 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +34 -0
- package/dist/nonce.d.ts +29 -0
- package/dist/nonce.js +89 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/orderId.d.ts +13 -0
- package/dist/types/orderId.js +35 -0
- package/dist/types/orders.d.ts +9 -0
- package/dist/types/orders.js +9 -0
- package/dist/ws/apy.d.ts +79 -0
- package/dist/ws/apy.js +98 -0
- package/dist/ws/apy.test.d.ts +1 -0
- package/dist/ws/apy.test.js +27 -0
- package/dist/ws/auth.d.ts +67 -0
- package/dist/ws/auth.js +98 -0
- package/dist/ws/client.d.ts +263 -0
- package/dist/ws/client.handshake.integration.test.d.ts +1 -0
- package/dist/ws/client.handshake.integration.test.js +64 -0
- package/dist/ws/client.js +857 -0
- package/dist/ws/client.test.d.ts +1 -0
- package/dist/ws/client.test.js +228 -0
- package/dist/ws/discovery.d.ts +13 -0
- package/dist/ws/discovery.js +44 -0
- package/dist/ws/flows.d.ts +44 -0
- package/dist/ws/flows.js +96 -0
- package/dist/ws/flows.test.d.ts +1 -0
- package/dist/ws/flows.test.js +83 -0
- package/dist/ws/index.d.ts +7 -0
- package/dist/ws/index.js +7 -0
- package/dist/ws/sponsoredTx.d.ts +39 -0
- package/dist/ws/sponsoredTx.js +92 -0
- package/dist/ws/types.d.ts +900 -0
- package/dist/ws/types.js +13 -0
- package/dist/ws/wirePolicy.d.ts +12 -0
- package/dist/ws/wirePolicy.js +30 -0
- package/package.json +87 -0
|
@@ -0,0 +1,431 @@
|
|
|
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.ORACLE_ACCOUNT_SIZE_BYTES = exports.MARKET_ACCOUNT_SIZE_BYTES = exports.CONFIG_ACCOUNT_SIZE_BYTES = exports.MAKER_ACCOUNT_SIZE_BYTES = exports.POSITION_ACCOUNT_SIZE_BYTES = exports.ORACLE_ACCOUNT_DISCRIMINATOR = exports.MARKET_ACCOUNT_DISCRIMINATOR = exports.CONFIG_ACCOUNT_DISCRIMINATOR = exports.MAKER_ACCOUNT_DISCRIMINATOR = exports.POSITION_ACCOUNT_DISCRIMINATOR = exports.MAKER_OFFSET_QUOTE_SIGNING = exports.MAKER_OFFSET_MAKER_OWNER = exports.ORACLE_OFFSET_FEED_ID = exports.ORACLE_OFFSET_AUTHORITY = exports.ORACLE_OFFSET_MINT = exports.ORACLE_OFFSET_EXPIRY_TS = exports.ORACLE_OFFSET_UPDATED_AT = exports.ORACLE_OFFSET_PRICE = exports.ORACLE_OFFSET_ACTIVE_MARKETS_COUNT = exports.ORACLE_OFFSET_DECIMALS = exports.ORACLE_OFFSET_FLAGS = exports.ORACLE_OFFSET_ORACLE_TYPE = exports.MARKET_OFFSET_QUOTE_ORACLE_ADDRESS = exports.MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS = exports.MARKET_OFFSET_QUOTE_MINT = exports.MARKET_OFFSET_UNDERLYING_MINT = exports.MARKET_OFFSET_SETTLEMENT_PRICE = exports.MARKET_OFFSET_EXPIRY_TS = exports.MARKET_OFFSET_FLAGS = exports.MARKET_OFFSET_QUOTE_DECIMALS = exports.MARKET_OFFSET_UNDERLYING_DECIMALS = exports.POSITION_OFFSET_MARKET = exports.POSITION_OFFSET_MAKER_OWNER = exports.POSITION_OFFSET_TAKER_OWNER = exports.POSITION_OFFSET_STATUS = void 0;
|
|
7
|
+
exports.fetchPositionsByMaker = fetchPositionsByMaker;
|
|
8
|
+
exports.fetchPositionsByMakerDecoded = fetchPositionsByMakerDecoded;
|
|
9
|
+
exports.fetchPositionsByTaker = fetchPositionsByTaker;
|
|
10
|
+
exports.fetchPositionsByTakerDecoded = fetchPositionsByTakerDecoded;
|
|
11
|
+
exports.fetchPositionsByMarket = fetchPositionsByMarket;
|
|
12
|
+
exports.fetchPositionsByMarketDecoded = fetchPositionsByMarketDecoded;
|
|
13
|
+
exports.fetchPositionsByStatus = fetchPositionsByStatus;
|
|
14
|
+
exports.fetchPositionsByMakerAndStatus = fetchPositionsByMakerAndStatus;
|
|
15
|
+
exports.fetchPositionsByMarketAndStatus = fetchPositionsByMarketAndStatus;
|
|
16
|
+
exports.fetchPositionsByStatusDecoded = fetchPositionsByStatusDecoded;
|
|
17
|
+
exports.fetchAllConfigsDecoded = fetchAllConfigsDecoded;
|
|
18
|
+
exports.fetchAllMakersDecoded = fetchAllMakersDecoded;
|
|
19
|
+
exports.fetchAllMarketsDecoded = fetchAllMarketsDecoded;
|
|
20
|
+
exports.fetchAllOraclesDecoded = fetchAllOraclesDecoded;
|
|
21
|
+
exports.fetchAllPositionsDecoded = fetchAllPositionsDecoded;
|
|
22
|
+
exports.fetchMarketsByUnderlying = fetchMarketsByUnderlying;
|
|
23
|
+
exports.fetchMarketsByUnderlyingDecoded = fetchMarketsByUnderlyingDecoded;
|
|
24
|
+
exports.fetchMarketsByQuote = fetchMarketsByQuote;
|
|
25
|
+
exports.fetchMarketsByQuoteDecoded = fetchMarketsByQuoteDecoded;
|
|
26
|
+
exports.fetchMarketsByExpiry = fetchMarketsByExpiry;
|
|
27
|
+
exports.fetchMarketsByExpiryDecoded = fetchMarketsByExpiryDecoded;
|
|
28
|
+
exports.fetchMarketsByQuoteAndExpiry = fetchMarketsByQuoteAndExpiry;
|
|
29
|
+
exports.fetchMarketsByQuoteAndExpiryDecoded = fetchMarketsByQuoteAndExpiryDecoded;
|
|
30
|
+
exports.fetchMarketsByUnderlyingAndExpiry = fetchMarketsByUnderlyingAndExpiry;
|
|
31
|
+
exports.fetchConfigAccountByAddress = fetchConfigAccountByAddress;
|
|
32
|
+
exports.fetchMarketAccountByAddress = fetchMarketAccountByAddress;
|
|
33
|
+
exports.fetchOracleAccountByAddress = fetchOracleAccountByAddress;
|
|
34
|
+
exports.fetchMarketsByUnderlyingAndExpiryDecoded = fetchMarketsByUnderlyingAndExpiryDecoded;
|
|
35
|
+
exports.decodePositionAccount = decodePositionAccount;
|
|
36
|
+
exports.decodeMarketAccount = decodeMarketAccount;
|
|
37
|
+
exports.decodeConfigAccount = decodeConfigAccount;
|
|
38
|
+
exports.decodeMakerAccount = decodeMakerAccount;
|
|
39
|
+
exports.decodeOracleAccount = decodeOracleAccount;
|
|
40
|
+
const addresses_1 = require("@solana/addresses");
|
|
41
|
+
const config_1 = require("../generated/accounts/config");
|
|
42
|
+
const market_1 = require("../generated/accounts/market");
|
|
43
|
+
const oracle_1 = require("../generated/accounts/oracle");
|
|
44
|
+
const position_1 = require("../generated/accounts/position");
|
|
45
|
+
const maker_1 = require("../generated/accounts/maker");
|
|
46
|
+
const index_1 = require("../index");
|
|
47
|
+
const buffer_1 = require("buffer");
|
|
48
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
49
|
+
// Offsets match Rust account layouts (discriminator is the first field).
|
|
50
|
+
exports.POSITION_OFFSET_STATUS = 4;
|
|
51
|
+
exports.POSITION_OFFSET_TAKER_OWNER = 8;
|
|
52
|
+
exports.POSITION_OFFSET_MAKER_OWNER = 40;
|
|
53
|
+
exports.POSITION_OFFSET_MARKET = 72;
|
|
54
|
+
exports.MARKET_OFFSET_UNDERLYING_DECIMALS = 3;
|
|
55
|
+
exports.MARKET_OFFSET_QUOTE_DECIMALS = 4;
|
|
56
|
+
exports.MARKET_OFFSET_FLAGS = 5;
|
|
57
|
+
exports.MARKET_OFFSET_EXPIRY_TS = 8;
|
|
58
|
+
exports.MARKET_OFFSET_SETTLEMENT_PRICE = 16;
|
|
59
|
+
exports.MARKET_OFFSET_UNDERLYING_MINT = 32;
|
|
60
|
+
exports.MARKET_OFFSET_QUOTE_MINT = 64;
|
|
61
|
+
exports.MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS = 160;
|
|
62
|
+
exports.MARKET_OFFSET_QUOTE_ORACLE_ADDRESS = 192;
|
|
63
|
+
exports.ORACLE_OFFSET_ORACLE_TYPE = 3;
|
|
64
|
+
exports.ORACLE_OFFSET_FLAGS = 4;
|
|
65
|
+
exports.ORACLE_OFFSET_DECIMALS = 5;
|
|
66
|
+
exports.ORACLE_OFFSET_ACTIVE_MARKETS_COUNT = 6;
|
|
67
|
+
exports.ORACLE_OFFSET_PRICE = 8;
|
|
68
|
+
exports.ORACLE_OFFSET_UPDATED_AT = 16;
|
|
69
|
+
exports.ORACLE_OFFSET_EXPIRY_TS = 24;
|
|
70
|
+
exports.ORACLE_OFFSET_MINT = 32;
|
|
71
|
+
exports.ORACLE_OFFSET_AUTHORITY = 64;
|
|
72
|
+
exports.ORACLE_OFFSET_FEED_ID = 96;
|
|
73
|
+
// Maker (account) offsets
|
|
74
|
+
exports.MAKER_OFFSET_MAKER_OWNER = 4;
|
|
75
|
+
exports.MAKER_OFFSET_QUOTE_SIGNING = 36;
|
|
76
|
+
// Account discriminators (first byte of account data).
|
|
77
|
+
exports.POSITION_ACCOUNT_DISCRIMINATOR = 1;
|
|
78
|
+
exports.MAKER_ACCOUNT_DISCRIMINATOR = 2;
|
|
79
|
+
exports.CONFIG_ACCOUNT_DISCRIMINATOR = 3;
|
|
80
|
+
exports.MARKET_ACCOUNT_DISCRIMINATOR = 4;
|
|
81
|
+
exports.ORACLE_ACCOUNT_DISCRIMINATOR = 5;
|
|
82
|
+
// Account sizes (bytes). Note: Maker includes 4 bytes of padding on-chain.
|
|
83
|
+
exports.POSITION_ACCOUNT_SIZE_BYTES = 416;
|
|
84
|
+
exports.MAKER_ACCOUNT_SIZE_BYTES = 328;
|
|
85
|
+
exports.CONFIG_ACCOUNT_SIZE_BYTES = 392;
|
|
86
|
+
exports.MARKET_ACCOUNT_SIZE_BYTES = 416;
|
|
87
|
+
exports.ORACLE_ACCOUNT_SIZE_BYTES = 384;
|
|
88
|
+
const addressEncoder = (0, addresses_1.getAddressEncoder)();
|
|
89
|
+
function memcmp(offset, addressOrBytes) {
|
|
90
|
+
const bytes = addressOrBytes instanceof Uint8Array
|
|
91
|
+
? bs58_1.default.encode(addressOrBytes)
|
|
92
|
+
: addressOrBytes;
|
|
93
|
+
return {
|
|
94
|
+
memcmp: {
|
|
95
|
+
offset: BigInt(offset),
|
|
96
|
+
bytes,
|
|
97
|
+
encoding: "base58",
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function u64Le(value) {
|
|
102
|
+
const buf = buffer_1.Buffer.alloc(8);
|
|
103
|
+
buf.writeBigUInt64LE(BigInt(value));
|
|
104
|
+
return buf;
|
|
105
|
+
}
|
|
106
|
+
function addrBytes(address) {
|
|
107
|
+
return buffer_1.Buffer.from(addressEncoder.encode(address));
|
|
108
|
+
}
|
|
109
|
+
async function fetchAndDecode(rpc, config, decode) {
|
|
110
|
+
// IMPORTANT: Solana JSON-RPC rejects base58 encoding for account data > 128 bytes.
|
|
111
|
+
// Always request base64 here, because we decode bytes locally.
|
|
112
|
+
const configWithEncoding = {
|
|
113
|
+
...config,
|
|
114
|
+
encoding: "base64",
|
|
115
|
+
};
|
|
116
|
+
const accounts = (await rpc
|
|
117
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), configWithEncoding)
|
|
118
|
+
.send());
|
|
119
|
+
return accounts.map((acc) => {
|
|
120
|
+
const [b64] = acc.account.data;
|
|
121
|
+
const buf = buffer_1.Buffer.from(b64, "base64");
|
|
122
|
+
return { pubkey: acc.pubkey, account: decode(buf) };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function dataSize(bytes) {
|
|
126
|
+
return { dataSize: BigInt(bytes) };
|
|
127
|
+
}
|
|
128
|
+
// --- Positions ---
|
|
129
|
+
async function fetchPositionsByMaker(rpc, makerOwner, options) {
|
|
130
|
+
return rpc
|
|
131
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
132
|
+
commitment: options?.commitment,
|
|
133
|
+
dataSlice: options?.dataSlice,
|
|
134
|
+
filters: [
|
|
135
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
136
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
137
|
+
memcmp(exports.POSITION_OFFSET_MAKER_OWNER, addrBytes(makerOwner)),
|
|
138
|
+
],
|
|
139
|
+
})
|
|
140
|
+
.send();
|
|
141
|
+
}
|
|
142
|
+
async function fetchPositionsByMakerDecoded(rpc, makerOwner, options) {
|
|
143
|
+
return fetchAndDecode(rpc, {
|
|
144
|
+
commitment: options?.commitment,
|
|
145
|
+
dataSlice: options?.dataSlice,
|
|
146
|
+
filters: [
|
|
147
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
148
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
149
|
+
memcmp(exports.POSITION_OFFSET_MAKER_OWNER, addrBytes(makerOwner)),
|
|
150
|
+
],
|
|
151
|
+
}, decodePositionAccount);
|
|
152
|
+
}
|
|
153
|
+
async function fetchPositionsByTaker(rpc, takerOwner, options) {
|
|
154
|
+
return rpc
|
|
155
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
156
|
+
commitment: options?.commitment,
|
|
157
|
+
dataSlice: options?.dataSlice,
|
|
158
|
+
filters: [
|
|
159
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
160
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
161
|
+
memcmp(exports.POSITION_OFFSET_TAKER_OWNER, addrBytes(takerOwner)),
|
|
162
|
+
],
|
|
163
|
+
})
|
|
164
|
+
.send();
|
|
165
|
+
}
|
|
166
|
+
async function fetchPositionsByTakerDecoded(rpc, takerOwner, options) {
|
|
167
|
+
return fetchAndDecode(rpc, {
|
|
168
|
+
commitment: options?.commitment,
|
|
169
|
+
dataSlice: options?.dataSlice,
|
|
170
|
+
filters: [
|
|
171
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
172
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
173
|
+
memcmp(exports.POSITION_OFFSET_TAKER_OWNER, addrBytes(takerOwner)),
|
|
174
|
+
],
|
|
175
|
+
}, decodePositionAccount);
|
|
176
|
+
}
|
|
177
|
+
async function fetchPositionsByMarket(rpc, market, options) {
|
|
178
|
+
return rpc
|
|
179
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
180
|
+
commitment: options?.commitment,
|
|
181
|
+
dataSlice: options?.dataSlice,
|
|
182
|
+
filters: [
|
|
183
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
184
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
185
|
+
memcmp(exports.POSITION_OFFSET_MARKET, addrBytes(market)),
|
|
186
|
+
],
|
|
187
|
+
})
|
|
188
|
+
.send();
|
|
189
|
+
}
|
|
190
|
+
async function fetchPositionsByMarketDecoded(rpc, market, options) {
|
|
191
|
+
return fetchAndDecode(rpc, {
|
|
192
|
+
commitment: options?.commitment,
|
|
193
|
+
dataSlice: options?.dataSlice,
|
|
194
|
+
filters: [
|
|
195
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
196
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
197
|
+
memcmp(exports.POSITION_OFFSET_MARKET, addrBytes(market)),
|
|
198
|
+
],
|
|
199
|
+
}, decodePositionAccount);
|
|
200
|
+
}
|
|
201
|
+
async function fetchPositionsByStatus(rpc, status, options) {
|
|
202
|
+
return rpc
|
|
203
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
204
|
+
commitment: options?.commitment,
|
|
205
|
+
dataSlice: options?.dataSlice,
|
|
206
|
+
filters: [
|
|
207
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
208
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
209
|
+
memcmp(exports.POSITION_OFFSET_STATUS, new Uint8Array([status])),
|
|
210
|
+
],
|
|
211
|
+
})
|
|
212
|
+
.send();
|
|
213
|
+
}
|
|
214
|
+
async function fetchPositionsByMakerAndStatus(rpc, makerOwner, status, options) {
|
|
215
|
+
return rpc
|
|
216
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
217
|
+
commitment: options?.commitment,
|
|
218
|
+
dataSlice: options?.dataSlice,
|
|
219
|
+
filters: [
|
|
220
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
221
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
222
|
+
memcmp(exports.POSITION_OFFSET_MAKER_OWNER, addrBytes(makerOwner)),
|
|
223
|
+
memcmp(exports.POSITION_OFFSET_STATUS, new Uint8Array([status])),
|
|
224
|
+
],
|
|
225
|
+
})
|
|
226
|
+
.send();
|
|
227
|
+
}
|
|
228
|
+
async function fetchPositionsByMarketAndStatus(rpc, market, status, options) {
|
|
229
|
+
return rpc
|
|
230
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
231
|
+
commitment: options?.commitment,
|
|
232
|
+
dataSlice: options?.dataSlice,
|
|
233
|
+
filters: [
|
|
234
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
235
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
236
|
+
memcmp(exports.POSITION_OFFSET_MARKET, addrBytes(market)),
|
|
237
|
+
memcmp(exports.POSITION_OFFSET_STATUS, new Uint8Array([status])),
|
|
238
|
+
],
|
|
239
|
+
})
|
|
240
|
+
.send();
|
|
241
|
+
}
|
|
242
|
+
async function fetchPositionsByStatusDecoded(rpc, status, options) {
|
|
243
|
+
return fetchAndDecode(rpc, {
|
|
244
|
+
commitment: options?.commitment,
|
|
245
|
+
dataSlice: options?.dataSlice,
|
|
246
|
+
filters: [
|
|
247
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
248
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
249
|
+
memcmp(exports.POSITION_OFFSET_STATUS, new Uint8Array([status])),
|
|
250
|
+
],
|
|
251
|
+
}, decodePositionAccount);
|
|
252
|
+
}
|
|
253
|
+
// --- Fetch-all (GPA) helpers ---
|
|
254
|
+
async function fetchAllConfigsDecoded(rpc, options) {
|
|
255
|
+
return fetchAndDecode(rpc, {
|
|
256
|
+
commitment: options?.commitment,
|
|
257
|
+
dataSlice: options?.dataSlice,
|
|
258
|
+
filters: [
|
|
259
|
+
dataSize(exports.CONFIG_ACCOUNT_SIZE_BYTES),
|
|
260
|
+
memcmp(0, new Uint8Array([exports.CONFIG_ACCOUNT_DISCRIMINATOR])),
|
|
261
|
+
],
|
|
262
|
+
}, decodeConfigAccount);
|
|
263
|
+
}
|
|
264
|
+
async function fetchAllMakersDecoded(rpc, options) {
|
|
265
|
+
return fetchAndDecode(rpc, {
|
|
266
|
+
commitment: options?.commitment,
|
|
267
|
+
dataSlice: options?.dataSlice,
|
|
268
|
+
filters: [
|
|
269
|
+
dataSize(exports.MAKER_ACCOUNT_SIZE_BYTES),
|
|
270
|
+
memcmp(0, new Uint8Array([exports.MAKER_ACCOUNT_DISCRIMINATOR])),
|
|
271
|
+
],
|
|
272
|
+
}, decodeMakerAccount);
|
|
273
|
+
}
|
|
274
|
+
async function fetchAllMarketsDecoded(rpc, options) {
|
|
275
|
+
return fetchAndDecode(rpc, {
|
|
276
|
+
commitment: options?.commitment,
|
|
277
|
+
dataSlice: options?.dataSlice,
|
|
278
|
+
filters: [
|
|
279
|
+
dataSize(exports.MARKET_ACCOUNT_SIZE_BYTES),
|
|
280
|
+
memcmp(0, new Uint8Array([exports.MARKET_ACCOUNT_DISCRIMINATOR])),
|
|
281
|
+
],
|
|
282
|
+
}, decodeMarketAccount);
|
|
283
|
+
}
|
|
284
|
+
async function fetchAllOraclesDecoded(rpc, options) {
|
|
285
|
+
return fetchAndDecode(rpc, {
|
|
286
|
+
commitment: options?.commitment,
|
|
287
|
+
dataSlice: options?.dataSlice,
|
|
288
|
+
filters: [
|
|
289
|
+
dataSize(exports.ORACLE_ACCOUNT_SIZE_BYTES),
|
|
290
|
+
memcmp(0, new Uint8Array([exports.ORACLE_ACCOUNT_DISCRIMINATOR])),
|
|
291
|
+
],
|
|
292
|
+
}, decodeOracleAccount);
|
|
293
|
+
}
|
|
294
|
+
async function fetchAllPositionsDecoded(rpc, options) {
|
|
295
|
+
return fetchAndDecode(rpc, {
|
|
296
|
+
commitment: options?.commitment,
|
|
297
|
+
dataSlice: options?.dataSlice,
|
|
298
|
+
filters: [
|
|
299
|
+
dataSize(exports.POSITION_ACCOUNT_SIZE_BYTES),
|
|
300
|
+
memcmp(0, new Uint8Array([exports.POSITION_ACCOUNT_DISCRIMINATOR])),
|
|
301
|
+
],
|
|
302
|
+
}, decodePositionAccount);
|
|
303
|
+
}
|
|
304
|
+
// --- Markets ---
|
|
305
|
+
async function fetchMarketsByUnderlying(rpc, underlying, options) {
|
|
306
|
+
return rpc
|
|
307
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
308
|
+
commitment: options?.commitment,
|
|
309
|
+
dataSlice: options?.dataSlice,
|
|
310
|
+
filters: [memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))],
|
|
311
|
+
})
|
|
312
|
+
.send();
|
|
313
|
+
}
|
|
314
|
+
async function fetchMarketsByUnderlyingDecoded(rpc, underlying, options) {
|
|
315
|
+
return fetchAndDecode(rpc, {
|
|
316
|
+
commitment: options?.commitment,
|
|
317
|
+
dataSlice: options?.dataSlice,
|
|
318
|
+
filters: [memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying))],
|
|
319
|
+
}, decodeMarketAccount);
|
|
320
|
+
}
|
|
321
|
+
async function fetchMarketsByQuote(rpc, quote, options) {
|
|
322
|
+
return rpc
|
|
323
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
324
|
+
commitment: options?.commitment,
|
|
325
|
+
dataSlice: options?.dataSlice,
|
|
326
|
+
filters: [memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))],
|
|
327
|
+
})
|
|
328
|
+
.send();
|
|
329
|
+
}
|
|
330
|
+
async function fetchMarketsByQuoteDecoded(rpc, quote, options) {
|
|
331
|
+
return fetchAndDecode(rpc, {
|
|
332
|
+
commitment: options?.commitment,
|
|
333
|
+
dataSlice: options?.dataSlice,
|
|
334
|
+
filters: [memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote))],
|
|
335
|
+
}, decodeMarketAccount);
|
|
336
|
+
}
|
|
337
|
+
async function fetchMarketsByExpiry(rpc, expiryTs, options) {
|
|
338
|
+
return rpc
|
|
339
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
340
|
+
commitment: options?.commitment,
|
|
341
|
+
dataSlice: options?.dataSlice,
|
|
342
|
+
filters: [memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))],
|
|
343
|
+
})
|
|
344
|
+
.send();
|
|
345
|
+
}
|
|
346
|
+
async function fetchMarketsByExpiryDecoded(rpc, expiryTs, options) {
|
|
347
|
+
return fetchAndDecode(rpc, {
|
|
348
|
+
commitment: options?.commitment,
|
|
349
|
+
dataSlice: options?.dataSlice,
|
|
350
|
+
filters: [memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs))],
|
|
351
|
+
}, decodeMarketAccount);
|
|
352
|
+
}
|
|
353
|
+
async function fetchMarketsByQuoteAndExpiry(rpc, quote, expiryTs, options) {
|
|
354
|
+
return rpc
|
|
355
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
356
|
+
commitment: options?.commitment,
|
|
357
|
+
dataSlice: options?.dataSlice,
|
|
358
|
+
filters: [
|
|
359
|
+
memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
360
|
+
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
361
|
+
],
|
|
362
|
+
})
|
|
363
|
+
.send();
|
|
364
|
+
}
|
|
365
|
+
async function fetchMarketsByQuoteAndExpiryDecoded(rpc, quote, expiryTs, options) {
|
|
366
|
+
return fetchAndDecode(rpc, {
|
|
367
|
+
commitment: options?.commitment,
|
|
368
|
+
dataSlice: options?.dataSlice,
|
|
369
|
+
filters: [
|
|
370
|
+
memcmp(exports.MARKET_OFFSET_QUOTE_MINT, addrBytes(quote)),
|
|
371
|
+
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
372
|
+
],
|
|
373
|
+
}, decodeMarketAccount);
|
|
374
|
+
}
|
|
375
|
+
async function fetchMarketsByUnderlyingAndExpiry(rpc, underlying, expiryTs, options) {
|
|
376
|
+
return rpc
|
|
377
|
+
.getProgramAccounts((0, index_1.getActaProgramId)(), {
|
|
378
|
+
commitment: options?.commitment,
|
|
379
|
+
dataSlice: options?.dataSlice,
|
|
380
|
+
filters: [
|
|
381
|
+
memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
382
|
+
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
383
|
+
],
|
|
384
|
+
})
|
|
385
|
+
.send();
|
|
386
|
+
}
|
|
387
|
+
// --- Single account fetch helpers ---
|
|
388
|
+
async function fetchConfigAccountByAddress(rpc, address, commitment) {
|
|
389
|
+
const resp = await (0, config_1.fetchConfig)(rpc, address, {
|
|
390
|
+
commitment,
|
|
391
|
+
});
|
|
392
|
+
return { pubkey: resp.address, account: resp.data };
|
|
393
|
+
}
|
|
394
|
+
async function fetchMarketAccountByAddress(rpc, address, commitment) {
|
|
395
|
+
const resp = await (0, market_1.fetchMarket)(rpc, address, {
|
|
396
|
+
commitment,
|
|
397
|
+
});
|
|
398
|
+
return { pubkey: resp.address, account: resp.data };
|
|
399
|
+
}
|
|
400
|
+
async function fetchOracleAccountByAddress(rpc, address, commitment) {
|
|
401
|
+
const resp = await (0, oracle_1.fetchOracle)(rpc, address, {
|
|
402
|
+
commitment,
|
|
403
|
+
});
|
|
404
|
+
return { pubkey: resp.address, account: resp.data };
|
|
405
|
+
}
|
|
406
|
+
async function fetchMarketsByUnderlyingAndExpiryDecoded(rpc, underlying, expiryTs, options) {
|
|
407
|
+
return fetchAndDecode(rpc, {
|
|
408
|
+
commitment: options?.commitment,
|
|
409
|
+
dataSlice: options?.dataSlice,
|
|
410
|
+
filters: [
|
|
411
|
+
memcmp(exports.MARKET_OFFSET_UNDERLYING_MINT, addrBytes(underlying)),
|
|
412
|
+
memcmp(exports.MARKET_OFFSET_EXPIRY_TS, u64Le(expiryTs)),
|
|
413
|
+
],
|
|
414
|
+
}, decodeMarketAccount);
|
|
415
|
+
}
|
|
416
|
+
// --- Decode helpers ---
|
|
417
|
+
function decodePositionAccount(data) {
|
|
418
|
+
return (0, position_1.getPositionDecoder)().decode(data);
|
|
419
|
+
}
|
|
420
|
+
function decodeMarketAccount(data) {
|
|
421
|
+
return (0, market_1.getMarketDecoder)().decode(data);
|
|
422
|
+
}
|
|
423
|
+
function decodeConfigAccount(data) {
|
|
424
|
+
return (0, config_1.getConfigDecoder)().decode(data);
|
|
425
|
+
}
|
|
426
|
+
function decodeMakerAccount(data) {
|
|
427
|
+
return (0, maker_1.getMakerDecoder)().decode(data);
|
|
428
|
+
}
|
|
429
|
+
function decodeOracleAccount(data) {
|
|
430
|
+
return (0, oracle_1.getOracleDecoder)().decode(data);
|
|
431
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fetch_1 = require("./fetch");
|
|
4
|
+
const addresses_1 = require("@solana/addresses");
|
|
5
|
+
const orders_1 = require("./orders");
|
|
6
|
+
const maker_1 = require("../generated/accounts/maker");
|
|
7
|
+
const market_1 = require("../generated/accounts/market");
|
|
8
|
+
const position_1 = require("../generated/accounts/position");
|
|
9
|
+
const buffer_1 = require("buffer");
|
|
10
|
+
describe("fetch offsets and order encode", () => {
|
|
11
|
+
it("position offsets match", () => {
|
|
12
|
+
expect(fetch_1.POSITION_OFFSET_STATUS).toBe(4);
|
|
13
|
+
expect(fetch_1.POSITION_OFFSET_TAKER_OWNER).toBe(8);
|
|
14
|
+
expect(fetch_1.POSITION_OFFSET_MAKER_OWNER).toBe(40);
|
|
15
|
+
expect(fetch_1.POSITION_OFFSET_MARKET).toBe(72);
|
|
16
|
+
});
|
|
17
|
+
it("market offsets match", () => {
|
|
18
|
+
expect(fetch_1.MARKET_OFFSET_UNDERLYING_MINT).toBe(32);
|
|
19
|
+
expect(fetch_1.MARKET_OFFSET_QUOTE_MINT).toBe(64);
|
|
20
|
+
expect(fetch_1.MARKET_OFFSET_UNDERLYING_DECIMALS).toBe(3);
|
|
21
|
+
expect(fetch_1.MARKET_OFFSET_QUOTE_DECIMALS).toBe(4);
|
|
22
|
+
expect(fetch_1.MARKET_OFFSET_FLAGS).toBe(5);
|
|
23
|
+
expect(fetch_1.MARKET_OFFSET_EXPIRY_TS).toBe(8);
|
|
24
|
+
expect(fetch_1.MARKET_OFFSET_SETTLEMENT_PRICE).toBe(16);
|
|
25
|
+
});
|
|
26
|
+
it("maker offsets match", () => {
|
|
27
|
+
expect(fetch_1.MAKER_OFFSET_MAKER_OWNER).toBe(4);
|
|
28
|
+
expect(fetch_1.MAKER_OFFSET_QUOTE_SIGNING).toBe(36);
|
|
29
|
+
});
|
|
30
|
+
it("offsets are consistent with generated account encoders (IDL-backed)", () => {
|
|
31
|
+
const decoder = (0, addresses_1.getAddressDecoder)();
|
|
32
|
+
const underlyingBytes = Uint8Array.from({ length: 32 }, (_, i) => i + 1);
|
|
33
|
+
const quoteBytes = Uint8Array.from({ length: 32 }, (_, i) => 101 + i);
|
|
34
|
+
const underlyingTokenProgramBytes = Uint8Array.from({ length: 32 }, (_, i) => 31 + i);
|
|
35
|
+
const quoteTokenProgramBytes = Uint8Array.from({ length: 32 }, (_, i) => 61 + i);
|
|
36
|
+
const makerOwnerBytes = Uint8Array.from({ length: 32 }, (_, i) => 51 + i);
|
|
37
|
+
const makerSigningBytes = Uint8Array.from({ length: 32 }, (_, i) => 151 + i);
|
|
38
|
+
const underlyingOracleBytes = Uint8Array.from({ length: 32 }, (_, i) => 181 + i);
|
|
39
|
+
const quoteOracleBytes = Uint8Array.from({ length: 32 }, (_, i) => 211 + i);
|
|
40
|
+
const takerBytes = Uint8Array.from({ length: 32 }, (_, i) => 9 + i);
|
|
41
|
+
const marketBytes = Uint8Array.from({ length: 32 }, (_, i) => 77 + i);
|
|
42
|
+
const underlyingMint = decoder.decode(underlyingBytes);
|
|
43
|
+
const quoteMint = decoder.decode(quoteBytes);
|
|
44
|
+
const makerOwner = decoder.decode(makerOwnerBytes);
|
|
45
|
+
const quoteSigning = decoder.decode(makerSigningBytes);
|
|
46
|
+
const takerOwner = decoder.decode(takerBytes);
|
|
47
|
+
const market = decoder.decode(marketBytes);
|
|
48
|
+
const underlyingTokenProgramId = decoder.decode(underlyingTokenProgramBytes);
|
|
49
|
+
const quoteTokenProgramId = decoder.decode(quoteTokenProgramBytes);
|
|
50
|
+
const underlyingOracleAddress = decoder.decode(underlyingOracleBytes);
|
|
51
|
+
const quoteOracleAddress = decoder.decode(quoteOracleBytes);
|
|
52
|
+
// --- Market layout ---
|
|
53
|
+
const expiryTs = 0x0102030405060708n;
|
|
54
|
+
const settlementPrice = 0x1122334455667788n;
|
|
55
|
+
const marketData = (0, market_1.getMarketEncoder)().encode({
|
|
56
|
+
discriminator: 4,
|
|
57
|
+
version: 1,
|
|
58
|
+
bump: 9,
|
|
59
|
+
underlyingDecimals: 7,
|
|
60
|
+
quoteDecimals: 8,
|
|
61
|
+
flags: 0b0000_0010,
|
|
62
|
+
reservedByte1: 0,
|
|
63
|
+
reservedByte2: 0,
|
|
64
|
+
expiryTs,
|
|
65
|
+
settlementPrice,
|
|
66
|
+
openPositionsCount: 0x9999888877776666n,
|
|
67
|
+
underlyingTokenProgramId,
|
|
68
|
+
quoteTokenProgramId,
|
|
69
|
+
underlyingOracleAddress,
|
|
70
|
+
quoteOracleAddress,
|
|
71
|
+
reserved: Array(24).fill(0n),
|
|
72
|
+
underlyingMint,
|
|
73
|
+
quoteMint,
|
|
74
|
+
});
|
|
75
|
+
expect(marketData.length).toBe((0, market_1.getMarketSize)());
|
|
76
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_UNDERLYING_MINT, fetch_1.MARKET_OFFSET_UNDERLYING_MINT + 32))).toEqual(buffer_1.Buffer.from(underlyingBytes));
|
|
77
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_QUOTE_MINT, fetch_1.MARKET_OFFSET_QUOTE_MINT + 32))).toEqual(buffer_1.Buffer.from(quoteBytes));
|
|
78
|
+
expect(marketData[fetch_1.MARKET_OFFSET_UNDERLYING_DECIMALS]).toBe(7);
|
|
79
|
+
expect(marketData[fetch_1.MARKET_OFFSET_QUOTE_DECIMALS]).toBe(8);
|
|
80
|
+
const expiryBuf = buffer_1.Buffer.alloc(8);
|
|
81
|
+
expiryBuf.writeBigUInt64LE(expiryTs);
|
|
82
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_EXPIRY_TS, fetch_1.MARKET_OFFSET_EXPIRY_TS + 8))).toEqual(expiryBuf);
|
|
83
|
+
expect(marketData[fetch_1.MARKET_OFFSET_FLAGS]).toBe(0b0000_0010);
|
|
84
|
+
const settleBuf = buffer_1.Buffer.alloc(8);
|
|
85
|
+
settleBuf.writeBigUInt64LE(settlementPrice);
|
|
86
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_SETTLEMENT_PRICE, fetch_1.MARKET_OFFSET_SETTLEMENT_PRICE + 8))).toEqual(settleBuf);
|
|
87
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS, fetch_1.MARKET_OFFSET_UNDERLYING_ORACLE_ADDRESS + 32))).toEqual(buffer_1.Buffer.from(underlyingOracleBytes));
|
|
88
|
+
expect(buffer_1.Buffer.from(marketData.slice(fetch_1.MARKET_OFFSET_QUOTE_ORACLE_ADDRESS, fetch_1.MARKET_OFFSET_QUOTE_ORACLE_ADDRESS + 32))).toEqual(buffer_1.Buffer.from(quoteOracleBytes));
|
|
89
|
+
// --- Position layout ---
|
|
90
|
+
const positionData = (0, position_1.getPositionEncoder)().encode({
|
|
91
|
+
discriminator: 1,
|
|
92
|
+
version: 1,
|
|
93
|
+
bump: 7,
|
|
94
|
+
positionType: 9,
|
|
95
|
+
status: 3,
|
|
96
|
+
flags: 0,
|
|
97
|
+
flags2: 0,
|
|
98
|
+
flags3: 0,
|
|
99
|
+
takerOwner,
|
|
100
|
+
makerOwner,
|
|
101
|
+
market,
|
|
102
|
+
strike: 0x0102030405060708n,
|
|
103
|
+
quantity: 0x1111222233334444n,
|
|
104
|
+
totalPremium: 0x9999888877776666n,
|
|
105
|
+
orderId: new Uint8Array(32).fill(0x88),
|
|
106
|
+
reserved: Array(32).fill(0n),
|
|
107
|
+
});
|
|
108
|
+
expect(positionData.length).toBe((0, position_1.getPositionSize)());
|
|
109
|
+
expect(positionData[fetch_1.POSITION_OFFSET_STATUS]).toBe(3);
|
|
110
|
+
expect(buffer_1.Buffer.from(positionData.slice(fetch_1.POSITION_OFFSET_TAKER_OWNER, fetch_1.POSITION_OFFSET_TAKER_OWNER + 32))).toEqual(buffer_1.Buffer.from(takerBytes));
|
|
111
|
+
expect(buffer_1.Buffer.from(positionData.slice(fetch_1.POSITION_OFFSET_MAKER_OWNER, fetch_1.POSITION_OFFSET_MAKER_OWNER + 32))).toEqual(buffer_1.Buffer.from(makerOwnerBytes));
|
|
112
|
+
expect(buffer_1.Buffer.from(positionData.slice(fetch_1.POSITION_OFFSET_MARKET, fetch_1.POSITION_OFFSET_MARKET + 32))).toEqual(buffer_1.Buffer.from(marketBytes));
|
|
113
|
+
// --- Maker layout ---
|
|
114
|
+
const makerData = (0, maker_1.getMakerEncoder)().encode({
|
|
115
|
+
discriminator: 2,
|
|
116
|
+
version: 1,
|
|
117
|
+
bump: 5,
|
|
118
|
+
flags: 0,
|
|
119
|
+
makerOwner,
|
|
120
|
+
quoteSigning,
|
|
121
|
+
reserved: Array(32).fill(0n),
|
|
122
|
+
});
|
|
123
|
+
expect(makerData.length).toBe((0, maker_1.getMakerSize)());
|
|
124
|
+
expect(buffer_1.Buffer.from(makerData.slice(fetch_1.MAKER_OFFSET_MAKER_OWNER, fetch_1.MAKER_OFFSET_MAKER_OWNER + 32))).toEqual(buffer_1.Buffer.from(makerOwnerBytes));
|
|
125
|
+
expect(buffer_1.Buffer.from(makerData.slice(fetch_1.MAKER_OFFSET_QUOTE_SIGNING, fetch_1.MAKER_OFFSET_QUOTE_SIGNING + 32))).toEqual(buffer_1.Buffer.from(makerSigningBytes));
|
|
126
|
+
});
|
|
127
|
+
it("order preimage encodes to 182 bytes", () => {
|
|
128
|
+
const decoder = (0, addresses_1.getAddressDecoder)();
|
|
129
|
+
const marketBytes = new Uint8Array(Array(32).fill(1));
|
|
130
|
+
const makerBytes = new Uint8Array(Array(32).fill(7));
|
|
131
|
+
const takerBytes = new Uint8Array(Array(32).fill(8));
|
|
132
|
+
const programBytes = new Uint8Array(Array(32).fill(9));
|
|
133
|
+
const market = decoder.decode(marketBytes);
|
|
134
|
+
const maker = decoder.decode(makerBytes);
|
|
135
|
+
const taker = decoder.decode(takerBytes);
|
|
136
|
+
const programId = decoder.decode(programBytes);
|
|
137
|
+
const preimage = (0, orders_1.encodeOrderPreimage)({
|
|
138
|
+
chainId: 0n,
|
|
139
|
+
programId,
|
|
140
|
+
isTakerBuy: false,
|
|
141
|
+
positionType: 0,
|
|
142
|
+
market,
|
|
143
|
+
strike: 2n,
|
|
144
|
+
quantity: 3n,
|
|
145
|
+
price: 4n,
|
|
146
|
+
validUntil: 5n,
|
|
147
|
+
maker,
|
|
148
|
+
taker,
|
|
149
|
+
nonce: 6n,
|
|
150
|
+
});
|
|
151
|
+
expect(preimage.length).toBe(4 + 8 + 32 + 138);
|
|
152
|
+
expect(preimage.slice(0, 4)).toEqual(new Uint8Array([0x41, 0x43, 0x54, 0x41])); // "ACTA"
|
|
153
|
+
expect(preimage.slice(12, 44)).toEqual(programBytes);
|
|
154
|
+
const base = 44;
|
|
155
|
+
expect(preimage[base]).toBe(0);
|
|
156
|
+
expect(preimage.slice(base + 2, base + 34)).toEqual(marketBytes);
|
|
157
|
+
expect(preimage.slice(base + 66, base + 98)).toEqual(makerBytes);
|
|
158
|
+
expect(preimage.slice(base + 98, base + 130)).toEqual(takerBytes);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./openPosition"), exports);
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildOpenPositionFlowIxs = buildOpenPositionFlowIxs;
|
|
4
|
+
const orders_1 = require("../orders");
|
|
5
|
+
const helpers_1 = require("../helpers");
|
|
6
|
+
const instructions_1 = require("../instructions");
|
|
7
|
+
const orderId_1 = require("../../types/orderId");
|
|
8
|
+
const index_1 = require("../../index");
|
|
9
|
+
const toAddress = (value) => typeof value === "string" ? value : value.address;
|
|
10
|
+
function assertSignerPubkeyMatches(label, signer, expected) {
|
|
11
|
+
if (signer.publicKey !== expected) {
|
|
12
|
+
throw new Error(`${label}.publicKey must match ${expected}`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build the minimal instruction set required for `open_position`:
|
|
17
|
+
* - Ed25519 verify (maker quote signing key) over 32-byte orderId
|
|
18
|
+
* - OpenPosition instruction
|
|
19
|
+
*/
|
|
20
|
+
async function buildOpenPositionFlowIxs(args) {
|
|
21
|
+
assertSignerPubkeyMatches("makerSigner", args.makerSigner, args.makerQuoteSigning);
|
|
22
|
+
const marketPda = await (0, helpers_1.findMarketPda)({
|
|
23
|
+
underlyingMint: args.underlyingMint,
|
|
24
|
+
quoteMint: args.quoteMint,
|
|
25
|
+
expiryTs: args.expiryTs,
|
|
26
|
+
isPut: args.isPut,
|
|
27
|
+
});
|
|
28
|
+
const orderId = (0, orders_1.computeOrderId)({
|
|
29
|
+
chainId: 0,
|
|
30
|
+
programId: args.programId ?? (0, index_1.getActaProgramId)(),
|
|
31
|
+
isTakerBuy: false,
|
|
32
|
+
positionType: args.positionType,
|
|
33
|
+
market: marketPda,
|
|
34
|
+
strike: args.strike,
|
|
35
|
+
quantity: args.quantity,
|
|
36
|
+
price: args.price,
|
|
37
|
+
validUntil: args.validUntil,
|
|
38
|
+
maker: args.makerOwner,
|
|
39
|
+
taker: toAddress(args.user),
|
|
40
|
+
nonce: args.nonce,
|
|
41
|
+
});
|
|
42
|
+
(0, orderId_1.assertOrderId32)(orderId);
|
|
43
|
+
const positionPda = await (0, helpers_1.findPositionPda)({ orderId });
|
|
44
|
+
const makerSig = await args.makerSigner.signMessage(orderId);
|
|
45
|
+
const makerSigIx = (0, orders_1.orderSignatureInstruction)({
|
|
46
|
+
publicKey: args.makerQuoteSigning,
|
|
47
|
+
signature: makerSig,
|
|
48
|
+
message: orderId,
|
|
49
|
+
});
|
|
50
|
+
const openPositionIx = await (0, instructions_1.buildOpenPositionIx)({
|
|
51
|
+
keeper: args.keeper,
|
|
52
|
+
user: args.user,
|
|
53
|
+
makerOwner: args.makerOwner,
|
|
54
|
+
underlyingMint: args.underlyingMint,
|
|
55
|
+
quoteMint: args.quoteMint,
|
|
56
|
+
premiumMint: args.premiumMint,
|
|
57
|
+
positionType: args.positionType,
|
|
58
|
+
strike: args.strike,
|
|
59
|
+
quantity: args.quantity,
|
|
60
|
+
price: args.price,
|
|
61
|
+
validUntil: args.validUntil,
|
|
62
|
+
nonce: args.nonce,
|
|
63
|
+
orderId,
|
|
64
|
+
isPut: args.isPut,
|
|
65
|
+
expiryTs: args.expiryTs,
|
|
66
|
+
configPda: args.configPda,
|
|
67
|
+
tokenProgram: args.tokenProgram,
|
|
68
|
+
underlyingTokenProgram: args.underlyingTokenProgram,
|
|
69
|
+
quoteTokenProgram: args.quoteTokenProgram,
|
|
70
|
+
rpc: args.rpc,
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
orderId,
|
|
74
|
+
orderIdHex: (0, orderId_1.orderIdToHex)(orderId),
|
|
75
|
+
marketPda,
|
|
76
|
+
positionPda,
|
|
77
|
+
makerSigIx,
|
|
78
|
+
openPositionIx,
|
|
79
|
+
ixs: [makerSigIx, openPositionIx],
|
|
80
|
+
};
|
|
81
|
+
}
|