@symmetry-hq/sdk 1.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/src/constants.d.ts +23 -0
- package/dist/src/constants.js +38 -0
- package/dist/src/index.d.ts +804 -0
- package/dist/src/index.js +2097 -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/flashSwap.d.ts +21 -0
- package/dist/src/instructions/automation/flashSwap.js +74 -0
- package/dist/src/instructions/automation/priceUpdate.d.ts +19 -0
- package/dist/src/instructions/automation/priceUpdate.js +89 -0
- package/dist/src/instructions/automation/rebalanceIntent.d.ts +32 -0
- package/dist/src/instructions/automation/rebalanceIntent.js +117 -0
- package/dist/src/instructions/automation/rebalanceSwap.d.ts +11 -0
- package/dist/src/instructions/automation/rebalanceSwap.js +42 -0
- package/dist/src/instructions/management/addBounty.d.ts +7 -0
- package/dist/src/instructions/management/addBounty.js +41 -0
- package/dist/src/instructions/management/admin.d.ts +9 -0
- package/dist/src/instructions/management/admin.js +53 -0
- package/dist/src/instructions/management/claimFees.d.ts +15 -0
- package/dist/src/instructions/management/claimFees.js +95 -0
- package/dist/src/instructions/management/createBasket.d.ts +21 -0
- package/dist/src/instructions/management/createBasket.js +98 -0
- package/dist/src/instructions/management/edit.d.ts +51 -0
- package/dist/src/instructions/management/edit.js +477 -0
- package/dist/src/instructions/management/luts.d.ts +30 -0
- package/dist/src/instructions/management/luts.js +99 -0
- package/dist/src/instructions/pda.d.ts +25 -0
- package/dist/src/instructions/pda.js +128 -0
- package/dist/src/instructions/user/deposit.d.ts +20 -0
- package/dist/src/instructions/user/deposit.js +100 -0
- package/dist/src/instructions/user/withdraw.d.ts +8 -0
- package/dist/src/instructions/user/withdraw.js +36 -0
- package/dist/src/jup.d.ts +49 -0
- package/dist/src/jup.js +80 -0
- package/dist/src/keeperMonitor.d.ts +52 -0
- package/dist/src/keeperMonitor.js +624 -0
- package/dist/src/layouts/basket.d.ts +191 -0
- package/dist/src/layouts/basket.js +51 -0
- package/dist/src/layouts/config.d.ts +281 -0
- package/dist/src/layouts/config.js +237 -0
- package/dist/src/layouts/fraction.d.ts +20 -0
- package/dist/src/layouts/fraction.js +164 -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 +209 -0
- package/dist/src/layouts/intents/intent.js +97 -0
- package/dist/src/layouts/intents/rebalanceIntent.d.ts +212 -0
- package/dist/src/layouts/intents/rebalanceIntent.js +94 -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 +63 -0
- package/dist/src/layouts/oracle.js +96 -0
- package/dist/src/states/basket.d.ts +14 -0
- package/dist/src/states/basket.js +479 -0
- package/dist/src/states/config.d.ts +3 -0
- package/dist/src/states/config.js +71 -0
- package/dist/src/states/intents/intent.d.ts +10 -0
- package/dist/src/states/intents/intent.js +316 -0
- package/dist/src/states/intents/rebalanceIntent.d.ts +42 -0
- package/dist/src/states/intents/rebalanceIntent.js +680 -0
- package/dist/src/states/oracles/constants.d.ts +9 -0
- package/dist/src/states/oracles/constants.js +15 -0
- package/dist/src/states/oracles/oracle.d.ts +24 -0
- package/dist/src/states/oracles/oracle.js +168 -0
- package/dist/src/states/oracles/pythOracle.d.ts +132 -0
- package/dist/src/states/oracles/pythOracle.js +609 -0
- package/dist/src/states/oracles/raydiumClmmOracle.d.ts +184 -0
- package/dist/src/states/oracles/raydiumClmmOracle.js +843 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.d.ts +120 -0
- package/dist/src/states/oracles/raydiumCpmmOracle.js +540 -0
- package/dist/src/states/oracles/switchboardOracle.d.ts +0 -0
- package/dist/src/states/oracles/switchboardOracle.js +1 -0
- package/dist/src/states/withdrawBasketFees.d.ts +10 -0
- package/dist/src/states/withdrawBasketFees.js +154 -0
- package/dist/src/txUtils.d.ts +65 -0
- package/dist/src/txUtils.js +306 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +561 -0
- package/package.json +31 -0
- package/src/constants.ts +40 -0
- package/src/index.ts +2431 -0
- package/src/instructions/automation/auction.ts +55 -0
- package/src/instructions/automation/claimBounty.ts +69 -0
- package/src/instructions/automation/flashSwap.ts +104 -0
- package/src/instructions/automation/priceUpdate.ts +117 -0
- package/src/instructions/automation/rebalanceIntent.ts +181 -0
- package/src/instructions/management/addBounty.ts +55 -0
- package/src/instructions/management/admin.ts +72 -0
- package/src/instructions/management/claimFees.ts +129 -0
- package/src/instructions/management/createBasket.ts +138 -0
- package/src/instructions/management/edit.ts +602 -0
- package/src/instructions/management/luts.ts +157 -0
- package/src/instructions/pda.ts +151 -0
- package/src/instructions/user/deposit.ts +143 -0
- package/src/instructions/user/withdraw.ts +53 -0
- package/src/jup.ts +113 -0
- package/src/keeperMonitor.ts +585 -0
- package/src/layouts/basket.ts +233 -0
- package/src/layouts/config.ts +576 -0
- package/src/layouts/fraction.ts +164 -0
- package/src/layouts/intents/bounty.ts +35 -0
- package/src/layouts/intents/intent.ts +324 -0
- package/src/layouts/intents/rebalanceIntent.ts +306 -0
- package/src/layouts/lookupTable.ts +14 -0
- package/src/layouts/oracle.ts +157 -0
- package/src/states/basket.ts +527 -0
- package/src/states/config.ts +62 -0
- package/src/states/intents/intent.ts +311 -0
- package/src/states/intents/rebalanceIntent.ts +751 -0
- package/src/states/oracles/constants.ts +13 -0
- package/src/states/oracles/oracle.ts +212 -0
- package/src/states/oracles/pythOracle.ts +874 -0
- package/src/states/oracles/raydiumClmmOracle.ts +1193 -0
- package/src/states/oracles/raydiumCpmmOracle.ts +784 -0
- package/src/states/oracles/switchboardOracle.ts +0 -0
- package/src/states/withdrawBasketFees.ts +160 -0
- package/src/txUtils.ts +424 -0
- package/test.ts +609 -0
- package/tsconfig.json +101 -0
|
@@ -0,0 +1,128 @@
|
|
|
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.TOKEN_METADATA_PROGRAM_ID = exports.REBALANCE_INTENT_SEED = exports.BOUNTY_VAULT_SEED = exports.RENT_PAYER_SEED = exports.MINT_SEED = exports.BASKET_SEED = exports.WITHDRAW_BASKET_FEES_SEED = exports.BASKET_FEES_SEED = exports.GLOBAL_CONFIG_SEED = void 0;
|
|
7
|
+
exports.serializeString = serializeString;
|
|
8
|
+
exports.getRandomSeed = getRandomSeed;
|
|
9
|
+
exports.getBasketTokenMintPda = getBasketTokenMintPda;
|
|
10
|
+
exports.getBasketState = getBasketState;
|
|
11
|
+
exports.getBountyVaultPda = getBountyVaultPda;
|
|
12
|
+
exports.getBasketFeesPda = getBasketFeesPda;
|
|
13
|
+
exports.getWithdrawBasketFeesPda = getWithdrawBasketFeesPda;
|
|
14
|
+
exports.getGlobalConfigPda = getGlobalConfigPda;
|
|
15
|
+
exports.getRentPayerPda = getRentPayerPda;
|
|
16
|
+
exports.getIntentPda = getIntentPda;
|
|
17
|
+
exports.getRebalanceIntentPda = getRebalanceIntentPda;
|
|
18
|
+
exports.getMetadataAccount = getMetadataAccount;
|
|
19
|
+
exports.getLookupTableAccount = getLookupTableAccount;
|
|
20
|
+
exports.getLookupTableInfoAccount = getLookupTableInfoAccount;
|
|
21
|
+
exports.getAta = getAta;
|
|
22
|
+
const crypto_1 = require("crypto");
|
|
23
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
24
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
25
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
26
|
+
const constants_1 = require("../constants");
|
|
27
|
+
exports.GLOBAL_CONFIG_SEED = Buffer.from("global_config");
|
|
28
|
+
exports.BASKET_FEES_SEED = Buffer.from("basket_fees");
|
|
29
|
+
exports.WITHDRAW_BASKET_FEES_SEED = Buffer.from("withdraw_basket_fees");
|
|
30
|
+
exports.BASKET_SEED = Buffer.from("basket");
|
|
31
|
+
exports.MINT_SEED = Buffer.from("mint");
|
|
32
|
+
exports.RENT_PAYER_SEED = Buffer.from("rent_payer");
|
|
33
|
+
exports.BOUNTY_VAULT_SEED = Buffer.from("bounty_vault");
|
|
34
|
+
exports.REBALANCE_INTENT_SEED = Buffer.from("rebalance_intent");
|
|
35
|
+
exports.TOKEN_METADATA_PROGRAM_ID = new web3_js_1.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s");
|
|
36
|
+
function serializeString(input) {
|
|
37
|
+
const utf8 = new TextEncoder().encode(input);
|
|
38
|
+
const length = utf8.length;
|
|
39
|
+
const out = new Uint8Array(4 + length);
|
|
40
|
+
// encode length as little-endian u32
|
|
41
|
+
out[0] = length & 0xff;
|
|
42
|
+
out[1] = (length >> 8) & 0xff;
|
|
43
|
+
out[2] = (length >> 16) & 0xff;
|
|
44
|
+
out[3] = (length >> 24) & 0xff;
|
|
45
|
+
// copy utf8 bytes after the 4-byte length
|
|
46
|
+
out.set(utf8, 4);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function getRandomSeed() {
|
|
50
|
+
return Array.from((0, crypto_1.randomBytes)(16));
|
|
51
|
+
}
|
|
52
|
+
function getBasketTokenMintPda(basketId) {
|
|
53
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
54
|
+
exports.MINT_SEED,
|
|
55
|
+
new bn_js_1.default(basketId).toArrayLike(Buffer, "le", 8)
|
|
56
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
57
|
+
}
|
|
58
|
+
function getBasketState(mint) {
|
|
59
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
60
|
+
exports.BASKET_SEED,
|
|
61
|
+
mint.toBuffer()
|
|
62
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
63
|
+
}
|
|
64
|
+
function getBountyVaultPda() {
|
|
65
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
66
|
+
exports.BOUNTY_VAULT_SEED,
|
|
67
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
68
|
+
}
|
|
69
|
+
function getBasketFeesPda(basket) {
|
|
70
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
71
|
+
exports.BASKET_FEES_SEED,
|
|
72
|
+
basket.toBuffer()
|
|
73
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
74
|
+
}
|
|
75
|
+
function getWithdrawBasketFeesPda(basket, feeType) {
|
|
76
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
77
|
+
exports.WITHDRAW_BASKET_FEES_SEED,
|
|
78
|
+
basket.toBuffer(),
|
|
79
|
+
Buffer.from([feeType]) // u8, not u64
|
|
80
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
81
|
+
}
|
|
82
|
+
function getGlobalConfigPda() {
|
|
83
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
84
|
+
exports.GLOBAL_CONFIG_SEED
|
|
85
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
86
|
+
}
|
|
87
|
+
function getRentPayerPda() {
|
|
88
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
89
|
+
exports.RENT_PAYER_SEED
|
|
90
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
91
|
+
}
|
|
92
|
+
function getIntentPda(basket, intentSeedArray, editType) {
|
|
93
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
94
|
+
basket.toBuffer(),
|
|
95
|
+
intentSeedArray,
|
|
96
|
+
Uint8Array.from([editType]),
|
|
97
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
98
|
+
}
|
|
99
|
+
function getRebalanceIntentPda(basket, owner) {
|
|
100
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
101
|
+
exports.REBALANCE_INTENT_SEED,
|
|
102
|
+
basket.toBuffer(),
|
|
103
|
+
owner.toBuffer(),
|
|
104
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
105
|
+
}
|
|
106
|
+
function getMetadataAccount(tokenMint) {
|
|
107
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
108
|
+
Buffer.from("metadata"),
|
|
109
|
+
exports.TOKEN_METADATA_PROGRAM_ID.toBuffer(),
|
|
110
|
+
tokenMint.toBuffer(),
|
|
111
|
+
], exports.TOKEN_METADATA_PROGRAM_ID)[0];
|
|
112
|
+
}
|
|
113
|
+
function getLookupTableAccount(creator, slot) {
|
|
114
|
+
const ixAndPubkey = web3_js_1.AddressLookupTableProgram.createLookupTable({
|
|
115
|
+
authority: creator,
|
|
116
|
+
recentSlot: slot,
|
|
117
|
+
payer: creator,
|
|
118
|
+
});
|
|
119
|
+
return ixAndPubkey[1];
|
|
120
|
+
}
|
|
121
|
+
function getLookupTableInfoAccount(lookupTable) {
|
|
122
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
123
|
+
lookupTable.toBuffer()
|
|
124
|
+
], constants_1.BASKETS_V3_PROGRAM_ID)[0];
|
|
125
|
+
}
|
|
126
|
+
function getAta(wallet, tokenMint, tokenProgram) {
|
|
127
|
+
return (0, spl_token_1.getAssociatedTokenAddressSync)(tokenMint, wallet, true, tokenProgram);
|
|
128
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
export declare function depositTokensIx(params: {
|
|
3
|
+
owner: PublicKey;
|
|
4
|
+
basket: PublicKey;
|
|
5
|
+
contributions: {
|
|
6
|
+
mint: PublicKey;
|
|
7
|
+
amount: number;
|
|
8
|
+
}[];
|
|
9
|
+
}): TransactionInstruction[];
|
|
10
|
+
export declare function lockDepositsIx(params: {
|
|
11
|
+
owner: PublicKey;
|
|
12
|
+
basket: PublicKey;
|
|
13
|
+
}): TransactionInstruction;
|
|
14
|
+
export declare function mintBasketIx(params: {
|
|
15
|
+
keeper: PublicKey;
|
|
16
|
+
basket: PublicKey;
|
|
17
|
+
basketTokenMint: PublicKey;
|
|
18
|
+
buyer: PublicKey;
|
|
19
|
+
basketRebalanceIntent?: PublicKey;
|
|
20
|
+
}): TransactionInstruction;
|
|
@@ -0,0 +1,100 @@
|
|
|
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.depositTokensIx = depositTokensIx;
|
|
7
|
+
exports.lockDepositsIx = lockDepositsIx;
|
|
8
|
+
exports.mintBasketIx = mintBasketIx;
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
11
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
12
|
+
const constants_1 = require("../../constants");
|
|
13
|
+
const pda_1 = require("../pda");
|
|
14
|
+
const DEPOSIT_TOKENS_DISCRIMINATOR = Buffer.from([88, 92, 158, 219, 83, 71, 239, 164]);
|
|
15
|
+
const LOCK_DEPOSITS_DISCRIMINATOR = Buffer.from([64, 238, 171, 198, 135, 253, 37, 9]);
|
|
16
|
+
const MINT_BASKET_DISCRIMINATOR = Buffer.from([161, 207, 48, 45, 7, 156, 233, 143]);
|
|
17
|
+
function depositTokensIx(params) {
|
|
18
|
+
const { owner, basket, contributions } = params;
|
|
19
|
+
let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
|
|
20
|
+
const discriminator = DEPOSIT_TOKENS_DISCRIMINATOR;
|
|
21
|
+
let ixs = [];
|
|
22
|
+
let batch_size = 5;
|
|
23
|
+
for (let i = 0; i < contributions.length; i += batch_size) {
|
|
24
|
+
let batch_contributions = contributions.slice(i, i + batch_size);
|
|
25
|
+
let amounts = batch_contributions.map((contribution) => contribution.amount);
|
|
26
|
+
while (amounts.length < 10)
|
|
27
|
+
amounts.push(0);
|
|
28
|
+
const amountsBuffer = Buffer.concat(amounts.map((amount) => Buffer.from(new bn_js_1.default(amount).toArray("le", 8))));
|
|
29
|
+
const data = Buffer.concat([discriminator, amountsBuffer]);
|
|
30
|
+
const keys = [
|
|
31
|
+
{ pubkey: owner, isSigner: true, isWritable: true },
|
|
32
|
+
{ pubkey: basket, isSigner: false, isWritable: true },
|
|
33
|
+
{ pubkey: rebalanceIntent, isSigner: false, isWritable: true },
|
|
34
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
35
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
36
|
+
{ pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
37
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
38
|
+
];
|
|
39
|
+
// remaining accounts
|
|
40
|
+
batch_contributions.forEach((contribution) => {
|
|
41
|
+
let mint = contribution.mint;
|
|
42
|
+
let ownerAta = (0, pda_1.getAta)(owner, mint);
|
|
43
|
+
let basketAta = (0, pda_1.getAta)(basket, mint);
|
|
44
|
+
keys.push({ pubkey: mint, isSigner: false, isWritable: false });
|
|
45
|
+
keys.push({ pubkey: ownerAta, isSigner: false, isWritable: true });
|
|
46
|
+
keys.push({ pubkey: basketAta, isSigner: false, isWritable: true });
|
|
47
|
+
});
|
|
48
|
+
ixs.push(new web3_js_1.TransactionInstruction({
|
|
49
|
+
keys,
|
|
50
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
51
|
+
data,
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
return ixs;
|
|
55
|
+
}
|
|
56
|
+
function lockDepositsIx(params) {
|
|
57
|
+
const { owner, basket } = params;
|
|
58
|
+
let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
|
|
59
|
+
let globalConfig = (0, pda_1.getGlobalConfigPda)();
|
|
60
|
+
const keys = [
|
|
61
|
+
{ pubkey: params.owner, isSigner: true, isWritable: true },
|
|
62
|
+
{ pubkey: rebalanceIntent, isSigner: false, isWritable: true },
|
|
63
|
+
{ pubkey: globalConfig, isSigner: false, isWritable: false },
|
|
64
|
+
];
|
|
65
|
+
return new web3_js_1.TransactionInstruction({
|
|
66
|
+
keys,
|
|
67
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
68
|
+
data: LOCK_DEPOSITS_DISCRIMINATOR,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function mintBasketIx(params) {
|
|
72
|
+
var _a;
|
|
73
|
+
const { keeper, basket, basketTokenMint, buyer } = params;
|
|
74
|
+
let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, buyer);
|
|
75
|
+
let basketFees = (0, pda_1.getBasketFeesPda)(basket);
|
|
76
|
+
let globalConfig = (0, pda_1.getGlobalConfigPda)();
|
|
77
|
+
let buyerBasketATA = (0, pda_1.getAta)(buyer, basketTokenMint);
|
|
78
|
+
let basketFeesAta = (0, pda_1.getAta)(basketFees, basketTokenMint);
|
|
79
|
+
const keys = [
|
|
80
|
+
{ pubkey: keeper, isWritable: true, isSigner: true },
|
|
81
|
+
{ pubkey: basket, isWritable: true, isSigner: false },
|
|
82
|
+
{ pubkey: rebalanceIntent, isWritable: true, isSigner: false },
|
|
83
|
+
{ pubkey: basketTokenMint, isWritable: true, isSigner: false },
|
|
84
|
+
{ pubkey: buyer, isWritable: true, isSigner: false },
|
|
85
|
+
{ pubkey: buyerBasketATA, isWritable: true, isSigner: false },
|
|
86
|
+
{ pubkey: globalConfig, isWritable: false, isSigner: false },
|
|
87
|
+
{ pubkey: basketFees, isWritable: true, isSigner: false },
|
|
88
|
+
{ pubkey: basketFeesAta, isWritable: true, isSigner: false },
|
|
89
|
+
{ pubkey: (_a = params.basketRebalanceIntent) !== null && _a !== void 0 ? _a : constants_1.BASKETS_V3_PROGRAM_ID, isWritable: params.basketRebalanceIntent ? true : false, isSigner: false },
|
|
90
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
91
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
92
|
+
{ pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
|
|
93
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isWritable: false, isSigner: false },
|
|
94
|
+
];
|
|
95
|
+
return new web3_js_1.TransactionInstruction({
|
|
96
|
+
keys,
|
|
97
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
98
|
+
data: MINT_BASKET_DISCRIMINATOR,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
export declare function redeemTokensIx(params: {
|
|
4
|
+
keeper: PublicKey;
|
|
5
|
+
basket: PublicKey;
|
|
6
|
+
owner: PublicKey;
|
|
7
|
+
tokenMints: PublicKey[];
|
|
8
|
+
}): TransactionInstruction;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redeemTokensIx = redeemTokensIx;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const pda_1 = require("../pda");
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const web3_js_2 = require("@solana/web3.js");
|
|
9
|
+
const REDEEM_TOKENS_DISCRIMINATOR = Buffer.from([83, 49, 112, 2, 105, 193, 106, 126]);
|
|
10
|
+
function redeemTokensIx(params) {
|
|
11
|
+
const { keeper, basket, owner, } = params;
|
|
12
|
+
let rebalanceIntent = (0, pda_1.getRebalanceIntentPda)(basket, owner);
|
|
13
|
+
const keys = [
|
|
14
|
+
{ pubkey: keeper, isSigner: true, isWritable: true },
|
|
15
|
+
{ pubkey: basket, isSigner: false, isWritable: true },
|
|
16
|
+
{ pubkey: rebalanceIntent, isSigner: false, isWritable: true },
|
|
17
|
+
{ pubkey: owner, isSigner: false, isWritable: true },
|
|
18
|
+
{ pubkey: spl_token_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
19
|
+
{ pubkey: spl_token_1.TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
20
|
+
{ pubkey: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
21
|
+
{ pubkey: web3_js_2.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
22
|
+
];
|
|
23
|
+
// remaining accounts
|
|
24
|
+
params.tokenMints.forEach((mint) => {
|
|
25
|
+
keys.push({ pubkey: mint, isWritable: false, isSigner: false });
|
|
26
|
+
keys.push({ pubkey: (0, pda_1.getAta)(owner, mint), isWritable: true, isSigner: false });
|
|
27
|
+
keys.push({ pubkey: (0, pda_1.getAta)(basket, mint), isWritable: true, isSigner: false });
|
|
28
|
+
});
|
|
29
|
+
const discriminator = REDEEM_TOKENS_DISCRIMINATOR;
|
|
30
|
+
const data = discriminator;
|
|
31
|
+
return new web3_js_1.TransactionInstruction({
|
|
32
|
+
keys,
|
|
33
|
+
programId: constants_1.BASKETS_V3_PROGRAM_ID,
|
|
34
|
+
data,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
export declare function processJupInstruction(instruction: {
|
|
3
|
+
programId: string;
|
|
4
|
+
accounts: {
|
|
5
|
+
pubkey: string;
|
|
6
|
+
isSigner: boolean;
|
|
7
|
+
isWritable: boolean;
|
|
8
|
+
}[];
|
|
9
|
+
data: string;
|
|
10
|
+
}): TransactionInstruction;
|
|
11
|
+
export declare function getJupQuote(params: {
|
|
12
|
+
keeper: PublicKey;
|
|
13
|
+
basketMintIn: PublicKey;
|
|
14
|
+
basketMintOut: PublicKey;
|
|
15
|
+
basketAmountIn: number;
|
|
16
|
+
basketAmountOut: number;
|
|
17
|
+
swapMode: "exact_in" | "exact_out" | "ioc";
|
|
18
|
+
apiKey: string;
|
|
19
|
+
maxJupAccounts: number;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
mode: string;
|
|
22
|
+
inputMint: string;
|
|
23
|
+
outputMint: string;
|
|
24
|
+
inAmount: number;
|
|
25
|
+
outAmount: number;
|
|
26
|
+
swapUsdValue: number;
|
|
27
|
+
routePlan: any;
|
|
28
|
+
transaction: string;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function getJupSwapInstructions(params: {
|
|
31
|
+
keeper: PublicKey;
|
|
32
|
+
quoteResponse: any;
|
|
33
|
+
apiKey: string;
|
|
34
|
+
}): Promise<any>;
|
|
35
|
+
export declare function getJupTokenLedgerAndSwapInstructions(params: {
|
|
36
|
+
keeper: PublicKey;
|
|
37
|
+
basketMintIn: PublicKey;
|
|
38
|
+
basketMintOut: PublicKey;
|
|
39
|
+
basketAmountIn: number;
|
|
40
|
+
basketAmountOut: number;
|
|
41
|
+
swapMode: "exact_in" | "exact_out" | "ioc";
|
|
42
|
+
apiKey: string;
|
|
43
|
+
maxJupAccounts: number;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
tokenLedgerInstruction: TransactionInstruction;
|
|
46
|
+
swapInstruction: TransactionInstruction;
|
|
47
|
+
addressLookupTableAddresses: PublicKey[];
|
|
48
|
+
quoteResponse: any;
|
|
49
|
+
}>;
|
package/dist/src/jup.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.processJupInstruction = processJupInstruction;
|
|
13
|
+
exports.getJupQuote = getJupQuote;
|
|
14
|
+
exports.getJupSwapInstructions = getJupSwapInstructions;
|
|
15
|
+
exports.getJupTokenLedgerAndSwapInstructions = getJupTokenLedgerAndSwapInstructions;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
function processJupInstruction(instruction) {
|
|
18
|
+
return {
|
|
19
|
+
programId: new web3_js_1.PublicKey(instruction.programId),
|
|
20
|
+
keys: instruction.accounts.map((a) => (Object.assign(Object.assign({}, a), { pubkey: new web3_js_1.PublicKey(a.pubkey) }))),
|
|
21
|
+
data: Buffer.from(instruction.data, "base64")
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getJupQuote(params) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
let options = { method: 'GET', headers: { 'x-api-key': params.apiKey } };
|
|
27
|
+
let reqUrl = 'https://api.jup.ag/swap/v1/quote' +
|
|
28
|
+
'?inputMint=' + params.basketMintOut.toBase58() +
|
|
29
|
+
'&outputMint=' + params.basketMintIn.toBase58() +
|
|
30
|
+
'&amount=' + (params.swapMode == "exact_in" ? params.basketAmountIn : params.basketAmountOut) +
|
|
31
|
+
'&swapMode=' + (params.swapMode == "exact_in" ? "ExactOut" : "ExactIn") +
|
|
32
|
+
'&maxAccounts=' + params.maxJupAccounts;
|
|
33
|
+
let res = yield fetch(reqUrl, options).then(res => res.json());
|
|
34
|
+
return res;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function getJupSwapInstructions(params) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
let reqUrl = 'https://api.jup.ag/swap/v1/swap-instructions';
|
|
40
|
+
let body = {
|
|
41
|
+
userPublicKey: params.keeper.toBase58(),
|
|
42
|
+
quoteResponse: params.quoteResponse,
|
|
43
|
+
wrapAndUnwrapSol: false,
|
|
44
|
+
useTokenLedger: true,
|
|
45
|
+
};
|
|
46
|
+
let options = {
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'Content-Type': 'application/json',
|
|
50
|
+
'x-api-key': params.apiKey
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(body),
|
|
53
|
+
};
|
|
54
|
+
let res = yield fetch(reqUrl, options).then(res => res.json());
|
|
55
|
+
return res;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function getJupTokenLedgerAndSwapInstructions(params) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
try {
|
|
61
|
+
let quoteResponse = yield getJupQuote(params);
|
|
62
|
+
let swapInstructions = yield getJupSwapInstructions(Object.assign(Object.assign({}, params), { quoteResponse }));
|
|
63
|
+
return {
|
|
64
|
+
tokenLedgerInstruction: processJupInstruction(swapInstructions.tokenLedgerInstruction),
|
|
65
|
+
swapInstruction: processJupInstruction(swapInstructions.swapInstruction),
|
|
66
|
+
addressLookupTableAddresses: swapInstructions.addressLookupTableAddresses.map((a) => new web3_js_1.PublicKey(a)),
|
|
67
|
+
quoteResponse: quoteResponse,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.log("Error getting Jup Instructions:", params.basketMintOut.toBase58(), params.basketMintIn.toBase58(), params.basketAmountOut);
|
|
72
|
+
return {
|
|
73
|
+
tokenLedgerInstruction: undefined,
|
|
74
|
+
swapInstruction: undefined,
|
|
75
|
+
addressLookupTableAddresses: [],
|
|
76
|
+
quoteResponse: undefined,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { Wallet } from "./txUtils";
|
|
3
|
+
import { Basket, UIRebalanceIntent } from ".";
|
|
4
|
+
export declare class KeeperMonitor {
|
|
5
|
+
private params;
|
|
6
|
+
private intents;
|
|
7
|
+
private rebalanceIntents;
|
|
8
|
+
private baskets;
|
|
9
|
+
constructor(params: {
|
|
10
|
+
wallet: Wallet;
|
|
11
|
+
connection: Connection;
|
|
12
|
+
network: "devnet" | "mainnet";
|
|
13
|
+
jupiterApiKey: string;
|
|
14
|
+
maxAllowedAccounts: number;
|
|
15
|
+
priorityFee?: number;
|
|
16
|
+
simulateTransactions?: boolean;
|
|
17
|
+
});
|
|
18
|
+
delay: (ms: number) => Promise<unknown>;
|
|
19
|
+
update(): Promise<void>;
|
|
20
|
+
run(runTime?: number): Promise<void>;
|
|
21
|
+
monitorIntent(pubkey: string): Promise<void>;
|
|
22
|
+
monitorRebalanceIntent(pubkey: string): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare class RebalanceHandler {
|
|
25
|
+
private params;
|
|
26
|
+
private intent;
|
|
27
|
+
private basket;
|
|
28
|
+
constructor(params: {
|
|
29
|
+
intent: UIRebalanceIntent;
|
|
30
|
+
basket: Basket;
|
|
31
|
+
wallet: Wallet;
|
|
32
|
+
connection: Connection;
|
|
33
|
+
network: "devnet" | "mainnet";
|
|
34
|
+
jupiterApiKey: string;
|
|
35
|
+
maxAllowedAccounts: number;
|
|
36
|
+
priorityFee?: number;
|
|
37
|
+
simulateTransactions?: boolean;
|
|
38
|
+
});
|
|
39
|
+
delay: (ms: number) => Promise<unknown>;
|
|
40
|
+
refresh(): Promise<void>;
|
|
41
|
+
static run(params: {
|
|
42
|
+
intentPubkey: PublicKey;
|
|
43
|
+
wallet: Wallet;
|
|
44
|
+
connection: Connection;
|
|
45
|
+
network: "devnet" | "mainnet";
|
|
46
|
+
jupiterApiKey: string;
|
|
47
|
+
maxAllowedAccounts: number;
|
|
48
|
+
priorityFee?: number;
|
|
49
|
+
simulateTransactions?: boolean;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
private execute;
|
|
52
|
+
}
|