@symmetry-hq/temp-v3-sdk 0.0.1
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/dist/idl/idl.d.ts +8 -0
- package/dist/idl/idl.js +4958 -0
- package/dist/idl/types.d.ts +4955 -0
- package/dist/idl/types.js +2 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +60 -0
- package/dist/layouts/basket.d.ts +42 -0
- package/dist/layouts/basket.js +43 -0
- package/dist/layouts/config.d.ts +97 -0
- package/dist/layouts/config.js +102 -0
- package/dist/layouts/fraction.d.ts +6 -0
- package/dist/layouts/fraction.js +9 -0
- package/dist/layouts/oracle.d.ts +36 -0
- package/dist/layouts/oracle.js +37 -0
- package/dist/src/constants.d.ts +15 -0
- package/dist/src/constants.js +19 -0
- package/dist/src/idl/idl.d.ts +8 -0
- package/dist/src/idl/idl.js +4958 -0
- package/dist/src/idl/types.d.ts +4955 -0
- package/dist/src/idl/types.js +2 -0
- package/dist/src/index.d.ts +53 -0
- package/dist/src/index.js +199 -0
- package/dist/src/instructions/accounts.d.ts +27 -0
- package/dist/src/instructions/accounts.js +110 -0
- package/dist/src/instructions/auction.d.ts +7 -0
- package/dist/src/instructions/auction.js +43 -0
- package/dist/src/instructions/automation/auction.d.ts +6 -0
- package/dist/src/instructions/automation/auction.js +40 -0
- package/dist/src/instructions/automation/claimBounty.d.ts +12 -0
- package/dist/src/instructions/automation/claimBounty.js +44 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +15 -0
- package/dist/src/instructions/automation/priceUpdate.js +47 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +10 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/basket.d.ts +120 -0
- package/dist/src/instructions/basket.js +622 -0
- package/dist/src/instructions/bounty.d.ts +18 -0
- package/dist/src/instructions/bounty.js +81 -0
- package/dist/src/instructions/fee.d.ts +8 -0
- package/dist/src/instructions/fee.js +46 -0
- package/dist/src/instructions/globalConfig.d.ts +11 -0
- package/dist/src/instructions/globalConfig.js +43 -0
- package/dist/src/instructions/luts.d.ts +33 -0
- package/dist/src/instructions/luts.js +91 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +39 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +43 -0
- package/dist/src/instructions/management/claimFees.d.ts +7 -0
- package/dist/src/instructions/management/claimFees.js +47 -0
- package/dist/src/instructions/management/createBasket.d.ts +22 -0
- package/dist/src/instructions/management/createBasket.js +101 -0
- package/dist/src/instructions/management/edit.d.ts +34 -0
- package/dist/src/instructions/management/edit.js +192 -0
- package/dist/src/instructions/management/luts.d.ts +29 -0
- package/dist/src/instructions/management/luts.js +88 -0
- package/dist/src/instructions/pda.d.ts +26 -0
- package/dist/src/instructions/pda.js +110 -0
- package/dist/src/instructions/price.d.ts +17 -0
- package/dist/src/instructions/price.js +47 -0
- package/dist/src/instructions/user/deposit.d.ts +32 -0
- package/dist/src/instructions/user/deposit.js +168 -0
- package/dist/src/instructions/user/withdraw.d.ts +16 -0
- package/dist/src/instructions/user/withdraw.js +82 -0
- package/dist/src/layouts/basket.d.ts +41 -0
- package/dist/src/layouts/basket.js +43 -0
- package/dist/src/layouts/config.d.ts +133 -0
- package/dist/src/layouts/config.js +137 -0
- package/dist/src/layouts/fraction.d.ts +6 -0
- package/dist/src/layouts/fraction.js +9 -0
- package/dist/src/layouts/intents/bounty.d.ts +18 -0
- package/dist/src/layouts/intents/bounty.js +19 -0
- package/dist/src/layouts/intents/intent.d.ts +101 -0
- package/dist/src/layouts/intents/intent.js +113 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +56 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +63 -0
- package/dist/src/layouts/lookupTable.d.ts +7 -0
- package/dist/src/layouts/lookupTable.js +10 -0
- package/dist/src/layouts/oracle.d.ts +42 -0
- package/dist/src/layouts/oracle.js +43 -0
- package/dist/src/states/basket.d.ts +8 -0
- package/dist/src/states/basket.js +54 -0
- package/dist/src/states/intents/intent.d.ts +14 -0
- package/dist/src/states/intents/intent.js +90 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +8 -0
- package/dist/src/states/intents/rebalanceIntent.js +54 -0
- package/dist/src/states/oracles/clmm_oracle.d.ts +178 -0
- package/dist/src/states/oracles/clmm_oracle.js +546 -0
- package/dist/src/states/oracles/constants.d.ts +8 -0
- package/dist/src/states/oracles/constants.js +12 -0
- package/dist/src/states/oracles/oracle.d.ts +60 -0
- package/dist/src/states/oracles/oracle.js +237 -0
- package/dist/src/states/oracles/pythOracle.d.ts +39 -0
- package/dist/src/states/oracles/pythOracle.js +202 -0
- package/dist/src/states/oracles/pyth_oracle.d.ts +39 -0
- package/dist/src/states/oracles/pyth_oracle.js +202 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +178 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +546 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +139 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +420 -0
- package/dist/src/states/oracles/raydium_cpmm_oracle.d.ts +139 -0
- package/dist/src/states/oracles/raydium_cpmm_oracle.js +420 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/oracles/switchboard_oracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboard_oracle.js +1 -0
- package/dist/src/txUtils.d.ts +26 -0
- package/dist/src/txUtils.js +183 -0
- package/dist/states/basket.d.ts +8 -0
- package/dist/states/basket.js +57 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +39 -0
- package/package.json +30 -0
- package/src/constants.ts +24 -0
- package/src/index.ts +260 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/priceUpdate.ts +73 -0
- package/src/instructions/automation/rebalanceSwap.ts +60 -0
- package/src/instructions/management/addBounty.ts +56 -0
- package/src/instructions/management/admin.ts +65 -0
- package/src/instructions/management/claimFees.ts +59 -0
- package/src/instructions/management/createBasket.ts +148 -0
- package/src/instructions/management/edit.ts +255 -0
- package/src/instructions/management/luts.ts +134 -0
- package/src/instructions/pda.ts +160 -0
- package/src/instructions/user/deposit.ts +237 -0
- package/src/instructions/user/withdraw.ts +130 -0
- package/src/layouts/basket.ts +82 -0
- package/src/layouts/config.ts +301 -0
- package/src/layouts/fraction.ts +12 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +204 -0
- package/src/layouts/intents/rebalanceIntent.ts +111 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +96 -0
- package/src/states/basket.ts +56 -0
- package/src/states/intents/intent.ts +107 -0
- package/src/states/intents/rebalanceIntent.ts +57 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +260 -0
- package/src/states/oracles/pythOracle.ts +270 -0
- package/src/states/oracles/raydiumClmmOracle.ts +812 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +614 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/txUtils.ts +250 -0
- package/test.ts +30 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
|
|
4
|
+
import { Fraction, FractionLayout } from "../fraction";
|
|
5
|
+
import { Bounty, BountyLayout } from "./bounty";
|
|
6
|
+
import { OraclePrice } from "../../states/oracles/oracle";
|
|
7
|
+
import { OraclePriceLayout } from "../oracle";
|
|
8
|
+
import { MAX_SUPPORTED_TOKENS_PER_BASKET } from "../basket";
|
|
9
|
+
|
|
10
|
+
export enum RebalanceType {
|
|
11
|
+
Deposit,
|
|
12
|
+
Withdraw,
|
|
13
|
+
Basket
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export enum RebalanceAction {
|
|
17
|
+
NotActive,
|
|
18
|
+
DepositTokens,
|
|
19
|
+
UpdatePrices,
|
|
20
|
+
AuctionLive
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export interface AuctionTimestamps {
|
|
24
|
+
startTime: BN; // u64
|
|
25
|
+
endTime: BN; // u64
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const AuctionTimestampsLayout = struct<AuctionTimestamps>([
|
|
29
|
+
u64('startTime'),
|
|
30
|
+
u64('endTime'),
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
export interface TokenAuction {
|
|
34
|
+
mint: PublicKey;
|
|
35
|
+
amount: BN; // u64
|
|
36
|
+
targetAmount: BN; // u64
|
|
37
|
+
price: OraclePrice;
|
|
38
|
+
keepToken: number; // u8
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const TokenAuctionLayout = struct<TokenAuction>([
|
|
42
|
+
publicKey('mint'),
|
|
43
|
+
u64('amount'),
|
|
44
|
+
u64('targetAmount'),
|
|
45
|
+
OraclePriceLayout.replicate('price'),
|
|
46
|
+
u8('keepToken'),
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
export interface TaskCompletion {
|
|
50
|
+
completedBounty: BN; //u64
|
|
51
|
+
completedTime: BN; //u64
|
|
52
|
+
completedBy: PublicKey; //Pubkey
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const TaskCompletionLayout = struct<TaskCompletion>([
|
|
56
|
+
u64('completedBounty'),
|
|
57
|
+
u64('completedTime'),
|
|
58
|
+
publicKey('completedBy'),
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
export interface RebalanceIntent {
|
|
62
|
+
basket: PublicKey;
|
|
63
|
+
owner: PublicKey;
|
|
64
|
+
rentPayer: PublicKey;
|
|
65
|
+
rebalanceType: RebalanceType;
|
|
66
|
+
currentAction: RebalanceAction;
|
|
67
|
+
|
|
68
|
+
executionStartTime: BN; // u64
|
|
69
|
+
rebalanceSlippageBps: number; // u16
|
|
70
|
+
initialTvl: Fraction; //
|
|
71
|
+
auctionUpdateTimestamp: BN; // u64
|
|
72
|
+
auctions: AuctionTimestamps; // AuctionTimestamps[3]
|
|
73
|
+
tokens: TokenAuction[]; // MAX_SUPPORTED_TOKENS_PER_BASKET
|
|
74
|
+
|
|
75
|
+
lastActionTimestamp: BN; // u64
|
|
76
|
+
bounty: Bounty; // u64
|
|
77
|
+
|
|
78
|
+
startPriceUpdateTask: TaskCompletion;
|
|
79
|
+
priceUpdateTasks: TaskCompletion[]; // MAX_SUPPORTED_TOKENS_PER_BASKET
|
|
80
|
+
finishPriceUpdateTask: TaskCompletion;
|
|
81
|
+
|
|
82
|
+
mintBasketTask: TaskCompletion;
|
|
83
|
+
|
|
84
|
+
tokenSettlementTasks: TaskCompletion[]; // MAX_SUPPORTED_TOKENS_PER_BASKET
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export const RebalanceIntentLayout = struct<RebalanceIntent>([
|
|
89
|
+
publicKey('basket'),
|
|
90
|
+
publicKey('owner'),
|
|
91
|
+
publicKey('rentPayer'),
|
|
92
|
+
u8('rebalanceType'),
|
|
93
|
+
u8('currentAction'),
|
|
94
|
+
|
|
95
|
+
u64('executionStartTime'),
|
|
96
|
+
u16('rebalanceSlippageBps'),
|
|
97
|
+
FractionLayout.replicate('initialTvl'),
|
|
98
|
+
u64('auctionUpdateTimestamp'),
|
|
99
|
+
array(AuctionTimestampsLayout, 3, 'auctions'),
|
|
100
|
+
array(TokenAuctionLayout, MAX_SUPPORTED_TOKENS_PER_BASKET, 'tokens'),
|
|
101
|
+
u64('lastActionTimestamp'),
|
|
102
|
+
BountyLayout.replicate('bounty'),
|
|
103
|
+
|
|
104
|
+
TaskCompletionLayout.replicate('startPriceUpdateTask'),
|
|
105
|
+
array(TaskCompletionLayout, MAX_SUPPORTED_TOKENS_PER_BASKET, 'priceUpdateTasks'),
|
|
106
|
+
TaskCompletionLayout.replicate('finishPriceUpdateTask'),
|
|
107
|
+
|
|
108
|
+
TaskCompletionLayout.replicate('mintBasketTask'),
|
|
109
|
+
|
|
110
|
+
array(TaskCompletionLayout, MAX_SUPPORTED_TOKENS_PER_BASKET, 'tokenSettlementTasks'),
|
|
111
|
+
]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { publicKey, struct } from '@coral-xyz/borsh';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
export interface LookupTableInfo {
|
|
5
|
+
lookupTable: PublicKey,
|
|
6
|
+
authority: PublicKey,
|
|
7
|
+
creator: PublicKey
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const LookupTableInfoLayout = struct<LookupTableInfo>([
|
|
11
|
+
publicKey("lookupTable"),
|
|
12
|
+
publicKey("authority"),
|
|
13
|
+
publicKey("creator")
|
|
14
|
+
]);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
|
|
3
|
+
import { Fraction, FractionLayout } from "./fraction";
|
|
4
|
+
|
|
5
|
+
export const MAX_ORACLES_PER_TOKEN = 4;
|
|
6
|
+
export const MAX_ACCOUNTS_PER_ORACLE = 4;
|
|
7
|
+
|
|
8
|
+
export interface OraclePrice {
|
|
9
|
+
price: Fraction;
|
|
10
|
+
conf: Fraction;
|
|
11
|
+
updateTime: BN; // u64
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const OraclePriceLayout = struct<OraclePrice>([
|
|
15
|
+
FractionLayout.replicate('price'),
|
|
16
|
+
FractionLayout.replicate('conf'),
|
|
17
|
+
u64('updateTime'),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export interface OracleSettings {
|
|
22
|
+
// type of the oracle (Pyth, CP swap, ...)
|
|
23
|
+
oracleType: number; // u8
|
|
24
|
+
numRequiredAccounts: number; // u8
|
|
25
|
+
// weight used in aggregation
|
|
26
|
+
weight: number; // u16
|
|
27
|
+
// whether oracle is required for aggregation
|
|
28
|
+
isRequired: number; // u8
|
|
29
|
+
// threshold for confidence ratio (conf / price < threshold)
|
|
30
|
+
confThreshBps: number; // u16
|
|
31
|
+
// how old a price can be before it's invalid
|
|
32
|
+
stalenessThresh: BN; // u64
|
|
33
|
+
// how much internal price derivations can differ (≥ 1.0)
|
|
34
|
+
volatilityThreshBps: number; // u16
|
|
35
|
+
// minimum liquidity (in quote tokens) for valid price
|
|
36
|
+
minLiquidity: BN; //u64
|
|
37
|
+
// rate (bps) that inflates confidence with time staleness
|
|
38
|
+
stalenessConfRateBps: number; // u16
|
|
39
|
+
tokenDecimals: number; // u8
|
|
40
|
+
// Special parameters specific to Raydium
|
|
41
|
+
twapSecondsAgo: BN; // u64, primary twap window in seconds
|
|
42
|
+
twapSecondarySecondsAgo: BN; // u64, secondary twap window - to check volatility
|
|
43
|
+
quote: number; // u8, 1 = USDC, 2 = WSOL
|
|
44
|
+
side: number; // 0 = base, 1 = quote
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const OracleSettingsLayout = struct<OracleSettings>([
|
|
48
|
+
u8('oracleType'),
|
|
49
|
+
u8('numRequiredAccounts'),
|
|
50
|
+
u16('weight'),
|
|
51
|
+
u8('isRequired'),
|
|
52
|
+
u16('confThreshBps'),
|
|
53
|
+
u64('stalenessThresh'),
|
|
54
|
+
u16('volatilityThreshBps'),
|
|
55
|
+
u64('minLiquidity'),
|
|
56
|
+
u16('stalenessConfRateBps'),
|
|
57
|
+
u8('tokenDecimals'),
|
|
58
|
+
u64('twapSecondsAgo'),
|
|
59
|
+
u64('twapSecondarySecondsAgo'),
|
|
60
|
+
u8('quote'),
|
|
61
|
+
u8('side')
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
export interface OracleData {
|
|
65
|
+
oracleSettings: OracleSettings;
|
|
66
|
+
accountsToLoadLutIds: number[]; // length MAX_ACCOUNTS_PER_ORACLE
|
|
67
|
+
accountsToLoadLutIndices: number[]; // length MAX_ACCOUNTS_PER_ORACLE
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const OracleDataLayout = struct<OracleData>([
|
|
71
|
+
OracleSettingsLayout.replicate('oracleSettings'),
|
|
72
|
+
array(u8(), MAX_ACCOUNTS_PER_ORACLE, 'accountsToLoadLutIds'),
|
|
73
|
+
array(u8(), MAX_ACCOUNTS_PER_ORACLE, 'accountsToLoadLutIndices'),
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
export interface OracleAggregator {
|
|
77
|
+
numOracles: number; // u8
|
|
78
|
+
oracles: OracleData[]; // [OracleData; MAX_ORACLES_PER_TOKEN]
|
|
79
|
+
// minimum confidence ratio allowed (conf / price)
|
|
80
|
+
minConfBps: number; // u16
|
|
81
|
+
// maximum confidence ratio allowed (conf / price)
|
|
82
|
+
confThreshBps: number; // u16
|
|
83
|
+
// minimum number of oracle results required for valid price
|
|
84
|
+
minOraclesThresh: number; // u8
|
|
85
|
+
// factor to expand confidence bands (≥ 1.0)
|
|
86
|
+
confMultiplier: Fraction;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const OracleAggregatorLayout = struct<OracleAggregator>([
|
|
90
|
+
u8('numOracles'),
|
|
91
|
+
array(OracleDataLayout, MAX_ORACLES_PER_TOKEN, 'oracles'),
|
|
92
|
+
u16('minConfBps'),
|
|
93
|
+
u16('confThreshBps'),
|
|
94
|
+
u8('minOraclesThresh'),
|
|
95
|
+
FractionLayout.replicate('confMultiplier')
|
|
96
|
+
]);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Connection, GetProgramAccountsFilter, GetProgramAccountsResponse, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { AssetLayout, Basket, BasketLayout, LookupTablesLayout } from "../layouts/basket";
|
|
3
|
+
import { BASKETS_V3_PROGRAM_ID } from "../constants";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export async function fetchBasket(
|
|
7
|
+
connection: Connection,
|
|
8
|
+
basketAddress: PublicKey,
|
|
9
|
+
): Promise<Basket> {
|
|
10
|
+
const basketAi = await connection.getAccountInfo(basketAddress);
|
|
11
|
+
if (!basketAi) {
|
|
12
|
+
throw new Error("Basket not found");
|
|
13
|
+
}
|
|
14
|
+
return BasketLayout.decode(basketAi.data.slice(8));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface BasketFilter {
|
|
18
|
+
filterType: "host" | "creator";
|
|
19
|
+
filterValue: PublicKey;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function fetchBaskets(
|
|
23
|
+
connection: Connection,
|
|
24
|
+
filters: BasketFilter[],
|
|
25
|
+
): Promise<Basket[]> {
|
|
26
|
+
console.log("fetching baskets with size", BasketLayout.getSpan());
|
|
27
|
+
let accountFilters: GetProgramAccountsFilter[] = [
|
|
28
|
+
{ dataSize: 8 + BasketLayout.getSpan() },
|
|
29
|
+
];
|
|
30
|
+
for (const filter of filters) {
|
|
31
|
+
if (filter.filterType === "host") {
|
|
32
|
+
accountFilters.push({ memcmp: {
|
|
33
|
+
offset: 8 + 1 + 16 + 32 + 32 + 8 + 16 + 8,
|
|
34
|
+
bytes: filter.filterValue.toBase58()
|
|
35
|
+
} });
|
|
36
|
+
} else if (filter.filterType === "creator") {
|
|
37
|
+
accountFilters.push({ memcmp: {
|
|
38
|
+
offset: 8 + 1 + 16 + 32 + 32 + 8 + 16 + 8 + 32,
|
|
39
|
+
bytes: filter.filterValue.toBase58()
|
|
40
|
+
} });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const accounts: GetProgramAccountsResponse = await connection
|
|
44
|
+
.getProgramAccounts(
|
|
45
|
+
BASKETS_V3_PROGRAM_ID,
|
|
46
|
+
{
|
|
47
|
+
commitment: "confirmed",
|
|
48
|
+
filters: accountFilters,
|
|
49
|
+
encoding: 'base64'
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
const baskets: Basket[] = accounts.map(account =>
|
|
53
|
+
BasketLayout.decode(account.account.data.slice(8))
|
|
54
|
+
);
|
|
55
|
+
return baskets;
|
|
56
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BN } from '@coral-xyz/anchor';
|
|
2
|
+
import { array, publicKey, struct, u16, u32, u64, u8 } from '@coral-xyz/borsh';
|
|
3
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
|
+
|
|
5
|
+
import { BASKETS_V3_PROGRAM_ID } from '../../constants';
|
|
6
|
+
import { AddTokenDelayLayout, AddTokenLayout, Intent, IntentLayout, IntentStatus, ManagerSettingsWithAuthorityBitmasksLayout, ParsedIntent, SwapLayout, TaskType, UpdateWeightsDelayLayout, UpdateWeightsLayout } from '../../layouts/intents/intent';
|
|
7
|
+
import { MetadataSettingsLayout, AutomationSettingsLayout, FeeSettingsLayout, LpSettingsLayout, ScheduleSettingsLayout } from '../../layouts/config';
|
|
8
|
+
import { GetProgramAccountsFilter } from '@solana/web3.js';
|
|
9
|
+
import { GetProgramAccountsResponse } from '@solana/web3.js';
|
|
10
|
+
|
|
11
|
+
// Map task type -> layout used to decode taskData prefix
|
|
12
|
+
const taskLayoutMap = new Map<number, any>([
|
|
13
|
+
[TaskType.EditSchedule, ScheduleSettingsLayout],
|
|
14
|
+
[TaskType.EditFeeSettings, FeeSettingsLayout],
|
|
15
|
+
[TaskType.EditManagerSettings, ManagerSettingsWithAuthorityBitmasksLayout],
|
|
16
|
+
[TaskType.EditAutomationSettings, AutomationSettingsLayout],
|
|
17
|
+
[TaskType.EditLpSettings, LpSettingsLayout],
|
|
18
|
+
[TaskType.EditMetadataSettings, MetadataSettingsLayout],
|
|
19
|
+
[TaskType.EditAddTokenDelay, AddTokenDelayLayout],
|
|
20
|
+
[TaskType.EditUpdateWeightsDelay, UpdateWeightsDelayLayout],
|
|
21
|
+
[TaskType.AddToken, AddTokenLayout],
|
|
22
|
+
[TaskType.UpdateWeights, UpdateWeightsLayout],
|
|
23
|
+
[TaskType.Swap, SwapLayout],
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
// Decode taskData buffer for a given task type; returns decoded object or raw Buffer on failure
|
|
27
|
+
|
|
28
|
+
function decodeTaskDataForType(
|
|
29
|
+
taskType: TaskType,
|
|
30
|
+
taskData: number[]
|
|
31
|
+
): any {
|
|
32
|
+
const layout = taskLayoutMap.get(taskType);
|
|
33
|
+
return layout.decode(taskData);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Decode an Intent account buffer.
|
|
39
|
+
* Returns ParsedIntent.
|
|
40
|
+
*/
|
|
41
|
+
export function decodeIntent(intent: Intent): ParsedIntent {
|
|
42
|
+
let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
|
|
43
|
+
return {
|
|
44
|
+
...intent,
|
|
45
|
+
taskData: parsedTaskData,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function fetchIntent(
|
|
50
|
+
connection: Connection,
|
|
51
|
+
intent: PublicKey,
|
|
52
|
+
): Promise<Intent>{
|
|
53
|
+
const intentAi = await connection.getAccountInfo(
|
|
54
|
+
intent
|
|
55
|
+
);
|
|
56
|
+
if (!intentAi) throw new Error('Basket intent not found');
|
|
57
|
+
return IntentLayout.decode(intentAi.data.slice(8));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function fetchParsedIntent(
|
|
61
|
+
connection: Connection,
|
|
62
|
+
intent: PublicKey,
|
|
63
|
+
): Promise<ParsedIntent>{
|
|
64
|
+
const intentState: Intent = await fetchIntent(connection, intent);
|
|
65
|
+
return decodeIntent(intentState);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface IntentFilter {
|
|
69
|
+
filterType: "basket" | "owner";
|
|
70
|
+
filterValue: PublicKey;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function fetchIntents(
|
|
74
|
+
connection: Connection,
|
|
75
|
+
filters: IntentFilter[],
|
|
76
|
+
): Promise<Intent[]> {
|
|
77
|
+
console.log("fetching intents with size", IntentLayout.getSpan());
|
|
78
|
+
let accountFilters: GetProgramAccountsFilter[] = [
|
|
79
|
+
{ dataSize: 8 + IntentLayout.getSpan() },
|
|
80
|
+
];
|
|
81
|
+
for (const filter of filters) {
|
|
82
|
+
if (filter.filterType === "basket") {
|
|
83
|
+
accountFilters.push({ memcmp: {
|
|
84
|
+
offset: 8 + 32 + 1 + 8,
|
|
85
|
+
bytes: filter.filterValue.toBase58()
|
|
86
|
+
} });
|
|
87
|
+
} else if (filter.filterType === "owner") {
|
|
88
|
+
accountFilters.push({ memcmp: {
|
|
89
|
+
offset: 8,
|
|
90
|
+
bytes: filter.filterValue.toBase58()
|
|
91
|
+
} });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const accounts: GetProgramAccountsResponse = await connection
|
|
95
|
+
.getProgramAccounts(
|
|
96
|
+
BASKETS_V3_PROGRAM_ID,
|
|
97
|
+
{
|
|
98
|
+
commitment: "confirmed",
|
|
99
|
+
filters: accountFilters,
|
|
100
|
+
encoding: 'base64'
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
const rebalanceIntents: Intent[] = accounts.map(account =>
|
|
104
|
+
IntentLayout.decode(account.account.data.slice(8))
|
|
105
|
+
);
|
|
106
|
+
return rebalanceIntents;
|
|
107
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Connection, GetProgramAccountsResponse, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { RebalanceIntent, RebalanceIntentLayout } from "../../layouts/intents/rebalanceIntent";
|
|
3
|
+
import { GetProgramAccountsFilter } from "@solana/web3.js";
|
|
4
|
+
import { BASKETS_V3_PROGRAM_ID } from "../../constants";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export async function fetchRebalanceIntent(
|
|
8
|
+
connection: Connection,
|
|
9
|
+
rebalanceIntent: PublicKey,
|
|
10
|
+
): Promise<RebalanceIntent> {
|
|
11
|
+
const rebalanceIntentAi = await connection.getAccountInfo(rebalanceIntent);
|
|
12
|
+
if (!rebalanceIntentAi) {
|
|
13
|
+
throw new Error("Rebalance intent not found");
|
|
14
|
+
}
|
|
15
|
+
return RebalanceIntentLayout.decode(rebalanceIntentAi.data.slice(8));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface RebalanceIntentFilter {
|
|
19
|
+
filterType: "basket" | "owner";
|
|
20
|
+
filterValue: PublicKey;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function fetchRebalanceIntents(
|
|
24
|
+
connection: Connection,
|
|
25
|
+
filters: RebalanceIntentFilter[],
|
|
26
|
+
): Promise<RebalanceIntent[]> {
|
|
27
|
+
console.log("fetching rebalance intents with size", RebalanceIntentLayout.getSpan());
|
|
28
|
+
let accountFilters: GetProgramAccountsFilter[] = [
|
|
29
|
+
{ dataSize: 8 + RebalanceIntentLayout.getSpan() },
|
|
30
|
+
];
|
|
31
|
+
for (const filter of filters) {
|
|
32
|
+
if (filter.filterType === "basket") {
|
|
33
|
+
accountFilters.push({ memcmp: {
|
|
34
|
+
offset: 8,
|
|
35
|
+
bytes: filter.filterValue.toBase58()
|
|
36
|
+
} });
|
|
37
|
+
} else if (filter.filterType === "owner") {
|
|
38
|
+
accountFilters.push({ memcmp: {
|
|
39
|
+
offset: 8 + 32,
|
|
40
|
+
bytes: filter.filterValue.toBase58()
|
|
41
|
+
} });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const accounts: GetProgramAccountsResponse = await connection
|
|
45
|
+
.getProgramAccounts(
|
|
46
|
+
BASKETS_V3_PROGRAM_ID,
|
|
47
|
+
{
|
|
48
|
+
commitment: "confirmed",
|
|
49
|
+
filters: accountFilters,
|
|
50
|
+
encoding: 'base64'
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
const rebalanceIntents: RebalanceIntent[] = accounts.map(account =>
|
|
54
|
+
RebalanceIntentLayout.decode(account.account.data.slice(8))
|
|
55
|
+
);
|
|
56
|
+
return rebalanceIntents;
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BN } from "@coral-xyz/anchor";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const U8_MAX = new BN(0xff);
|
|
5
|
+
export const U16_MAX = new BN(0xffff);
|
|
6
|
+
export const U32_MAX = new BN(0xffffffff);
|
|
7
|
+
export const U64_MAX = new BN(1).shln(64).sub(new BN(1));
|
|
8
|
+
export const U128_MAX = new BN(1).shln(128).sub(new BN(1));
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export const HERMES_PUBLIC_ENDPOINT = "https://hermes.pyth.network";
|
|
12
|
+
export const SOLANA_DEVNET_ENDPOINT = "https://api.devnet.solana.com";
|
|
13
|
+
export const SOLANA_MAINNET_ENDPOINT = "https://api.mainnet-beta.solana.com";
|