@symmetry-hq/temp-v3-sdk 0.0.2 → 0.0.4
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/src/index.d.ts +8 -4
- package/dist/src/index.js +9 -9
- package/dist/src/instructions/automation/rebalanceSwap.js +2 -2
- package/dist/src/instructions/management/addBounty.js +1 -2
- package/dist/src/instructions/management/admin.js +1 -2
- package/dist/src/instructions/management/createBasket.js +2 -2
- package/dist/src/instructions/management/edit.js +3 -3
- package/dist/src/instructions/management/luts.js +4 -5
- package/dist/src/instructions/user/deposit.js +5 -5
- package/dist/src/instructions/user/withdraw.js +3 -3
- package/dist/src/layouts/basket.d.ts +11 -5
- package/dist/src/layouts/basket.js +2 -2
- package/dist/src/layouts/config.d.ts +0 -1
- package/dist/src/layouts/config.js +3 -6
- package/dist/src/layouts/fraction.d.ts +2 -2
- package/dist/src/layouts/fraction.js +2 -2
- package/dist/src/layouts/intents/bounty.d.ts +2 -2
- package/dist/src/layouts/intents/bounty.js +2 -2
- package/dist/src/layouts/intents/intent.d.ts +2 -9
- package/dist/src/layouts/intents/intent.js +0 -1
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +3 -2
- package/dist/src/layouts/oracle.d.ts +18 -4
- package/dist/src/layouts/oracle.js +21 -1
- package/dist/src/states/basket.d.ts +3 -2
- package/dist/src/states/basket.js +15 -3
- package/dist/src/states/intents/intent.d.ts +2 -7
- package/dist/src/states/intents/intent.js +12 -16
- package/dist/src/states/intents/rebalanceIntent.d.ts +1 -0
- package/dist/src/states/intents/rebalanceIntent.js +14 -2
- package/dist/src/states/oracles/oracle.d.ts +3 -3
- package/dist/src/states/oracles/oracle.js +11 -5
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +4 -2
- package/dist/src/states/oracles/raydiumCpmmOracle.js +10 -3
- package/dist/test.js +19 -6
- package/package.json +1 -1
- package/src/index.ts +26 -10
- package/src/instructions/automation/rebalanceSwap.ts +2 -2
- package/src/instructions/management/addBounty.ts +1 -2
- package/src/instructions/management/admin.ts +1 -2
- package/src/instructions/management/createBasket.ts +2 -2
- package/src/instructions/management/edit.ts +3 -3
- package/src/instructions/management/luts.ts +4 -5
- package/src/instructions/user/deposit.ts +5 -5
- package/src/instructions/user/withdraw.ts +3 -3
- package/src/layouts/basket.ts +13 -5
- package/src/layouts/config.ts +2 -6
- package/src/layouts/fraction.ts +4 -4
- package/src/layouts/intents/bounty.ts +4 -4
- package/src/layouts/intents/intent.ts +2 -10
- package/src/layouts/intents/rebalanceIntent.ts +4 -3
- package/src/layouts/oracle.ts +22 -5
- package/src/states/basket.ts +19 -5
- package/src/states/intents/intent.ts +12 -20
- package/src/states/intents/rebalanceIntent.ts +15 -3
- package/src/states/oracles/oracle.ts +13 -9
- package/src/states/oracles/raydiumCpmmOracle.ts +11 -2
- package/test.ts +20 -7
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { Intent
|
|
3
|
-
|
|
4
|
-
* Decode an Intent account buffer.
|
|
5
|
-
* Returns ParsedIntent.
|
|
6
|
-
*/
|
|
7
|
-
export declare function decodeIntent(intent: Intent): ParsedIntent;
|
|
2
|
+
import { Intent } from '../../layouts/intents/intent';
|
|
3
|
+
export declare function decodeIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): Intent;
|
|
8
4
|
export declare function fetchIntent(connection: Connection, intent: PublicKey): Promise<Intent>;
|
|
9
|
-
export declare function fetchParsedIntent(connection: Connection, intent: PublicKey): Promise<ParsedIntent>;
|
|
10
5
|
export interface IntentFilter {
|
|
11
6
|
filterType: "basket" | "owner";
|
|
12
7
|
filterValue: PublicKey;
|
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.decodeIntent = decodeIntent;
|
|
13
13
|
exports.fetchIntent = fetchIntent;
|
|
14
|
-
exports.fetchParsedIntent = fetchParsedIntent;
|
|
15
14
|
exports.fetchIntents = fetchIntents;
|
|
16
15
|
const constants_1 = require("../../constants");
|
|
17
16
|
const intent_1 = require("../../layouts/intents/intent");
|
|
@@ -33,29 +32,26 @@ const taskLayoutMap = new Map([
|
|
|
33
32
|
// Decode taskData buffer for a given task type; returns decoded object or raw Buffer on failure
|
|
34
33
|
function decodeTaskDataForType(taskType, taskData) {
|
|
35
34
|
const layout = taskLayoutMap.get(taskType);
|
|
35
|
+
console.log(layout);
|
|
36
36
|
return layout.decode(taskData);
|
|
37
37
|
}
|
|
38
38
|
;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return Object.assign(Object.assign({}, intent), {
|
|
39
|
+
function decodeIntent(dataWithoutDiscriminator, ownAddress) {
|
|
40
|
+
let intent = intent_1.IntentLayout.decode(dataWithoutDiscriminator);
|
|
41
|
+
console.log(intent.taskData);
|
|
42
|
+
console.log(intent.taskType);
|
|
43
|
+
// let parsedTaskData = decodeTaskDataForType(intent.taskType, intent.taskData);
|
|
44
|
+
// console.log(parsedTaskData);
|
|
45
|
+
return Object.assign(Object.assign({}, intent), {
|
|
46
|
+
// parsedTaskData: parsedTaskData,
|
|
47
|
+
ownAddress: ownAddress });
|
|
46
48
|
}
|
|
47
49
|
function fetchIntent(connection, intent) {
|
|
48
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
51
|
const intentAi = yield connection.getAccountInfo(intent);
|
|
50
52
|
if (!intentAi)
|
|
51
53
|
throw new Error('Basket intent not found');
|
|
52
|
-
return
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function fetchParsedIntent(connection, intent) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const intentState = yield fetchIntent(connection, intent);
|
|
58
|
-
return decodeIntent(intentState);
|
|
54
|
+
return decodeIntent(intentAi.data.slice(8), intent);
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
57
|
function fetchIntents(connection, filters) {
|
|
@@ -84,7 +80,7 @@ function fetchIntents(connection, filters) {
|
|
|
84
80
|
filters: accountFilters,
|
|
85
81
|
encoding: 'base64'
|
|
86
82
|
});
|
|
87
|
-
const rebalanceIntents = accounts.map(account =>
|
|
83
|
+
const rebalanceIntents = accounts.map(account => decodeIntent(account.account.data.slice(8), account.pubkey));
|
|
88
84
|
return rebalanceIntents;
|
|
89
85
|
});
|
|
90
86
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { RebalanceIntent } from "../../layouts/intents/rebalanceIntent";
|
|
3
|
+
export declare function decodeRebalanceIntent(dataWithoutDiscriminator: Buffer, ownAddress?: PublicKey): RebalanceIntent;
|
|
3
4
|
export declare function fetchRebalanceIntent(connection: Connection, rebalanceIntent: PublicKey): Promise<RebalanceIntent>;
|
|
4
5
|
export interface RebalanceIntentFilter {
|
|
5
6
|
filterType: "basket" | "owner";
|
|
@@ -9,17 +9,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.decodeRebalanceIntent = decodeRebalanceIntent;
|
|
12
13
|
exports.fetchRebalanceIntent = fetchRebalanceIntent;
|
|
13
14
|
exports.fetchRebalanceIntents = fetchRebalanceIntents;
|
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
16
|
const rebalanceIntent_1 = require("../../layouts/intents/rebalanceIntent");
|
|
15
17
|
const constants_1 = require("../../constants");
|
|
18
|
+
function decodeRebalanceIntent(dataWithoutDiscriminator, ownAddress) {
|
|
19
|
+
let rebalanceIntent = rebalanceIntent_1.RebalanceIntentLayout.decode(dataWithoutDiscriminator);
|
|
20
|
+
let numTokens = constants_1.MAX_SUPPORTED_TOKENS_PER_BASKET - 1;
|
|
21
|
+
while (rebalanceIntent.tokens[numTokens].mint.equals(web3_js_1.PublicKey.default))
|
|
22
|
+
numTokens--;
|
|
23
|
+
rebalanceIntent.tokens = rebalanceIntent.tokens.slice(0, numTokens + 1);
|
|
24
|
+
rebalanceIntent.priceUpdateTasks = rebalanceIntent.priceUpdateTasks.slice(0, numTokens + 1);
|
|
25
|
+
rebalanceIntent.tokenSettlementTasks = rebalanceIntent.tokenSettlementTasks.slice(0, numTokens + 1);
|
|
26
|
+
return Object.assign(Object.assign({}, rebalanceIntent), { ownAddress: ownAddress });
|
|
27
|
+
}
|
|
16
28
|
function fetchRebalanceIntent(connection, rebalanceIntent) {
|
|
17
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
30
|
const rebalanceIntentAi = yield connection.getAccountInfo(rebalanceIntent);
|
|
19
31
|
if (!rebalanceIntentAi) {
|
|
20
32
|
throw new Error("Rebalance intent not found");
|
|
21
33
|
}
|
|
22
|
-
return
|
|
34
|
+
return decodeRebalanceIntent(rebalanceIntentAi.data.slice(8), rebalanceIntent);
|
|
23
35
|
});
|
|
24
36
|
}
|
|
25
37
|
function fetchRebalanceIntents(connection, filters) {
|
|
@@ -48,7 +60,7 @@ function fetchRebalanceIntents(connection, filters) {
|
|
|
48
60
|
filters: accountFilters,
|
|
49
61
|
encoding: 'base64'
|
|
50
62
|
});
|
|
51
|
-
const rebalanceIntents = accounts.map(account =>
|
|
63
|
+
const rebalanceIntents = accounts.map(account => decodeRebalanceIntent(account.account.data.slice(8), account.pubkey));
|
|
52
64
|
return rebalanceIntents;
|
|
53
65
|
});
|
|
54
66
|
}
|
|
@@ -28,10 +28,10 @@ export declare class OraclePrice {
|
|
|
28
28
|
price: Decimal;
|
|
29
29
|
conf: Decimal;
|
|
30
30
|
updateTime: BN;
|
|
31
|
-
mid: Decimal;
|
|
32
|
-
low: Decimal;
|
|
33
|
-
high: Decimal;
|
|
34
31
|
constructor(price: Decimal, conf: Decimal, updateTime: BN);
|
|
32
|
+
getMid(): Decimal;
|
|
33
|
+
getLow(): Decimal;
|
|
34
|
+
getHigh(): Decimal;
|
|
35
35
|
}
|
|
36
36
|
export declare class OracleResult {
|
|
37
37
|
price: OraclePrice | null;
|
|
@@ -53,9 +53,6 @@ class OraclePrice {
|
|
|
53
53
|
this.price = new decimal_js_1.default(price);
|
|
54
54
|
this.conf = new decimal_js_1.default(conf);
|
|
55
55
|
this.updateTime = updateTime;
|
|
56
|
-
this.mid = this.price;
|
|
57
|
-
this.low = this.price.sub(this.conf);
|
|
58
|
-
this.high = this.price.add(this.conf);
|
|
59
56
|
let zero_Decimal = new decimal_js_1.default(0);
|
|
60
57
|
if (this.price.lte(zero_Decimal))
|
|
61
58
|
throw new Error("price should be more than 0");
|
|
@@ -64,6 +61,15 @@ class OraclePrice {
|
|
|
64
61
|
if (this.updateTime.lte(0))
|
|
65
62
|
throw new Error("update time should be more than 0");
|
|
66
63
|
}
|
|
64
|
+
getMid() {
|
|
65
|
+
return this.price;
|
|
66
|
+
}
|
|
67
|
+
getLow() {
|
|
68
|
+
return this.price.sub(this.conf);
|
|
69
|
+
}
|
|
70
|
+
getHigh() {
|
|
71
|
+
return this.price.add(this.conf);
|
|
72
|
+
}
|
|
67
73
|
}
|
|
68
74
|
exports.OraclePrice = OraclePrice;
|
|
69
75
|
class OracleResult {
|
|
@@ -133,7 +139,7 @@ class OracleAggregator {
|
|
|
133
139
|
for (let i = 0; i < this.oracles.length; i++) {
|
|
134
140
|
try {
|
|
135
141
|
let result = yield this.oracles[i].fetch();
|
|
136
|
-
if (result.ok()) {
|
|
142
|
+
if (result.ok() && result.price !== null) {
|
|
137
143
|
prices.push(result.price);
|
|
138
144
|
weights.push(new decimal_js_1.default(this.oracles[i].weight));
|
|
139
145
|
}
|
|
@@ -154,7 +160,7 @@ class OracleAggregator {
|
|
|
154
160
|
let frac3 = new decimal_js_1.default(3);
|
|
155
161
|
prices.map((price, i) => {
|
|
156
162
|
var _a, _b, _c;
|
|
157
|
-
allPrices.push((_a = price === null || price === void 0 ? void 0 : price.
|
|
163
|
+
allPrices.push((_a = price === null || price === void 0 ? void 0 : price.getMid()) !== null && _a !== void 0 ? _a : null, (_b = price === null || price === void 0 ? void 0 : price.getLow()) !== null && _b !== void 0 ? _b : null, (_c = price === null || price === void 0 ? void 0 : price.getHigh()) !== null && _c !== void 0 ? _c : null);
|
|
158
164
|
let w = weights[i].div(frac3);
|
|
159
165
|
allWeights.push(w, w, w);
|
|
160
166
|
});
|
|
@@ -2,14 +2,16 @@ import Decimal from 'decimal.js';
|
|
|
2
2
|
import { BN } from '@coral-xyz/anchor';
|
|
3
3
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { Oracle, OracleResult } from './oracle';
|
|
5
|
-
declare enum Side {
|
|
5
|
+
export declare enum Side {
|
|
6
6
|
Base = 0,
|
|
7
7
|
Quote = 1
|
|
8
8
|
}
|
|
9
|
-
declare
|
|
9
|
+
export declare const SideLayout: any;
|
|
10
|
+
export declare enum Quote {
|
|
10
11
|
Usdc = 0,
|
|
11
12
|
Wsol = 1
|
|
12
13
|
}
|
|
14
|
+
export declare const QuoteLayout: any;
|
|
13
15
|
declare class Observation {
|
|
14
16
|
timestamp: BN;
|
|
15
17
|
cumT0Price: BN;
|
|
@@ -12,23 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.RaydiumCPMMOracle = void 0;
|
|
15
|
+
exports.RaydiumCPMMOracle = exports.QuoteLayout = exports.Quote = exports.SideLayout = exports.Side = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const oracle_1 = require("./oracle");
|
|
20
|
+
const borsh_1 = require("@coral-xyz/borsh");
|
|
20
21
|
const CPMM_PROGRAM_ID = new web3_js_1.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C");
|
|
21
22
|
const DEV_CPMM_PROGRAM_ID = new web3_js_1.PublicKey("DRaycpLY18LhpbydsBWbVJtxpNv9oXPgjRSfpF2bWpYb");
|
|
22
23
|
var Side;
|
|
23
24
|
(function (Side) {
|
|
24
25
|
Side[Side["Base"] = 0] = "Base";
|
|
25
26
|
Side[Side["Quote"] = 1] = "Quote";
|
|
26
|
-
})(Side || (Side = {}));
|
|
27
|
+
})(Side || (exports.Side = Side = {}));
|
|
28
|
+
exports.SideLayout = (0, borsh_1.struct)([
|
|
29
|
+
(0, borsh_1.u8)('side'),
|
|
30
|
+
]);
|
|
27
31
|
var Quote;
|
|
28
32
|
(function (Quote) {
|
|
29
33
|
Quote[Quote["Usdc"] = 0] = "Usdc";
|
|
30
34
|
Quote[Quote["Wsol"] = 1] = "Wsol";
|
|
31
|
-
})(Quote || (Quote = {}));
|
|
35
|
+
})(Quote || (exports.Quote = Quote = {}));
|
|
36
|
+
exports.QuoteLayout = (0, borsh_1.struct)([
|
|
37
|
+
(0, borsh_1.u8)('quote'),
|
|
38
|
+
]);
|
|
32
39
|
class Observation {
|
|
33
40
|
constructor(params) {
|
|
34
41
|
this.timestamp = params.timestamp;
|
package/dist/test.js
CHANGED
|
@@ -15,25 +15,38 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
15
15
|
let connection = new web3_js_1.Connection("https://api.devnet.solana.com");
|
|
16
16
|
function testStates() {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
let sdk = new src_1.
|
|
18
|
+
let sdk = new src_1.SymmetryCore({
|
|
19
19
|
connection: connection,
|
|
20
20
|
});
|
|
21
21
|
console.log("SDK created");
|
|
22
22
|
let x = yield sdk.createBasketTx({
|
|
23
23
|
creator: web3_js_1.PublicKey.default,
|
|
24
24
|
host: web3_js_1.PublicKey.default,
|
|
25
|
-
startPrice: {
|
|
25
|
+
startPrice: { high: new anchor_1.BN(0), low: new anchor_1.BN(Math.floor((1 << 64) / 10)) },
|
|
26
26
|
hostFees: { hostDepositFeeBps: 0, hostManagementFeeBps: 0, hostPerformanceFeeBps: 0 },
|
|
27
27
|
metadataParams: { name: "Test Basket", symbol: "TB", uri: "https://test.com" },
|
|
28
28
|
metadataModificationDelay: new anchor_1.BN(0),
|
|
29
29
|
});
|
|
30
30
|
console.log(x);
|
|
31
|
-
let baskets = yield sdk.fetchAllBaskets();
|
|
31
|
+
let baskets = yield sdk.fetchAllBaskets([]);
|
|
32
32
|
console.log(baskets.map(basket => basket.ownAddress.toBase58()));
|
|
33
|
-
let intents = yield sdk.fetchAllIntents();
|
|
33
|
+
let intents = yield sdk.fetchAllIntents([]);
|
|
34
34
|
console.log(intents.map(intent => intent.manager.toBase58()));
|
|
35
|
-
let rebalanceIntents = yield sdk.fetchAllRebalanceIntents();
|
|
36
|
-
console.log(rebalanceIntents.map(rebalanceIntent =>
|
|
35
|
+
let rebalanceIntents = yield sdk.fetchAllRebalanceIntents([]);
|
|
36
|
+
console.log(rebalanceIntents.map(rebalanceIntent => {
|
|
37
|
+
var _a;
|
|
38
|
+
return {
|
|
39
|
+
owner: rebalanceIntent.owner.toBase58(),
|
|
40
|
+
basket: rebalanceIntent.basket.toBase58(),
|
|
41
|
+
ownAddress: (_a = rebalanceIntent.ownAddress) === null || _a === void 0 ? void 0 : _a.toBase58(),
|
|
42
|
+
};
|
|
43
|
+
}));
|
|
44
|
+
rebalanceIntents.forEach(rebalanceIntent => {
|
|
45
|
+
console.log("--------------------------------");
|
|
46
|
+
console.log(rebalanceIntent.tokens[0].price, rebalanceIntent.tokens[0].price);
|
|
47
|
+
});
|
|
48
|
+
// console.log(baskets[0]);
|
|
49
|
+
// console.log(baskets[0].composition[0].oracleAggregator.oracles[0].oracleSettings);
|
|
37
50
|
});
|
|
38
51
|
}
|
|
39
52
|
testStates();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,9 +14,9 @@ import { Basket } from './layouts/basket';
|
|
|
14
14
|
import { Fraction } from './layouts/fraction';
|
|
15
15
|
import { EditData, HostFees, Intent, MetadataParams, TaskType } from './layouts/intents/intent';
|
|
16
16
|
import { RebalanceIntent } from './layouts/intents/rebalanceIntent';
|
|
17
|
-
import { fetchBasket, fetchBaskets } from './states/basket';
|
|
18
|
-
import { fetchIntents } from './states/intents/intent';
|
|
19
|
-
import { fetchRebalanceIntents } from './states/intents/rebalanceIntent';
|
|
17
|
+
import { BasketFilter, fetchBasket, fetchBaskets } from './states/basket';
|
|
18
|
+
import { fetchIntents, IntentFilter } from './states/intents/intent';
|
|
19
|
+
import { fetchRebalanceIntents, RebalanceIntentFilter } from './states/intents/rebalanceIntent';
|
|
20
20
|
import { prepareV0Transactions, sendV0Transactions, signedVersionedTxs, VersionedTxs, Wallet } from './txUtils';
|
|
21
21
|
|
|
22
22
|
export const COMPUTE_UNITS = 1_000_000;
|
|
@@ -25,7 +25,7 @@ export const JUPITER_API_KEY = "https://quote-api.jup.ag/v6/";
|
|
|
25
25
|
export const MAX_JUPITER_ACCOUNTS = 35;
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
export class
|
|
28
|
+
export class SymmetryCore {
|
|
29
29
|
|
|
30
30
|
private sdkParams: {
|
|
31
31
|
payer: PublicKey,
|
|
@@ -62,18 +62,24 @@ export class BasketsSdk {
|
|
|
62
62
|
return basketState;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
async fetchAllBaskets(
|
|
66
|
-
|
|
65
|
+
async fetchAllBaskets(
|
|
66
|
+
filters: BasketFilter[],
|
|
67
|
+
): Promise<Basket[]> {
|
|
68
|
+
const baskets = await fetchBaskets(this.sdkParams.connection, filters);
|
|
67
69
|
return baskets;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
async fetchAllIntents(
|
|
71
|
-
|
|
72
|
+
async fetchAllIntents(
|
|
73
|
+
filters: IntentFilter[],
|
|
74
|
+
): Promise<Intent[]> {
|
|
75
|
+
const intents = await fetchIntents(this.sdkParams.connection, filters);
|
|
72
76
|
return intents;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
async fetchAllRebalanceIntents(
|
|
76
|
-
|
|
79
|
+
async fetchAllRebalanceIntents(
|
|
80
|
+
filters: RebalanceIntentFilter[],
|
|
81
|
+
): Promise<RebalanceIntent[]> {
|
|
82
|
+
const rebalanceIntents = await fetchRebalanceIntents(this.sdkParams.connection, filters);
|
|
77
83
|
return rebalanceIntents;
|
|
78
84
|
}
|
|
79
85
|
|
|
@@ -258,3 +264,13 @@ export class BasketsSdk {
|
|
|
258
264
|
}
|
|
259
265
|
|
|
260
266
|
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
export {
|
|
270
|
+
Basket,
|
|
271
|
+
BasketFilter,
|
|
272
|
+
Intent,
|
|
273
|
+
IntentFilter,
|
|
274
|
+
RebalanceIntent,
|
|
275
|
+
RebalanceIntentFilter
|
|
276
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { getAta, getRebalanceIntentPda } from "../pda";
|
|
4
|
-
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";
|
|
5
4
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
6
5
|
import { BN } from "@coral-xyz/anchor";
|
|
7
6
|
import { BASKETS_V3_PROGRAM_ID } from "../../constants";
|
|
7
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -39,7 +39,7 @@ export function rebalanceSwapIx(
|
|
|
39
39
|
{ pubkey: keeperToATA, isWritable: true, isSigner: false },
|
|
40
40
|
{ pubkey: basketFromATA, isWritable: true, isSigner: false },
|
|
41
41
|
{ pubkey: basketToATA, isWritable: true, isSigner: false },
|
|
42
|
-
{ pubkey:
|
|
42
|
+
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
43
43
|
{ pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
44
44
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
45
45
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN } from '@coral-xyz/anchor';
|
|
2
|
-
import { SYSTEM_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/native/system';
|
|
3
2
|
import {
|
|
4
3
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
5
4
|
TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID
|
|
@@ -42,7 +41,7 @@ export function addBountyIx(params: {
|
|
|
42
41
|
{ pubkey: bountyVault, isSigner: false, isWritable: true },
|
|
43
42
|
{ pubkey: bountyVaultAta, isSigner: false, isWritable: true },
|
|
44
43
|
{ pubkey: globalConfig, isSigner: false, isWritable: false },
|
|
45
|
-
{ pubkey:
|
|
44
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
46
45
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
47
46
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
48
47
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN, Program } from '@coral-xyz/anchor';
|
|
2
|
-
import { SYSTEM_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/native/system';
|
|
3
2
|
import { array, publicKey, struct, u16, u64, u8 } from '@coral-xyz/borsh';
|
|
4
3
|
import {
|
|
5
4
|
PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction
|
|
@@ -27,7 +26,7 @@ export function createGlobalConfigIx(params: {
|
|
|
27
26
|
const keys = [
|
|
28
27
|
{ pubkey: admin, isSigner: true, isWritable: true },
|
|
29
28
|
{ pubkey: globalConfig, isSigner: false, isWritable: true },
|
|
30
|
-
{ pubkey:
|
|
29
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
31
30
|
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
|
|
32
31
|
];
|
|
33
32
|
|
|
@@ -108,8 +108,8 @@ export function createBasketIx(params: {
|
|
|
108
108
|
Buffer.from(seed),
|
|
109
109
|
Buffer.from(new BN(slot).toArray("le", 8)),
|
|
110
110
|
host.toBuffer(),
|
|
111
|
-
Buffer.from(startPrice.
|
|
112
|
-
Buffer.from(startPrice.
|
|
111
|
+
Buffer.from(startPrice.high.toArray("le", 8)),
|
|
112
|
+
Buffer.from(startPrice.low.toArray("le", 8)),
|
|
113
113
|
hostFeesBuffer,
|
|
114
114
|
serializeString(metadataParams.name),
|
|
115
115
|
serializeString(metadataParams.symbol),
|
|
@@ -4,9 +4,9 @@ import { TransactionInstruction } from "@solana/web3.js";
|
|
|
4
4
|
import { BASKETS_V3_PROGRAM_ID } from "../../constants";
|
|
5
5
|
import { getAta, getBountyVaultPda, getGlobalConfigPda, getIntentPda, getMetadataAccount, METADATA_PROGRAM_ID, serializeString } from "../pda";
|
|
6
6
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
7
|
-
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";
|
|
8
7
|
import { AutomationSettings, AutomationSettingsLayout, FeeSettings, FeeSettingsLayout, LpSettings, LpSettingsLayout, ManagerSettings, ManagerSettingsLayout, MetadataSettings, MetadataSettingsLayout, ScheduleSettings, ScheduleSettingsLayout } from "../../layouts/config";
|
|
9
8
|
import { BN } from "@coral-xyz/anchor";
|
|
9
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
10
10
|
|
|
11
11
|
const EDIT_PRIVATE_BASKET_SETTINGS_DISCRIMINATOR = Buffer.from([202,54,138,17,3,104,128,229]);
|
|
12
12
|
const CREATE_EDIT_BASKET_INTENT_DISCRIMINATOR = Buffer.from([82, 150, 58, 227, 153, 129, 20, 30]);
|
|
@@ -177,7 +177,7 @@ export function createEditBasketIntentIx(params: {
|
|
|
177
177
|
{ pubkey: managerBountyATA, isSigner: false, isWritable: true },
|
|
178
178
|
{ pubkey: bountyVault, isSigner: false, isWritable: true },
|
|
179
179
|
{ pubkey: bountyVaultATA, isSigner: false, isWritable: true },
|
|
180
|
-
{ pubkey:
|
|
180
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
181
181
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
182
182
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
183
183
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
@@ -230,7 +230,7 @@ export function editBasketIx(params: {
|
|
|
230
230
|
{ pubkey: managerBountyATA, isSigner: false, isWritable: true },
|
|
231
231
|
{ pubkey: bountyVault, isSigner: false, isWritable: true },
|
|
232
232
|
{ pubkey: bountyVaultATA, isSigner: false, isWritable: true },
|
|
233
|
-
{ pubkey:
|
|
233
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
234
234
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
235
235
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
236
236
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN, Program } from '@coral-xyz/anchor';
|
|
2
|
-
import { SYSTEM_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/native/system';
|
|
3
2
|
import { PublicKey, SystemProgram, TransactionInstruction } from '@solana/web3.js';
|
|
4
3
|
import { ADDRESS_LOOKUP_TABLE_PROGRAM_ID, BASKETS_V3_PROGRAM_ID } from '../../constants';
|
|
5
4
|
import { getLookupTableInfoAccount } from '../pda';
|
|
@@ -48,7 +47,7 @@ export function createBasketLookupTablesInstruction(params: {
|
|
|
48
47
|
{ pubkey: newTempLookupTableInfo0, isSigner: false, isWritable: true },
|
|
49
48
|
{ pubkey: newTempLookupTableInfo1, isSigner: false, isWritable: true },
|
|
50
49
|
{ pubkey: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
51
|
-
{ pubkey:
|
|
50
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
52
51
|
];
|
|
53
52
|
|
|
54
53
|
return new TransactionInstruction({
|
|
@@ -72,7 +71,7 @@ export function extendBasketLookupTablesIx(
|
|
|
72
71
|
{ pubkey: params.tempLookupTable0, isWritable: true, isSigner: false },
|
|
73
72
|
{ pubkey: params.tempLookupTable1, isWritable: true, isSigner: false },
|
|
74
73
|
{ pubkey: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
75
|
-
{ pubkey:
|
|
74
|
+
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
76
75
|
];
|
|
77
76
|
|
|
78
77
|
return new TransactionInstruction({
|
|
@@ -100,7 +99,7 @@ export function overwriteBasketLookupTablesIx(
|
|
|
100
99
|
{ pubkey: params.tempLookupTable1, isWritable: true, isSigner: false },
|
|
101
100
|
{ pubkey: params.activeLookupTable0, isWritable: true, isSigner: false },
|
|
102
101
|
{ pubkey: params.activeLookupTable1, isWritable: true, isSigner: false },
|
|
103
|
-
{ pubkey:
|
|
102
|
+
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
104
103
|
];
|
|
105
104
|
|
|
106
105
|
return new TransactionInstruction({
|
|
@@ -123,7 +122,7 @@ export function closeDeactivatedLookupTableIx(params: {
|
|
|
123
122
|
{ pubkey: params.lookupTable, isWritable: true, isSigner: false },
|
|
124
123
|
{ pubkey: lookupTableInfo, isWritable: true, isSigner: false },
|
|
125
124
|
{ pubkey: ADDRESS_LOOKUP_TABLE_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
126
|
-
{ pubkey:
|
|
125
|
+
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
127
126
|
];
|
|
128
127
|
|
|
129
128
|
return new TransactionInstruction({
|
|
@@ -3,8 +3,8 @@ import { BN } from "@coral-xyz/anchor";
|
|
|
3
3
|
import { BASKETS_V3_PROGRAM_ID } from "../../constants";
|
|
4
4
|
import { getAta, getBasketFeesPda, getBasketTokenMintPda, getBountyVaultPda, getGlobalConfigPda, getRebalanceIntentPda, getRentPayerPda } from "../pda";
|
|
5
5
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
6
|
-
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";
|
|
7
6
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
7
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
8
8
|
|
|
9
9
|
const CREATE_USER_REBALANCE_INTENT_ACCOUNT = Buffer.from([212, 23, 1, 46, 192, 87, 74, 196]);
|
|
10
10
|
const RESIZE_REBALANCE_INTENT_HANDLER = Buffer.from([71, 204, 243, 183, 209, 118, 111, 94]);
|
|
@@ -33,7 +33,7 @@ export function createUserRebalanceIntentIx(params: {
|
|
|
33
33
|
{ pubkey: globalConfig, isSigner: false, isWritable: true},
|
|
34
34
|
{ pubkey: SYSVAR_INSTRUCTIONS_PUBKEY, isSigner: false, isWritable: false},
|
|
35
35
|
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
|
|
36
|
-
{ pubkey:
|
|
36
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false}
|
|
37
37
|
];
|
|
38
38
|
|
|
39
39
|
const data = CREATE_USER_REBALANCE_INTENT_ACCOUNT;
|
|
@@ -112,7 +112,7 @@ export function depositStateIx(
|
|
|
112
112
|
{ pubkey: buyerBountyAta, isSigner: false, isWritable: true },
|
|
113
113
|
{ pubkey: bountyVault, isSigner: false, isWritable: true },
|
|
114
114
|
{ pubkey: bountyVaultAta, isSigner: false, isWritable: true },
|
|
115
|
-
{ pubkey:
|
|
115
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
116
116
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
117
117
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
118
118
|
// { pubkey: rebalanceIntent, isSigner: false, isWritable: true } // remaining accounts
|
|
@@ -149,7 +149,7 @@ export function depositTokensIx(params: {
|
|
|
149
149
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
150
150
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
151
151
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
152
|
-
{ pubkey:
|
|
152
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
153
153
|
];
|
|
154
154
|
|
|
155
155
|
// remaining accounts
|
|
@@ -223,7 +223,7 @@ export function mintBasketIx(params: {
|
|
|
223
223
|
{ pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
224
224
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
225
225
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
226
|
-
{ pubkey:
|
|
226
|
+
{ pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
|
|
227
227
|
];
|
|
228
228
|
|
|
229
229
|
return new TransactionInstruction({
|
|
@@ -3,8 +3,8 @@ import { BASKETS_V3_PROGRAM_ID } from "../../constants";
|
|
|
3
3
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
4
4
|
import { BN } from "@coral-xyz/anchor";
|
|
5
5
|
import { getAta, getBasketTokenMintPda, getBountyVaultPda, getGlobalConfigPda, getRebalanceIntentPda, getRentPayerPda } from "../pda";
|
|
6
|
-
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";
|
|
7
6
|
import { TransactionInstruction } from "@solana/web3.js";
|
|
7
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
const CREATE_WITHDRAW_STATE_DISCRIMINATOR = Buffer.from([161, 45, 253, 59, 110, 240, 65, 3]);
|
|
@@ -61,7 +61,7 @@ export function createWithdrawStateIx(params: {
|
|
|
61
61
|
{ pubkey: sellerBountyAta, isSigner: false, isWritable: true },
|
|
62
62
|
{ pubkey: bountyVault, isSigner: false, isWritable: true },
|
|
63
63
|
{ pubkey: bountyVaultAta, isSigner: false, isWritable: true },
|
|
64
|
-
{ pubkey:
|
|
64
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
65
65
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
66
66
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
67
67
|
{ pubkey: rebalanceIntent, isSigner: false, isWritable: false } // remaining accounts
|
|
@@ -100,7 +100,7 @@ export function redeemTokensIx(
|
|
|
100
100
|
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
101
101
|
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
102
102
|
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
103
|
-
{ pubkey:
|
|
103
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
104
104
|
];
|
|
105
105
|
|
|
106
106
|
// remaining accounts
|
package/src/layouts/basket.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
import { BN } from
|
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
import { array, publicKey, str, struct, u128, u16, u64, u8 } from '@coral-xyz/borsh';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { BasketSettings, BasketSettingsLayout } from
|
|
4
|
+
import { PublicKey } from '@solana/web3.js';
|
|
5
|
+
|
|
6
|
+
import { BasketSettings, BasketSettingsLayout } from './config';
|
|
7
|
+
import { Fraction, FractionLayout } from './fraction';
|
|
8
|
+
import { OracleAggregator, OracleAggregatorLayout } from './oracle';
|
|
8
9
|
|
|
9
10
|
export const MAX_SUPPORTED_TOKENS_PER_BASKET: number = 100;
|
|
10
11
|
|
|
@@ -46,6 +47,12 @@ export const AssetLayout = struct<Asset>([
|
|
|
46
47
|
OracleAggregatorLayout.replicate('oracleAggregator'),
|
|
47
48
|
]);
|
|
48
49
|
|
|
50
|
+
export interface Metadata {
|
|
51
|
+
symbol: string,
|
|
52
|
+
name: string,
|
|
53
|
+
uri: string
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
export interface Basket {
|
|
50
57
|
version: number; // u8
|
|
51
58
|
seedArray: number[]; // length 16
|
|
@@ -63,6 +70,7 @@ export interface Basket {
|
|
|
63
70
|
writeVersion: BN; // u64
|
|
64
71
|
numTokens: number; // u8
|
|
65
72
|
composition: Asset[]; // length MAX_SUPPORTED_TOKENS_PER_BASKET
|
|
73
|
+
metadata?: Metadata
|
|
66
74
|
};
|
|
67
75
|
|
|
68
76
|
export const BasketLayout = struct<Basket>([
|
package/src/layouts/config.ts
CHANGED
|
@@ -14,10 +14,6 @@ export enum BasketType {
|
|
|
14
14
|
Public = 1,
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export const BasketTypeLayout = struct<BasketType>([
|
|
18
|
-
u8('basketType'),
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
17
|
export interface ScheduleSettings {
|
|
22
18
|
cycleDuration: BN; // u64
|
|
23
19
|
depositsStart: BN; // u64
|
|
@@ -56,6 +52,7 @@ export interface FeeSettings {
|
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
export const FeeSettingsLayout = struct<FeeSettings>([
|
|
55
|
+
u64('modificationDelay'),
|
|
59
56
|
u16('hostDepositFeeBps'),
|
|
60
57
|
u16('hostManagementFeeBps'),
|
|
61
58
|
u16('hostPerformanceFeeBps'),
|
|
@@ -67,7 +64,6 @@ export const FeeSettingsLayout = struct<FeeSettings>([
|
|
|
67
64
|
u16('managersPerformanceFeeBps'),
|
|
68
65
|
u16('basketDepositFeeBps'),
|
|
69
66
|
u16('basketWithdrawFeeBps'),
|
|
70
|
-
u64('modificationDelay'),
|
|
71
67
|
]);
|
|
72
68
|
|
|
73
69
|
export interface ManagerSettings {
|
|
@@ -175,7 +171,7 @@ export const BasketSettingsLayout = struct<BasketSettings>([
|
|
|
175
171
|
publicKey('creator'),
|
|
176
172
|
publicKey('host'),
|
|
177
173
|
|
|
178
|
-
|
|
174
|
+
u8('basketType'),
|
|
179
175
|
FractionLayout.replicate('startPrice'),
|
|
180
176
|
|
|
181
177
|
u64('activeRebalance'),
|