@hawksightco/hawk-sdk 1.3.265 → 1.3.266
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/addresses.d.ts +37 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +84 -0
- package/dist/anchor.d.ts +22 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +121 -0
- package/dist/classes/AltStorage.d.ts +29 -0
- package/dist/classes/AltStorage.d.ts.map +1 -0
- package/dist/classes/AltStorage.js +58 -0
- package/dist/classes/Atomicity.d.ts +34 -0
- package/dist/classes/Atomicity.d.ts.map +1 -0
- package/dist/classes/Atomicity.js +110 -0
- package/dist/classes/Client.d.ts +35 -0
- package/dist/classes/Client.d.ts.map +1 -0
- package/dist/classes/Client.js +66 -0
- package/dist/classes/CombineTransactions.d.ts +11 -0
- package/dist/classes/CombineTransactions.d.ts.map +1 -0
- package/dist/classes/CombineTransactions.js +58 -0
- package/dist/classes/CreateTxMetadata.d.ts +100 -0
- package/dist/classes/CreateTxMetadata.d.ts.map +1 -0
- package/dist/classes/CreateTxMetadata.js +415 -0
- package/dist/classes/General.d.ts +87 -0
- package/dist/classes/General.d.ts.map +1 -0
- package/dist/classes/General.js +176 -0
- package/dist/classes/GeneralUtility.d.ts +79 -0
- package/dist/classes/GeneralUtility.d.ts.map +1 -0
- package/dist/classes/GeneralUtility.js +121 -0
- package/dist/classes/HawkAPI.d.ts +122 -0
- package/dist/classes/HawkAPI.d.ts.map +1 -0
- package/dist/classes/HawkAPI.js +169 -0
- package/dist/classes/Health.d.ts +29 -0
- package/dist/classes/Health.d.ts.map +1 -0
- package/dist/classes/Health.js +48 -0
- package/dist/classes/JupiterAlts.d.ts +37 -0
- package/dist/classes/JupiterAlts.d.ts.map +1 -0
- package/dist/classes/JupiterAlts.js +114 -0
- package/dist/classes/JupiterSwap.d.ts +21 -0
- package/dist/classes/JupiterSwap.d.ts.map +1 -0
- package/dist/classes/JupiterSwap.js +40 -0
- package/dist/classes/Logging.d.ts +13 -0
- package/dist/classes/Logging.d.ts.map +1 -0
- package/dist/classes/Logging.js +50 -0
- package/dist/classes/MultiTransaction.d.ts +75 -0
- package/dist/classes/MultiTransaction.d.ts.map +1 -0
- package/dist/classes/MultiTransaction.js +296 -0
- package/dist/classes/RaydiumSDK.d.ts +67 -0
- package/dist/classes/RaydiumSDK.d.ts.map +1 -0
- package/dist/classes/RaydiumSDK.js +206 -0
- package/dist/classes/Search.d.ts +100 -0
- package/dist/classes/Search.d.ts.map +1 -0
- package/dist/classes/Search.js +216 -0
- package/dist/classes/SimpleIxGenerator.d.ts +57 -0
- package/dist/classes/SimpleIxGenerator.d.ts.map +1 -0
- package/dist/classes/SimpleIxGenerator.js +62 -0
- package/dist/classes/SimplePdaGenerator.d.ts +28 -0
- package/dist/classes/SimplePdaGenerator.d.ts.map +1 -0
- package/dist/classes/SimplePdaGenerator.js +33 -0
- package/dist/classes/Transaction.d.ts +229 -0
- package/dist/classes/Transaction.d.ts.map +1 -0
- package/dist/classes/Transaction.js +643 -0
- package/dist/classes/Transaction2.d.ts +107 -0
- package/dist/classes/Transaction2.d.ts.map +1 -0
- package/dist/classes/Transaction2.js +249 -0
- package/dist/classes/Transaction3.d.ts +165 -0
- package/dist/classes/Transaction3.d.ts.map +1 -0
- package/dist/classes/Transaction3.js +416 -0
- package/dist/classes/TransactionBatchExecute.d.ts +163 -0
- package/dist/classes/TransactionBatchExecute.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute.js +466 -0
- package/dist/classes/TransactionBatchExecute2.d.ts +99 -0
- package/dist/classes/TransactionBatchExecute2.d.ts.map +1 -0
- package/dist/classes/TransactionBatchExecute2.js +357 -0
- package/dist/classes/Transactions.d.ts +586 -0
- package/dist/classes/Transactions.d.ts.map +1 -0
- package/dist/classes/Transactions.js +7667 -0
- package/dist/classes/TxGenerator.d.ts +350 -0
- package/dist/classes/TxGenerator.d.ts.map +1 -0
- package/dist/classes/TxGenerator.js +1957 -0
- package/dist/classes/TxGeneratorAutomations.d.ts +186 -0
- package/dist/classes/TxGeneratorAutomations.d.ts.map +1 -0
- package/dist/classes/TxGeneratorAutomations.js +897 -0
- package/dist/classes/Util.d.ts +87 -0
- package/dist/classes/Util.d.ts.map +1 -0
- package/dist/classes/Util.js +148 -0
- package/dist/classes/account-cache/AccountCache.d.ts +54 -0
- package/dist/classes/account-cache/AccountCache.d.ts.map +1 -0
- package/dist/classes/account-cache/AccountCache.js +143 -0
- package/dist/classes/account-cache/MintCache.d.ts +33 -0
- package/dist/classes/account-cache/MintCache.d.ts.map +1 -0
- package/dist/classes/account-cache/MintCache.js +47 -0
- package/dist/classes/account-cache/TokenCache.d.ts +33 -0
- package/dist/classes/account-cache/TokenCache.d.ts.map +1 -0
- package/dist/classes/account-cache/TokenCache.js +47 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +96 -0
- package/dist/functions.d.ts +514 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +1636 -0
- package/dist/hawksight.d.ts +53 -0
- package/dist/hawksight.d.ts.map +1 -0
- package/dist/hawksight.js +328 -0
- package/dist/hsToMeteora.d.ts +31 -0
- package/dist/hsToMeteora.d.ts.map +1 -0
- package/dist/hsToMeteora.js +3175 -0
- package/dist/idl/iyf-extension-idl.d.ts +14583 -0
- package/dist/idl/iyf-extension-idl.d.ts.map +1 -0
- package/dist/idl/iyf-extension-idl.js +14578 -0
- package/dist/idl/iyf-extension-wrapper.d.ts +112 -0
- package/dist/idl/iyf-extension-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-extension-wrapper.js +2 -0
- package/dist/idl/iyf-main-idl.d.ts +12078 -0
- package/dist/idl/iyf-main-idl.d.ts.map +1 -0
- package/dist/idl/iyf-main-idl.js +12073 -0
- package/dist/idl/iyf-main-wrapper.d.ts +112 -0
- package/dist/idl/iyf-main-wrapper.d.ts.map +1 -0
- package/dist/idl/iyf-main-wrapper.js +2 -0
- package/dist/idl/jupiter-idl.d.ts +3063 -0
- package/dist/idl/jupiter-idl.d.ts.map +1 -0
- package/dist/idl/jupiter-idl.js +3061 -0
- package/dist/idl/meteora-idl.d.ts +7371 -0
- package/dist/idl/meteora-idl.d.ts.map +1 -0
- package/dist/idl/meteora-idl.js +7372 -0
- package/dist/idl/orca-idl.d.ts +3833 -0
- package/dist/idl/orca-idl.d.ts.map +1 -0
- package/dist/idl/orca-idl.js +3834 -0
- package/dist/idl/raydium-idl.d.ts +3054 -0
- package/dist/idl/raydium-idl.d.ts.map +1 -0
- package/dist/idl/raydium-idl.js +3055 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts +126 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfExtensionIxGenerator.js +467 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts +330 -0
- package/dist/ixGenerator/IyfMainIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/IyfMainIxGenerator.js +1239 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts +685 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/MeteoraDlmmIxGenerator.js +3005 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts +119 -0
- package/dist/ixGenerator/OrcaIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/OrcaIxGenerator.js +438 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts +99 -0
- package/dist/ixGenerator/RaydiumIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/RaydiumIxGenerator.js +558 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts +20 -0
- package/dist/ixGenerator/UtilIxGenerator.d.ts.map +1 -0
- package/dist/ixGenerator/UtilIxGenerator.js +25 -0
- package/dist/meteora/index.d.ts +2 -0
- package/dist/meteora/index.d.ts.map +1 -0
- package/dist/meteora/index.js +17 -0
- package/dist/meteora/liquidityStrategy.d.ts +408 -0
- package/dist/meteora/liquidityStrategy.d.ts.map +1 -0
- package/dist/meteora/liquidityStrategy.js +1325 -0
- package/dist/meteora.d.ts +669 -0
- package/dist/meteora.d.ts.map +1 -0
- package/dist/meteora.js +1932 -0
- package/dist/orca.d.ts +57 -0
- package/dist/orca.d.ts.map +1 -0
- package/dist/orca.js +123 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts +29 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/HawksightPdaGenerator.js +75 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts +76 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/MeteoraPdaGenerator.js +166 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts +23 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/OrcaPdaGenerator.js +68 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts +49 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/RaydiumPdaGenerator.js +114 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts +8 -0
- package/dist/pdaGenerator/UtilPdaGenerator.d.ts.map +1 -0
- package/dist/pdaGenerator/UtilPdaGenerator.js +51 -0
- package/dist/types.d.ts +1104 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +95 -0
- package/package.json +6 -5
|
@@ -0,0 +1,1239 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.IyfMainIxGenerator = void 0;
|
|
49
|
+
const web3 = __importStar(require("@solana/web3.js"));
|
|
50
|
+
const anchor_1 = require("../anchor");
|
|
51
|
+
const hawksight_1 = require("../hawksight");
|
|
52
|
+
const functions_1 = require("../functions");
|
|
53
|
+
const addresses_1 = require("../addresses");
|
|
54
|
+
const types_1 = require("../types");
|
|
55
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
56
|
+
const token_1 = require("@coral-xyz/anchor/dist/cjs/utils/token");
|
|
57
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
58
|
+
const util = __importStar(require("../functions"));
|
|
59
|
+
const WSOL_MINT = new web3.PublicKey("So11111111111111111111111111111111111111112");
|
|
60
|
+
/**
|
|
61
|
+
* Iyf Main IX Generator
|
|
62
|
+
*/
|
|
63
|
+
class IyfMainIxGenerator {
|
|
64
|
+
/**
|
|
65
|
+
* Generates a transaction instruction that sets the current blockchain clock
|
|
66
|
+
* to the user's PDA (Program Derived Address) account.
|
|
67
|
+
*
|
|
68
|
+
* @param connection - A Solana web3.js Connection object for interacting with the blockchain.
|
|
69
|
+
* @param params - AtomicityContextParams containing the context and parameters for setting the transaction slot.
|
|
70
|
+
* @returns A Promise that resolves to a TransactionInstruction object for setting the current clock in the PDA.
|
|
71
|
+
*/
|
|
72
|
+
setTransactionSlot(connection, params) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
// Initialize anchor
|
|
75
|
+
anchor_1.Anchor.initialize(connection);
|
|
76
|
+
// Get set transaction slot instruction
|
|
77
|
+
return yield (0, hawksight_1.setTransactionSlot)(params);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Generates a transaction instruction that verifies whether the current blockchain
|
|
82
|
+
* clock matches the value that has been previously set in the user's PDA (Program Derived Address) account.
|
|
83
|
+
*
|
|
84
|
+
* @param connection - A Solana web3.js Connection object for interacting with the blockchain.
|
|
85
|
+
* @param params - AtomicityContextParams containing the context and parameters for verifying the transaction slot.
|
|
86
|
+
* @returns A Promise that resolves to a TransactionInstruction object for verifying the clock in the PDA.
|
|
87
|
+
*/
|
|
88
|
+
verifyTransactionSlot(connection, params) {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
// Initialize anchor
|
|
91
|
+
anchor_1.Anchor.initialize(connection);
|
|
92
|
+
// Get verify transaction slot instruction
|
|
93
|
+
return yield (0, hawksight_1.verifyTransactionSlot)(params);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Transfers all the pass through token accounts balance into the corresponding storage token account
|
|
98
|
+
*
|
|
99
|
+
* @param connection - A Solana web3.js Connection object for interacting with the blockchain.
|
|
100
|
+
* @param params - StoreTokenContextParams containing the context and parameters.
|
|
101
|
+
* @returns A Promise that resolves to a TransactionInstruction object for verifying the clock in the PDA.
|
|
102
|
+
*/
|
|
103
|
+
storeToken(connection, params) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
// Initialize anchor
|
|
106
|
+
anchor_1.Anchor.initialize(connection);
|
|
107
|
+
// Get verify transaction slot instruction
|
|
108
|
+
return yield (0, hawksight_1.storeToken)(connection, params);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Initialize a storage token account for a given user pda and mints
|
|
113
|
+
*
|
|
114
|
+
* @param connection
|
|
115
|
+
* @param params
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
initializeStorageTokenAccounts(connection, params) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return yield Promise.all(params.mints.map((mint) => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
return yield this.initializeStorageTokenAccount(connection, {
|
|
122
|
+
userWallet: params.userWallet,
|
|
123
|
+
mint,
|
|
124
|
+
});
|
|
125
|
+
})));
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Initialize a storage token account for a given user pda and mint
|
|
130
|
+
*
|
|
131
|
+
* @param connection
|
|
132
|
+
* @param params
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
initializeStorageTokenAccount(connection, params) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
// Initialize anchor
|
|
138
|
+
anchor_1.Anchor.initialize(connection);
|
|
139
|
+
const userPda = (0, functions_1.generateUserPda)(params.userWallet);
|
|
140
|
+
const storageTokenAccount = (0, functions_1.generateUserPdaStorageAccount)(userPda, params.mint);
|
|
141
|
+
const tokenProgram = yield util.getTokenProgramForMints(connection, [params.mint]);
|
|
142
|
+
// Create initialize storage token account instruction
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
return yield anchor_1.Anchor.instance().iyfMain.methods
|
|
145
|
+
.initializeStorageTokenAccount()
|
|
146
|
+
.accounts({
|
|
147
|
+
userPda,
|
|
148
|
+
payer: params.userWallet,
|
|
149
|
+
mint: params.mint,
|
|
150
|
+
storageTokenAccount,
|
|
151
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
152
|
+
tokenProgram,
|
|
153
|
+
systemProgram: web3_js_1.SystemProgram.programId
|
|
154
|
+
})
|
|
155
|
+
.instruction();
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Invoke iyf extension
|
|
160
|
+
*
|
|
161
|
+
* @param connection
|
|
162
|
+
* @param params
|
|
163
|
+
*/
|
|
164
|
+
iyfExtensionExecute(connection_1, _a) {
|
|
165
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userWallet, iyfExtensionIx, }) {
|
|
166
|
+
// Initialize anchor
|
|
167
|
+
anchor_1.Anchor.initialize(connection);
|
|
168
|
+
// Generate user pda
|
|
169
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
170
|
+
// Validate whether instruction is valid
|
|
171
|
+
const invalidInstruction = !iyfExtensionIx.programId.equals(addresses_1.IYF_EXTENSION) ||
|
|
172
|
+
iyfExtensionIx.keys.length < 4 ||
|
|
173
|
+
iyfExtensionIx.data.length < 8 ||
|
|
174
|
+
!iyfExtensionIx.keys[0].pubkey.equals(addresses_1.USDC_FARM) ||
|
|
175
|
+
!iyfExtensionIx.keys[1].pubkey.equals(userPda) ||
|
|
176
|
+
!iyfExtensionIx.keys[2].pubkey.equals(userWallet) ||
|
|
177
|
+
!iyfExtensionIx.keys[3].pubkey.equals(addresses_1.IYF_MAIN);
|
|
178
|
+
if (invalidInstruction) {
|
|
179
|
+
throw new Error('The given instruction is not a valid iyf extension instruction.');
|
|
180
|
+
}
|
|
181
|
+
// Generate iyf extension instruction
|
|
182
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain
|
|
183
|
+
.methods
|
|
184
|
+
.iyfExtensionExecute(iyfExtensionIx.data)
|
|
185
|
+
.accounts({
|
|
186
|
+
farm: addresses_1.USDC_FARM,
|
|
187
|
+
userPda,
|
|
188
|
+
authority: userWallet,
|
|
189
|
+
iyfProgram: addresses_1.IYF_MAIN,
|
|
190
|
+
iyfExtensionProgram: iyfExtensionIx.programId
|
|
191
|
+
})
|
|
192
|
+
.remainingAccounts(iyfExtensionIx.keys.slice(4))
|
|
193
|
+
.instruction();
|
|
194
|
+
return ix;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Invoke iyf extension
|
|
199
|
+
*
|
|
200
|
+
* @param connection
|
|
201
|
+
* @param params
|
|
202
|
+
*/
|
|
203
|
+
iyfExtensionExecuteV2(connection_1, _a) {
|
|
204
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userPda, authority, ix, }) {
|
|
205
|
+
// Initialize anchor
|
|
206
|
+
anchor_1.Anchor.initialize(connection);
|
|
207
|
+
// Validate whether instruction is valid
|
|
208
|
+
const invalidInstruction = !ix.programId.equals(addresses_1.IYF_EXTENSION) ||
|
|
209
|
+
ix.keys.length < 2 ||
|
|
210
|
+
ix.data.length < 8 ||
|
|
211
|
+
!ix.keys[0].pubkey.equals(userPda);
|
|
212
|
+
if (invalidInstruction) {
|
|
213
|
+
throw new Error('The given instruction is not a valid iyf extension v2 instruction.');
|
|
214
|
+
}
|
|
215
|
+
const wrapIx = yield anchor_1.Anchor.instance().iyfMain
|
|
216
|
+
.methods
|
|
217
|
+
.iyfExtensionExecuteV2(ix.data)
|
|
218
|
+
.accounts({
|
|
219
|
+
userPda,
|
|
220
|
+
authority,
|
|
221
|
+
iyfExtensionProgram: ix.programId
|
|
222
|
+
})
|
|
223
|
+
.remainingAccounts(ix.keys.slice(2))
|
|
224
|
+
.instruction();
|
|
225
|
+
// NOTE: We need iyf execute 2 authority to always be writable now
|
|
226
|
+
// // Retain the mutable status of the authority
|
|
227
|
+
// wrapIx.keys[1].isWritable = ix.keys[1].isWritable;
|
|
228
|
+
// Generate iyf extension instruction
|
|
229
|
+
return wrapIx;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
jupiterRouteIx(_a) {
|
|
233
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet, userPda, sourceTokenAccount, destinationTokenAccount, destinationMint, platformFeeAccount, eventAuthority, remainingAccounts, data, slippageOutPct, quotedOutAmount_override, slippageBps, platformFeeBps, isWalletSigner, }) {
|
|
234
|
+
var _b;
|
|
235
|
+
// Initialize anchor
|
|
236
|
+
anchor_1.Anchor.initialize(connection);
|
|
237
|
+
const { routePlan, slippageBps: slippageBps_default, platformFeeBps: platformFeeBps_default, } = (0, functions_1.getJupiterRouteIxParams)(data);
|
|
238
|
+
const tokenProgramMap = yield util.getTokenProgramMapForMints(connection, [destinationMint]);
|
|
239
|
+
const tokenProgram = tokenProgramMap[destinationMint.toString()];
|
|
240
|
+
// Generate user pda from given user wallet
|
|
241
|
+
userPda = userWallet !== undefined ? (0, functions_1.generateUserPda)(userWallet) : userPda;
|
|
242
|
+
if (userPda === undefined) {
|
|
243
|
+
throw new Error("Either one of `userWallet` or `userPda` parameter must be defined!");
|
|
244
|
+
}
|
|
245
|
+
// Defaults to false
|
|
246
|
+
let ataExists = false;
|
|
247
|
+
// Generate STA and ATA
|
|
248
|
+
const destATA = (0, functions_1.generateAta)(userPda, destinationMint, tokenProgram);
|
|
249
|
+
const destSTA = (0, functions_1.generateUserPdaStorageAccount)(userPda, destinationMint);
|
|
250
|
+
const destLTA = (0, functions_1.generateLimitToken)(userPda, destinationMint);
|
|
251
|
+
// createAtaIx
|
|
252
|
+
let createAtaIx;
|
|
253
|
+
if (destATA.equals(destinationTokenAccount)) {
|
|
254
|
+
[createAtaIx] = (0, functions_1.createAtaIdempotentIxs)({
|
|
255
|
+
accounts: [{
|
|
256
|
+
payer: addresses_1.HS_AUTHORITY,
|
|
257
|
+
mint: destinationMint,
|
|
258
|
+
owner: userPda,
|
|
259
|
+
programId: tokenProgram,
|
|
260
|
+
}]
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
else if (destSTA.equals(destinationTokenAccount)) {
|
|
264
|
+
createAtaIx = yield anchor_1.Anchor.instance().iyfMain
|
|
265
|
+
.methods
|
|
266
|
+
.initializeStorageTokenAccount()
|
|
267
|
+
.accounts({
|
|
268
|
+
userPda,
|
|
269
|
+
payer: addresses_1.HS_AUTHORITY,
|
|
270
|
+
mint: destinationMint,
|
|
271
|
+
storageTokenAccount: destSTA,
|
|
272
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
273
|
+
tokenProgram,
|
|
274
|
+
systemProgram: web3.SystemProgram.programId,
|
|
275
|
+
})
|
|
276
|
+
.instruction();
|
|
277
|
+
}
|
|
278
|
+
else if (destLTA.equals(destinationTokenAccount)) {
|
|
279
|
+
[createAtaIx] = (0, functions_1.createAtaIdempotentIxs)({
|
|
280
|
+
accounts: [{
|
|
281
|
+
payer: addresses_1.HS_AUTHORITY,
|
|
282
|
+
mint: destinationMint,
|
|
283
|
+
owner: userPda,
|
|
284
|
+
}]
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
throw new Error(`destinationTokenAccount: ${destinationTokenAccount} is neither ATA(${destATA}) or STA${destSTA}`);
|
|
289
|
+
}
|
|
290
|
+
const info = yield connection.getAccountInfo(destinationTokenAccount);
|
|
291
|
+
ataExists = !(info === null || info === undefined);
|
|
292
|
+
const closeAtaIx = yield anchor_1.Anchor.instance().iyfMain
|
|
293
|
+
.methods
|
|
294
|
+
.closeAta()
|
|
295
|
+
.accounts({
|
|
296
|
+
userPda,
|
|
297
|
+
hsAuthority: addresses_1.HS_AUTHORITY,
|
|
298
|
+
userTokenAccount: destinationTokenAccount,
|
|
299
|
+
tokenProgram,
|
|
300
|
+
})
|
|
301
|
+
.instruction();
|
|
302
|
+
const quotedOutAmount_sim = new bn_js_1.default(0);
|
|
303
|
+
const p_slippageBps = slippageBps === undefined ? slippageBps_default : slippageBps;
|
|
304
|
+
const p_platformFeeBps = platformFeeBps === undefined ? platformFeeBps_default : platformFeeBps;
|
|
305
|
+
const jupiterRouteIx = (quotedOutAmount) => __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
// @ts-ignore
|
|
307
|
+
return yield anchor_1.Anchor.instance().iyfMain
|
|
308
|
+
.methods
|
|
309
|
+
.jupiterRouteIx(routePlan, quotedOutAmount, p_slippageBps, p_platformFeeBps)
|
|
310
|
+
.accounts({
|
|
311
|
+
authority: isWalletSigner ? userWallet : addresses_1.HS_AUTHORITY,
|
|
312
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID, // token2022 program probably generated in remaining accounts generated by jupiter API.
|
|
313
|
+
userPda,
|
|
314
|
+
userSourceTokenAccount: sourceTokenAccount,
|
|
315
|
+
userDestinationTokenAccount: destinationTokenAccount,
|
|
316
|
+
destinationMint,
|
|
317
|
+
platformFeeAccount,
|
|
318
|
+
eventAuthority,
|
|
319
|
+
jupiterProgram: addresses_1.JUPITER_PROGRAM
|
|
320
|
+
})
|
|
321
|
+
.remainingAccounts(remainingAccounts)
|
|
322
|
+
.instruction();
|
|
323
|
+
});
|
|
324
|
+
// If quotedOutAmountOverride is set, then skip the simulation
|
|
325
|
+
if (quotedOutAmount_override) {
|
|
326
|
+
const ix = yield jupiterRouteIx(quotedOutAmount_override);
|
|
327
|
+
return {
|
|
328
|
+
swapIx: ix,
|
|
329
|
+
createAtaIx,
|
|
330
|
+
closeAtaIx,
|
|
331
|
+
ataExists,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
// Create simulation ix (to figure out result value of destination token)
|
|
335
|
+
const ixSimulate = yield jupiterRouteIx(quotedOutAmount_sim);
|
|
336
|
+
const instructions = [createAtaIx, ixSimulate]
|
|
337
|
+
.filter((_, index) => index === 0 && !ataExists ? !ataExists : true);
|
|
338
|
+
let previousAmount = new bn_js_1.default(0);
|
|
339
|
+
if (ataExists && info !== null) {
|
|
340
|
+
const token = (0, functions_1.parseTokenAccountData)(info.data);
|
|
341
|
+
previousAmount = token.amount;
|
|
342
|
+
}
|
|
343
|
+
if (slippageOutPct === undefined) {
|
|
344
|
+
throw new Error(`slippageOutPct parameter is not set`);
|
|
345
|
+
}
|
|
346
|
+
// Simulate the transaction to get expected out token
|
|
347
|
+
let tokenAmount = previousAmount;
|
|
348
|
+
if (slippageOutPct < 10000) {
|
|
349
|
+
const simulation = yield (0, functions_1.simulateTransaction)({
|
|
350
|
+
connection,
|
|
351
|
+
instructions,
|
|
352
|
+
payerKey: isWalletSigner ? userWallet : addresses_1.HS_AUTHORITY,
|
|
353
|
+
alts: [],
|
|
354
|
+
signers: [],
|
|
355
|
+
addresses: [destinationTokenAccount.toString()],
|
|
356
|
+
});
|
|
357
|
+
try {
|
|
358
|
+
const token = (0, functions_1.parseTokenAccountData)(Buffer.from((_b = simulation.accounts[0]) === null || _b === void 0 ? void 0 : _b.data[0], 'base64'));
|
|
359
|
+
tokenAmount = token.amount;
|
|
360
|
+
}
|
|
361
|
+
catch (_c) {
|
|
362
|
+
console.log(simulation.logs);
|
|
363
|
+
throw Error('Transaction simulation failed. See logs above.');
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
const delta = tokenAmount.sub(previousAmount);
|
|
367
|
+
const quotedOutAmount = delta.mul(new bn_js_1.default(10000)
|
|
368
|
+
.sub(new bn_js_1.default(slippageOutPct))).div(new bn_js_1.default(10000));
|
|
369
|
+
slippageBps = slippageBps === undefined ? slippageBps_default : slippageBps;
|
|
370
|
+
platformFeeBps = platformFeeBps === undefined ? platformFeeBps_default : platformFeeBps;
|
|
371
|
+
// Create actual ix with calculated slippage amount from `slippageOut` input
|
|
372
|
+
const ix = yield jupiterRouteIx(quotedOutAmount);
|
|
373
|
+
return {
|
|
374
|
+
swapIx: ix,
|
|
375
|
+
createAtaIx,
|
|
376
|
+
closeAtaIx,
|
|
377
|
+
ataExists,
|
|
378
|
+
};
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
withdrawLamportsFromPda(_a) {
|
|
382
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet }) {
|
|
383
|
+
// Initialize anchor
|
|
384
|
+
anchor_1.Anchor.initialize(connection);
|
|
385
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
386
|
+
const userPdaLamport = (0, functions_1.generateUserPdaLamport)(userWallet);
|
|
387
|
+
return yield anchor_1.Anchor.instance().iyfMain.methods
|
|
388
|
+
.withdrawLamportsFromPda()
|
|
389
|
+
.accounts({
|
|
390
|
+
farm: addresses_1.USDC_FARM,
|
|
391
|
+
payer: userWallet,
|
|
392
|
+
userPda,
|
|
393
|
+
userPdaLamport,
|
|
394
|
+
ownerFeeAccount: addresses_1.SITE_FEE_OWNER,
|
|
395
|
+
systemProgram: web3.SystemProgram.programId,
|
|
396
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
397
|
+
})
|
|
398
|
+
.instruction();
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Deposit multiple user pda token to passthrough token accounts
|
|
403
|
+
*
|
|
404
|
+
* @returns DepositMultipleToken instruction
|
|
405
|
+
*/
|
|
406
|
+
depositMultipleToken(_a) {
|
|
407
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, deposit }) {
|
|
408
|
+
return yield (0, hawksight_1.depositMultipleToken)({ connection, payer, deposit });
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Deposit multiple user pda token to passthrough token accountsz
|
|
413
|
+
*
|
|
414
|
+
* @returns DepositMultipleToken instruction
|
|
415
|
+
*/
|
|
416
|
+
withdrawMultipleToken(_a) {
|
|
417
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, withdraw, useSta }) {
|
|
418
|
+
return yield (0, hawksight_1.withdrawMultipleToken)({ connection, payer, withdraw, useSta });
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Deposit multiple user pda token to passthrough token accounts
|
|
423
|
+
*
|
|
424
|
+
* @returns DepositMultipleToken instruction
|
|
425
|
+
*/
|
|
426
|
+
depositMultipleTokenV2(_a) {
|
|
427
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, deposit, pdaTokenType }) {
|
|
428
|
+
return yield (0, hawksight_1.depositMultipleTokenV2)({ connection, payer, deposit, pdaTokenType });
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Deposit multiple user pda token to passthrough token accountsz
|
|
433
|
+
*
|
|
434
|
+
* @returns DepositMultipleToken instruction
|
|
435
|
+
*/
|
|
436
|
+
withdrawMultipleTokenV2(_a) {
|
|
437
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, withdraw, useSta, pdaTokenType, hasAmount }) {
|
|
438
|
+
return yield (0, hawksight_1.withdrawMultipleTokenV2)({ connection, payer, withdraw, useSta, pdaTokenType, hasAmount });
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Deposit multiple user pda token to passthrough token accounts
|
|
443
|
+
*
|
|
444
|
+
* @deprecated Will be moving towards labeled instructions. Please use depositMultipleTokenWithToken2022WithLabel
|
|
445
|
+
*
|
|
446
|
+
* @returns DepositMultipleToken instruction
|
|
447
|
+
*/
|
|
448
|
+
depositMultipleTokenWithToken2022(_a) {
|
|
449
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, deposit, pdaTokenType }) {
|
|
450
|
+
const farm = addresses_1.USDC_FARM;
|
|
451
|
+
const userPda = util.generateUserPda(payer, farm);
|
|
452
|
+
const amounts = deposit.map((d) => d.amount);
|
|
453
|
+
const remainingAccounts = [];
|
|
454
|
+
// Get mint pubkeys
|
|
455
|
+
const mints = deposit.map((d) => d.mint);
|
|
456
|
+
// Get and assert one token program for all mints.
|
|
457
|
+
// Throws an error if there are multiple token programs.
|
|
458
|
+
const tokenProgramMap = yield util.getTokenProgramMapForMints(connection, mints);
|
|
459
|
+
let skipIdempotent = false;
|
|
460
|
+
deposit.map((d) => {
|
|
461
|
+
const mint = d.mint;
|
|
462
|
+
const key = mint.toString();
|
|
463
|
+
const userToken = util.generateAta(payer, d.mint, tokenProgramMap[key]);
|
|
464
|
+
const ownerFeeToken = util.generateAta(addresses_1.SITE_FEE_OWNER, d.mint, tokenProgramMap[key]);
|
|
465
|
+
let userPdaToken;
|
|
466
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
467
|
+
skipIdempotent = true;
|
|
468
|
+
userPdaToken = util.generateLimitToken(userPda, d.mint);
|
|
469
|
+
}
|
|
470
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
471
|
+
skipIdempotent = true;
|
|
472
|
+
userPdaToken = util.generateUserPdaStorageAccount(userPda, d.mint);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
userPdaToken = util.generateAta(userPda, d.mint, tokenProgramMap[key]);
|
|
476
|
+
}
|
|
477
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
478
|
+
remainingAccounts.push({
|
|
479
|
+
pubkey: userToken,
|
|
480
|
+
isSigner: false,
|
|
481
|
+
isWritable: true,
|
|
482
|
+
});
|
|
483
|
+
remainingAccounts.push({
|
|
484
|
+
pubkey: userPdaToken,
|
|
485
|
+
isSigner: false,
|
|
486
|
+
isWritable: true,
|
|
487
|
+
});
|
|
488
|
+
remainingAccounts.push({
|
|
489
|
+
pubkey: ownerFeeToken,
|
|
490
|
+
isSigner: false,
|
|
491
|
+
isWritable: true,
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
// @ts-ignore
|
|
495
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
496
|
+
.depositMultipleTokenWithToken2022(amounts, skipIdempotent)
|
|
497
|
+
.accounts({
|
|
498
|
+
farm,
|
|
499
|
+
userPda,
|
|
500
|
+
payer,
|
|
501
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
502
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
503
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
504
|
+
tokenProgram2022: addresses_1.TOKEN_2022_PROGRAM_ID,
|
|
505
|
+
systemProgram: web3.SystemProgram.programId,
|
|
506
|
+
})
|
|
507
|
+
.remainingAccounts(remainingAccounts)
|
|
508
|
+
.instruction();
|
|
509
|
+
// IDL marks payer as signer only, but the program CPIs into
|
|
510
|
+
// CreateIdempotent/transfer which needs payer writable to debit lamports.
|
|
511
|
+
const payerKey = ix.keys.find(k => k.pubkey.equals(payer));
|
|
512
|
+
if (payerKey)
|
|
513
|
+
payerKey.isWritable = true;
|
|
514
|
+
return ix;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Deposit multiple user pda token to passthrough token accounts
|
|
519
|
+
*
|
|
520
|
+
* @returns DepositMultipleToken instruction
|
|
521
|
+
*/
|
|
522
|
+
depositMultipleTokenWithToken2022WithLabel(_a) {
|
|
523
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, deposit, pdaTokenType }) {
|
|
524
|
+
const farm = addresses_1.USDC_FARM;
|
|
525
|
+
const userPda = util.generateUserPda(payer, farm);
|
|
526
|
+
const amounts = deposit.map((d) => d.amount);
|
|
527
|
+
const remainingAccounts = [];
|
|
528
|
+
// Get mint pubkeys
|
|
529
|
+
const mints = deposit.map((d) => d.mint);
|
|
530
|
+
// Get and assert one token program for all mints.
|
|
531
|
+
// Throws an error if there are multiple token programs.
|
|
532
|
+
const tokenProgramMap = yield util.getTokenProgramMapForMints(connection, mints);
|
|
533
|
+
let skipIdempotent = false;
|
|
534
|
+
deposit.map((d) => {
|
|
535
|
+
const mint = d.mint;
|
|
536
|
+
const key = mint.toString();
|
|
537
|
+
const userToken = util.generateAta(payer, d.mint, tokenProgramMap[key]);
|
|
538
|
+
const ownerFeeToken = util.generateAta(addresses_1.SITE_FEE_OWNER, d.mint, tokenProgramMap[key]);
|
|
539
|
+
let userPdaToken;
|
|
540
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
541
|
+
skipIdempotent = true;
|
|
542
|
+
userPdaToken = util.generateLimitToken(userPda, d.mint);
|
|
543
|
+
}
|
|
544
|
+
else if (pdaTokenType === types_1.TokenType.STA) {
|
|
545
|
+
skipIdempotent = true;
|
|
546
|
+
userPdaToken = util.generateUserPdaStorageAccount(userPda, d.mint);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
userPdaToken = util.generateAta(userPda, d.mint, tokenProgramMap[key]);
|
|
550
|
+
}
|
|
551
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
552
|
+
remainingAccounts.push({
|
|
553
|
+
pubkey: userToken,
|
|
554
|
+
isSigner: false,
|
|
555
|
+
isWritable: true,
|
|
556
|
+
});
|
|
557
|
+
remainingAccounts.push({
|
|
558
|
+
pubkey: userPdaToken,
|
|
559
|
+
isSigner: false,
|
|
560
|
+
isWritable: true,
|
|
561
|
+
});
|
|
562
|
+
remainingAccounts.push({
|
|
563
|
+
pubkey: ownerFeeToken,
|
|
564
|
+
isSigner: false,
|
|
565
|
+
isWritable: true,
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
// @ts-ignore
|
|
569
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
570
|
+
.depositMultipleTokenWithToken2022(amounts, skipIdempotent)
|
|
571
|
+
.accounts({
|
|
572
|
+
farm,
|
|
573
|
+
userPda,
|
|
574
|
+
payer,
|
|
575
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
576
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
577
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
578
|
+
tokenProgram2022: addresses_1.TOKEN_2022_PROGRAM_ID,
|
|
579
|
+
systemProgram: web3.SystemProgram.programId,
|
|
580
|
+
})
|
|
581
|
+
.remainingAccounts(remainingAccounts)
|
|
582
|
+
.instruction();
|
|
583
|
+
// IDL marks payer as signer only, but the program CPIs into
|
|
584
|
+
// CreateIdempotent/transfer which needs payer writable to debit lamports.
|
|
585
|
+
const payerKey = ix.keys.find(k => k.pubkey.equals(payer));
|
|
586
|
+
if (payerKey)
|
|
587
|
+
payerKey.isWritable = true;
|
|
588
|
+
return {
|
|
589
|
+
instruction: ix,
|
|
590
|
+
label: `Deposit tokens to passthrough token accounts`,
|
|
591
|
+
class: `depositMultipleTokenWithToken2022WithLabel`
|
|
592
|
+
};
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Deposit multiple user pda token to passthrough token accountsz
|
|
597
|
+
*
|
|
598
|
+
* @returns DepositMultipleToken instruction
|
|
599
|
+
*/
|
|
600
|
+
withdrawMultipleTokenWithToken2022(_a) {
|
|
601
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, withdraw, useSta, pdaTokenType, hasAmount }) {
|
|
602
|
+
const farm = addresses_1.USDC_FARM;
|
|
603
|
+
const userPda = util.generateUserPda(payer, farm);
|
|
604
|
+
const remainingAccounts = [];
|
|
605
|
+
const amounts = withdraw.map((d) => d.amount);
|
|
606
|
+
// Get mint pubkeys
|
|
607
|
+
const mints = withdraw.map((d) => d.mint);
|
|
608
|
+
console.log("mints", mints);
|
|
609
|
+
// Get and assert one token program for all mints.
|
|
610
|
+
// Throws an error if there are multiple token programs.
|
|
611
|
+
const tokenProgramMap = yield util.getTokenProgramMapForMints(connection, mints);
|
|
612
|
+
let skipIdempotent = false;
|
|
613
|
+
withdraw.map((d) => {
|
|
614
|
+
const mint = d.mint;
|
|
615
|
+
const key = mint.toString();
|
|
616
|
+
const userToken = util.generateAta(payer, d.mint, tokenProgramMap[key]);
|
|
617
|
+
const ownerFeeToken = util.generateAta(addresses_1.SITE_FEE_OWNER, d.mint, tokenProgramMap[key]);
|
|
618
|
+
let userPdaToken;
|
|
619
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
620
|
+
// skipIdempotent = true;
|
|
621
|
+
userPdaToken = util.generateLimitToken(userPda, d.mint);
|
|
622
|
+
}
|
|
623
|
+
else if (pdaTokenType === types_1.TokenType.STA || useSta) {
|
|
624
|
+
// skipIdempotent = true;
|
|
625
|
+
userPdaToken = util.generateUserPdaStorageAccount(userPda, d.mint);
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
userPdaToken = util.generateAta(userPda, d.mint, tokenProgramMap[key]);
|
|
629
|
+
}
|
|
630
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
631
|
+
remainingAccounts.push({
|
|
632
|
+
pubkey: userToken,
|
|
633
|
+
isSigner: false,
|
|
634
|
+
isWritable: true,
|
|
635
|
+
});
|
|
636
|
+
remainingAccounts.push({
|
|
637
|
+
pubkey: userPdaToken,
|
|
638
|
+
isSigner: false,
|
|
639
|
+
isWritable: true,
|
|
640
|
+
});
|
|
641
|
+
remainingAccounts.push({
|
|
642
|
+
pubkey: ownerFeeToken,
|
|
643
|
+
isSigner: false,
|
|
644
|
+
isWritable: true,
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
// @ts-ignore
|
|
648
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
649
|
+
.withdrawMultipleTokenWithToken2022(skipIdempotent, hasAmount ? amounts : null)
|
|
650
|
+
.accounts({
|
|
651
|
+
farm,
|
|
652
|
+
userPda,
|
|
653
|
+
payer,
|
|
654
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
655
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
656
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
657
|
+
tokenProgram2022: addresses_1.TOKEN_2022_PROGRAM_ID,
|
|
658
|
+
systemProgram: web3.SystemProgram.programId,
|
|
659
|
+
})
|
|
660
|
+
.remainingAccounts(remainingAccounts)
|
|
661
|
+
.instruction();
|
|
662
|
+
return ix;
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Deposit multiple user pda token to passthrough token accountsz
|
|
667
|
+
*
|
|
668
|
+
* @returns DepositMultipleToken instruction
|
|
669
|
+
*/
|
|
670
|
+
withdrawMultipleTokenWithToken2022WithLabel(_a) {
|
|
671
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, withdraw, useSta, pdaTokenType, hasAmount }) {
|
|
672
|
+
const farm = addresses_1.USDC_FARM;
|
|
673
|
+
const userPda = util.generateUserPda(payer, farm);
|
|
674
|
+
const remainingAccounts = [];
|
|
675
|
+
const amounts = withdraw.map((d) => d.amount);
|
|
676
|
+
// Get mint pubkeys
|
|
677
|
+
const mints = withdraw.map((d) => d.mint);
|
|
678
|
+
console.log("mints", mints);
|
|
679
|
+
// Get and assert one token program for all mints.
|
|
680
|
+
// Throws an error if there are multiple token programs.
|
|
681
|
+
const tokenProgramMap = yield util.getTokenProgramMapForMints(connection, mints);
|
|
682
|
+
let skipIdempotent = false;
|
|
683
|
+
withdraw.map((d) => {
|
|
684
|
+
const mint = d.mint;
|
|
685
|
+
const key = mint.toString();
|
|
686
|
+
const userToken = util.generateAta(payer, d.mint, tokenProgramMap[key]);
|
|
687
|
+
const ownerFeeToken = util.generateAta(addresses_1.SITE_FEE_OWNER, d.mint, tokenProgramMap[key]);
|
|
688
|
+
let userPdaToken;
|
|
689
|
+
if (pdaTokenType === types_1.TokenType.LTA) {
|
|
690
|
+
// skipIdempotent = true;
|
|
691
|
+
userPdaToken = util.generateLimitToken(userPda, d.mint);
|
|
692
|
+
}
|
|
693
|
+
else if (pdaTokenType === types_1.TokenType.STA || useSta) {
|
|
694
|
+
// skipIdempotent = true;
|
|
695
|
+
userPdaToken = util.generateUserPdaStorageAccount(userPda, d.mint);
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
userPdaToken = util.generateAta(userPda, d.mint, tokenProgramMap[key]);
|
|
699
|
+
}
|
|
700
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
701
|
+
remainingAccounts.push({
|
|
702
|
+
pubkey: userToken,
|
|
703
|
+
isSigner: false,
|
|
704
|
+
isWritable: true,
|
|
705
|
+
});
|
|
706
|
+
remainingAccounts.push({
|
|
707
|
+
pubkey: userPdaToken,
|
|
708
|
+
isSigner: false,
|
|
709
|
+
isWritable: true,
|
|
710
|
+
});
|
|
711
|
+
remainingAccounts.push({
|
|
712
|
+
pubkey: ownerFeeToken,
|
|
713
|
+
isSigner: false,
|
|
714
|
+
isWritable: true,
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
// @ts-ignore
|
|
718
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
719
|
+
.withdrawMultipleTokenWithToken2022(skipIdempotent, hasAmount ? amounts : null)
|
|
720
|
+
.accounts({
|
|
721
|
+
farm,
|
|
722
|
+
userPda,
|
|
723
|
+
payer,
|
|
724
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
725
|
+
associatedTokenProgram: addresses_1.ASSOCIATED_TOKEN_PROGRAM,
|
|
726
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
727
|
+
tokenProgram2022: addresses_1.TOKEN_2022_PROGRAM_ID,
|
|
728
|
+
systemProgram: web3.SystemProgram.programId,
|
|
729
|
+
})
|
|
730
|
+
.remainingAccounts(remainingAccounts)
|
|
731
|
+
.instruction();
|
|
732
|
+
return {
|
|
733
|
+
instruction: ix,
|
|
734
|
+
label: `Withdraw tokens from passthrough token accounts`,
|
|
735
|
+
class: `withdrawMultipleTokenWithToken2022WithLabel`
|
|
736
|
+
};
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Deposit single token from user pda
|
|
741
|
+
*
|
|
742
|
+
* @returns
|
|
743
|
+
*/
|
|
744
|
+
depositTokenFromUserPda(_a) {
|
|
745
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet, mint, amount, type, }) {
|
|
746
|
+
const farm = addresses_1.USDC_FARM;
|
|
747
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
748
|
+
const tokenProgram = yield util.getTokenProgramForMints(connection, [mint]);
|
|
749
|
+
const userToken = (0, functions_1.generateAta)(userWallet, mint, tokenProgram);
|
|
750
|
+
let userPdaToken;
|
|
751
|
+
if (type === types_1.TokenType.LTA) {
|
|
752
|
+
userPdaToken = (0, functions_1.generateLimitToken)(userPda, mint);
|
|
753
|
+
}
|
|
754
|
+
else if (type === types_1.TokenType.STA) {
|
|
755
|
+
userPdaToken = (0, functions_1.generateUserPdaStorageAccount)(userPda, mint);
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
userPdaToken = (0, functions_1.generateAta)(userPda, mint, tokenProgram);
|
|
759
|
+
}
|
|
760
|
+
const ownerFeeToken = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mint, tokenProgram);
|
|
761
|
+
// @ts-ignore
|
|
762
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
763
|
+
.depositTokenToUserPda(amount)
|
|
764
|
+
.accounts({
|
|
765
|
+
farm,
|
|
766
|
+
userPda,
|
|
767
|
+
payer: userWallet,
|
|
768
|
+
userToken,
|
|
769
|
+
userPdaToken,
|
|
770
|
+
ownerFeeToken,
|
|
771
|
+
tokenProgram,
|
|
772
|
+
})
|
|
773
|
+
.instruction();
|
|
774
|
+
return ix;
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Withdraw single token from user pda
|
|
779
|
+
*
|
|
780
|
+
* @returns
|
|
781
|
+
*/
|
|
782
|
+
withdrawTokenFromUserPda(_a) {
|
|
783
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet, mint, useSta, type, }) {
|
|
784
|
+
const farm = addresses_1.USDC_FARM;
|
|
785
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
786
|
+
const remainingAccounts = [];
|
|
787
|
+
const tokenProgram = yield util.getTokenProgramForMints(connection, [mint]);
|
|
788
|
+
const userToken = (0, functions_1.generateAta)(userWallet, mint, tokenProgram);
|
|
789
|
+
let userPdaToken;
|
|
790
|
+
if (type === types_1.TokenType.LTA) {
|
|
791
|
+
userPdaToken = (0, functions_1.generateLimitToken)(userPda, mint);
|
|
792
|
+
}
|
|
793
|
+
else if (type === types_1.TokenType.STA || useSta) {
|
|
794
|
+
userPdaToken = (0, functions_1.generateUserPdaStorageAccount)(userPda, mint);
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
userPdaToken = (0, functions_1.generateAta)(userPda, mint, tokenProgram);
|
|
798
|
+
}
|
|
799
|
+
const ownerFeeToken = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, mint, tokenProgram);
|
|
800
|
+
// @ts-ignore
|
|
801
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
802
|
+
.withdrawTokenFromUserPda()
|
|
803
|
+
.accounts({
|
|
804
|
+
farm,
|
|
805
|
+
userPda,
|
|
806
|
+
payer: userWallet,
|
|
807
|
+
userToken,
|
|
808
|
+
userPdaToken,
|
|
809
|
+
ownerFeeToken,
|
|
810
|
+
tokenProgram,
|
|
811
|
+
})
|
|
812
|
+
.remainingAccounts(remainingAccounts)
|
|
813
|
+
.instruction();
|
|
814
|
+
return ix;
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
raydiumDynamicCpi(connection_1, _a) {
|
|
818
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userWallet, raydiumIx, }) {
|
|
819
|
+
// Initialize anchor
|
|
820
|
+
anchor_1.Anchor.initialize(connection);
|
|
821
|
+
// Generate user pda
|
|
822
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
823
|
+
const nftOwner = (0, functions_1.generateUserPdaLamport)(userWallet);
|
|
824
|
+
if (raydiumIx.programId.equals(addresses_1.RAYDIUM_PROGRAM)) {
|
|
825
|
+
// Define the whitelisted instructions
|
|
826
|
+
const whitelist = {
|
|
827
|
+
"open_position_with_token22_nft": 1,
|
|
828
|
+
"close_position": 0,
|
|
829
|
+
"increase_liquidity_v2": 0,
|
|
830
|
+
};
|
|
831
|
+
// Find the instruction
|
|
832
|
+
const key = Object.keys(whitelist).find(discriminator => (0, functions_1.sighashMatch)(raydiumIx.data, discriminator, "global", true));
|
|
833
|
+
// Key has to return a value. Otherwise, throw error (means we try to execute ix not in the whitelist)
|
|
834
|
+
if (key === undefined) {
|
|
835
|
+
throw new Error('raydiumDynamicCpi: Instruction not in whitelist.');
|
|
836
|
+
}
|
|
837
|
+
const index = whitelist[key];
|
|
838
|
+
// Remove nft owner
|
|
839
|
+
raydiumIx.keys.splice(index, 1);
|
|
840
|
+
// Raydium dynamic cpi wrapper
|
|
841
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
842
|
+
.raydiumDynamicCpi(raydiumIx.data)
|
|
843
|
+
.accounts({
|
|
844
|
+
raydiumProgram: addresses_1.RAYDIUM_PROGRAM,
|
|
845
|
+
userPda,
|
|
846
|
+
authority: userWallet,
|
|
847
|
+
nftOwner,
|
|
848
|
+
})
|
|
849
|
+
.remainingAccounts([
|
|
850
|
+
...raydiumIx.keys
|
|
851
|
+
])
|
|
852
|
+
.instruction();
|
|
853
|
+
return ix;
|
|
854
|
+
}
|
|
855
|
+
else if (raydiumIx.programId.equals(addresses_1.IYF_EXTENSION)) {
|
|
856
|
+
// Raydium dynamic cpi wrapper
|
|
857
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
858
|
+
.raydiumDynamicCpi(raydiumIx.data)
|
|
859
|
+
.accounts({
|
|
860
|
+
raydiumProgram: addresses_1.RAYDIUM_PROGRAM,
|
|
861
|
+
userPda,
|
|
862
|
+
authority: raydiumIx.keys[2].pubkey,
|
|
863
|
+
nftOwner,
|
|
864
|
+
})
|
|
865
|
+
.remainingAccounts([
|
|
866
|
+
{ pubkey: addresses_1.IYF_EXTENSION, isSigner: false, isWritable: false },
|
|
867
|
+
...raydiumIx.keys.slice(4)
|
|
868
|
+
])
|
|
869
|
+
.instruction();
|
|
870
|
+
return ix;
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
throw new Error(`raydiumDynamicCpi: Invalid raydiumIx.programId: ${raydiumIx.programId}`);
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
depositMultipleLamportPdaToken(_a) {
|
|
878
|
+
return __awaiter(this, arguments, void 0, function* ({ userWallet, deposit, skipIdempotent }) {
|
|
879
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
880
|
+
const userPdaLamport = (0, functions_1.generateUserPdaLamport)(userWallet);
|
|
881
|
+
const amounts = deposit.map((d) => d.amount);
|
|
882
|
+
const remainingAccounts = [];
|
|
883
|
+
deposit.map((d) => {
|
|
884
|
+
const mint = d.mint;
|
|
885
|
+
const userToken = (0, functions_1.generateAta)(userWallet, d.mint);
|
|
886
|
+
const userPdaToken = (0, functions_1.generateAta)(userPdaLamport, d.mint);
|
|
887
|
+
const ownerFeeToken = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, d.mint);
|
|
888
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
889
|
+
remainingAccounts.push({
|
|
890
|
+
pubkey: userToken,
|
|
891
|
+
isSigner: false,
|
|
892
|
+
isWritable: true,
|
|
893
|
+
});
|
|
894
|
+
remainingAccounts.push({
|
|
895
|
+
pubkey: userPdaToken,
|
|
896
|
+
isSigner: false,
|
|
897
|
+
isWritable: true,
|
|
898
|
+
});
|
|
899
|
+
remainingAccounts.push({
|
|
900
|
+
pubkey: ownerFeeToken,
|
|
901
|
+
isSigner: false,
|
|
902
|
+
isWritable: true,
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
skipIdempotent = skipIdempotent === undefined ? false : skipIdempotent;
|
|
906
|
+
// @ts-ignore
|
|
907
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
908
|
+
.depositMultipleLamportPdaToken(amounts, skipIdempotent)
|
|
909
|
+
.accounts({
|
|
910
|
+
userPda,
|
|
911
|
+
userPdaLamport,
|
|
912
|
+
payer: userWallet,
|
|
913
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
914
|
+
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
|
|
915
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
916
|
+
systemProgram: web3.SystemProgram.programId,
|
|
917
|
+
})
|
|
918
|
+
.remainingAccounts(remainingAccounts)
|
|
919
|
+
.instruction();
|
|
920
|
+
return ix;
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
withdrawMultipleLamportPdaToken(_a) {
|
|
924
|
+
return __awaiter(this, arguments, void 0, function* ({ userWallet, withdraw, skipIdempotent }) {
|
|
925
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
926
|
+
const userPdaLamport = (0, functions_1.generateUserPdaLamport)(userWallet);
|
|
927
|
+
const remainingAccounts = [];
|
|
928
|
+
withdraw.map((d) => {
|
|
929
|
+
const mint = d.mint;
|
|
930
|
+
const userToken = (0, functions_1.generateAta)(userWallet, d.mint);
|
|
931
|
+
const userPdaToken = (0, functions_1.generateAta)(userPdaLamport, d.mint);
|
|
932
|
+
const ownerFeeToken = (0, functions_1.generateAta)(addresses_1.SITE_FEE_OWNER, d.mint);
|
|
933
|
+
remainingAccounts.push({ pubkey: mint, isSigner: false, isWritable: true });
|
|
934
|
+
remainingAccounts.push({
|
|
935
|
+
pubkey: userToken,
|
|
936
|
+
isSigner: false,
|
|
937
|
+
isWritable: true,
|
|
938
|
+
});
|
|
939
|
+
remainingAccounts.push({
|
|
940
|
+
pubkey: userPdaToken,
|
|
941
|
+
isSigner: false,
|
|
942
|
+
isWritable: true,
|
|
943
|
+
});
|
|
944
|
+
remainingAccounts.push({
|
|
945
|
+
pubkey: ownerFeeToken,
|
|
946
|
+
isSigner: false,
|
|
947
|
+
isWritable: true,
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
skipIdempotent = skipIdempotent === undefined ? false : skipIdempotent;
|
|
951
|
+
// @ts-ignore
|
|
952
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
953
|
+
.withdrawMultipleLamportPdaToken(skipIdempotent)
|
|
954
|
+
.accounts({
|
|
955
|
+
userPda,
|
|
956
|
+
userPdaLamport,
|
|
957
|
+
payer: userWallet,
|
|
958
|
+
hsFeeOwner: addresses_1.SITE_FEE_OWNER,
|
|
959
|
+
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
|
|
960
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
961
|
+
systemProgram: web3.SystemProgram.programId,
|
|
962
|
+
})
|
|
963
|
+
.remainingAccounts(remainingAccounts)
|
|
964
|
+
.instruction();
|
|
965
|
+
return ix;
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
createLimitToken(_a) {
|
|
969
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, payer, userWallet, mint, }) {
|
|
970
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
971
|
+
const tokenProgram = yield util.getTokenProgramForMints(connection, [mint]);
|
|
972
|
+
const limitToken = (0, functions_1.generateLimitToken)(userPda, mint);
|
|
973
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
974
|
+
.createLimitToken()
|
|
975
|
+
.accounts({
|
|
976
|
+
userPda,
|
|
977
|
+
payer,
|
|
978
|
+
authority: userWallet,
|
|
979
|
+
limitToken,
|
|
980
|
+
mint,
|
|
981
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
982
|
+
tokenProgram,
|
|
983
|
+
systemProgram: web3.SystemProgram.programId,
|
|
984
|
+
})
|
|
985
|
+
.instruction();
|
|
986
|
+
return ix;
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
closeLimitToken(_a) {
|
|
990
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet, mint, }) {
|
|
991
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
992
|
+
const tokenProgram = yield util.getTokenProgramForMints(connection, [mint]);
|
|
993
|
+
const limitToken = (0, functions_1.generateLimitToken)(userPda, mint);
|
|
994
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
995
|
+
.closeLimitToken()
|
|
996
|
+
.accounts({
|
|
997
|
+
userPda,
|
|
998
|
+
payer: userWallet,
|
|
999
|
+
authority: userWallet,
|
|
1000
|
+
limitToken,
|
|
1001
|
+
mint,
|
|
1002
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
1003
|
+
tokenProgram,
|
|
1004
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1005
|
+
})
|
|
1006
|
+
.instruction();
|
|
1007
|
+
return ix;
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
fuelDeposit(_a) {
|
|
1011
|
+
return __awaiter(this, arguments, void 0, function* ({ userWallet, amount, }) {
|
|
1012
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
1013
|
+
const fuelAccount = (0, functions_1.generateFuelAccount)(userWallet);
|
|
1014
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1015
|
+
.fuelDeposit(amount)
|
|
1016
|
+
.accounts({
|
|
1017
|
+
userPda,
|
|
1018
|
+
authority: userWallet,
|
|
1019
|
+
fuelAccount,
|
|
1020
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1021
|
+
})
|
|
1022
|
+
.instruction();
|
|
1023
|
+
return ix;
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
fuelWithdraw(connection_1, _a) {
|
|
1027
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userWallet, amount, }) {
|
|
1028
|
+
// Initialize anchor
|
|
1029
|
+
anchor_1.Anchor.initialize(connection);
|
|
1030
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
1031
|
+
const fuelAccount = (0, functions_1.generateFuelAccount)(userWallet);
|
|
1032
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1033
|
+
.fuelWithdraw(amount)
|
|
1034
|
+
.accounts({
|
|
1035
|
+
userPda,
|
|
1036
|
+
authority: userWallet,
|
|
1037
|
+
fuelAccount,
|
|
1038
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1039
|
+
})
|
|
1040
|
+
.instruction();
|
|
1041
|
+
return ix;
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
wrapFromFuel(connection_1, _a) {
|
|
1045
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userWallet, authority, amount, }) {
|
|
1046
|
+
// Initialize anchor
|
|
1047
|
+
anchor_1.Anchor.initialize(connection);
|
|
1048
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
1049
|
+
const fuelAccount = (0, functions_1.generateFuelAccount)(userWallet);
|
|
1050
|
+
const userWrappedSol = (0, functions_1.generateLimitToken)(userPda, WSOL_MINT);
|
|
1051
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1052
|
+
.wrapFromFuel(amount || null)
|
|
1053
|
+
.accounts({
|
|
1054
|
+
userPda,
|
|
1055
|
+
authority,
|
|
1056
|
+
fuelAccount,
|
|
1057
|
+
userWrappedSol,
|
|
1058
|
+
wsolMint: WSOL_MINT,
|
|
1059
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
1060
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1061
|
+
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
|
|
1062
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1063
|
+
})
|
|
1064
|
+
.instruction();
|
|
1065
|
+
return ix;
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
unwrapToFuel(connection_1, _a) {
|
|
1069
|
+
return __awaiter(this, arguments, void 0, function* (connection, { userWallet, authority, }) {
|
|
1070
|
+
// Initialize anchor
|
|
1071
|
+
anchor_1.Anchor.initialize(connection);
|
|
1072
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
1073
|
+
const fuelAccount = (0, functions_1.generateFuelAccount)(userWallet);
|
|
1074
|
+
// Only supports LTA for now
|
|
1075
|
+
const userWrappedSol = (0, functions_1.generateLimitToken)(userPda, WSOL_MINT);
|
|
1076
|
+
// @ts-ignore
|
|
1077
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1078
|
+
.unwrapToFuel()
|
|
1079
|
+
.accounts({
|
|
1080
|
+
userPda,
|
|
1081
|
+
authority,
|
|
1082
|
+
fuelAccount,
|
|
1083
|
+
userWrappedSol,
|
|
1084
|
+
wsolMint: WSOL_MINT,
|
|
1085
|
+
rent: web3.SYSVAR_RENT_PUBKEY,
|
|
1086
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1087
|
+
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
|
|
1088
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1089
|
+
})
|
|
1090
|
+
.instruction();
|
|
1091
|
+
return ix;
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
pumpFunCloseUserVolumeAccumulator(_a) {
|
|
1095
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userPda, authority, eventAuthorityPda, }) {
|
|
1096
|
+
// Initialize anchor
|
|
1097
|
+
anchor_1.Anchor.initialize(connection);
|
|
1098
|
+
// Derive userVolumeAccumulatorAddress using PDA
|
|
1099
|
+
const [userVolumeAccumulatorAddress] = web3.PublicKey.findProgramAddressSync([
|
|
1100
|
+
Buffer.from('user_volume_accumulator'),
|
|
1101
|
+
userPda.toBuffer(),
|
|
1102
|
+
], addresses_1.PUMP_FUN_AMM_PROGRAM);
|
|
1103
|
+
// Generate the instruction using Anchor pattern
|
|
1104
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1105
|
+
.pumpFunCloseUserVolumeAccumulator()
|
|
1106
|
+
.accounts({
|
|
1107
|
+
userPda,
|
|
1108
|
+
hawksightAuthority: addresses_1.HS_AUTHORITY,
|
|
1109
|
+
userVolumeAccumulator: userVolumeAccumulatorAddress,
|
|
1110
|
+
eventAuthority: eventAuthorityPda,
|
|
1111
|
+
pumpFunProgram: addresses_1.PUMP_FUN_AMM_PROGRAM,
|
|
1112
|
+
})
|
|
1113
|
+
.instruction();
|
|
1114
|
+
return ix;
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
meteoraDynamicCpi(_a) {
|
|
1118
|
+
return __awaiter(this, arguments, void 0, function* ({ connection, userWallet, meteoraIx, }) {
|
|
1119
|
+
// Initialize anchor
|
|
1120
|
+
anchor_1.Anchor.initialize(connection);
|
|
1121
|
+
// Generate user PDA
|
|
1122
|
+
const userPda = (0, functions_1.generateUserPda)(userWallet);
|
|
1123
|
+
// Generate dynamic cpi for invoking Meteora DLMM program via HawkFi
|
|
1124
|
+
// The meteoraIx.keys are passed as remaining accounts to the CPI
|
|
1125
|
+
// @ts-ignore
|
|
1126
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1127
|
+
.meteoraDynamicCpi(meteoraIx.data)
|
|
1128
|
+
.accounts({
|
|
1129
|
+
userPda,
|
|
1130
|
+
authority: userWallet,
|
|
1131
|
+
meteoraProgram: addresses_1.METEORA_DLMM_PROGRAM,
|
|
1132
|
+
})
|
|
1133
|
+
.remainingAccounts(meteoraIx.keys)
|
|
1134
|
+
.instruction();
|
|
1135
|
+
return ix;
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
unstakeFromFarm(_a) {
|
|
1139
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, userWallet, farm, strategy, quarry, miner, minerVault, saberFarmRewarder, userPdaLpToken, }) {
|
|
1140
|
+
const user = (0, functions_1.generateUserPda)(userWallet, farm);
|
|
1141
|
+
// @ts-ignore
|
|
1142
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1143
|
+
.unstakeFromFarm(amount)
|
|
1144
|
+
.accounts({
|
|
1145
|
+
farm,
|
|
1146
|
+
user,
|
|
1147
|
+
strategy,
|
|
1148
|
+
authority: userWallet,
|
|
1149
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1150
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1151
|
+
clock: web3.SYSVAR_CLOCK_PUBKEY,
|
|
1152
|
+
saberFarmProgram: addresses_1.QUARRY_MINE_PROGRAM,
|
|
1153
|
+
saberFarm: {
|
|
1154
|
+
quarry,
|
|
1155
|
+
miner,
|
|
1156
|
+
minerVault,
|
|
1157
|
+
},
|
|
1158
|
+
saberFarmRewarder,
|
|
1159
|
+
userPdaLpToken,
|
|
1160
|
+
})
|
|
1161
|
+
.instruction();
|
|
1162
|
+
return ix;
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
saberUnsupplyLiquidity(_a) {
|
|
1166
|
+
return __awaiter(this, arguments, void 0, function* ({ assetIndex, userWallet, farm, userPda, saberSwap, saberAuthority, lpMint, inputLp, quoteReserves, outputUserToken, outputReserve, outputFees, ownerFee, }) {
|
|
1167
|
+
// @ts-ignore
|
|
1168
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1169
|
+
.saberUnsupplyLiquidity(assetIndex)
|
|
1170
|
+
.accounts({
|
|
1171
|
+
saberSwapProgram: addresses_1.SABER_SWAP_PROGRAM,
|
|
1172
|
+
user: {
|
|
1173
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1174
|
+
swapAuthority: saberAuthority,
|
|
1175
|
+
userAuthority: userPda,
|
|
1176
|
+
userWallet,
|
|
1177
|
+
farm,
|
|
1178
|
+
swap: saberSwap,
|
|
1179
|
+
},
|
|
1180
|
+
poolMint: lpMint,
|
|
1181
|
+
inputLp,
|
|
1182
|
+
quoteReserves,
|
|
1183
|
+
output: {
|
|
1184
|
+
userToken: {
|
|
1185
|
+
user: outputUserToken,
|
|
1186
|
+
reserve: outputReserve,
|
|
1187
|
+
},
|
|
1188
|
+
fees: outputFees,
|
|
1189
|
+
ownerFee,
|
|
1190
|
+
},
|
|
1191
|
+
})
|
|
1192
|
+
.instruction();
|
|
1193
|
+
return ix;
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
harvestFromFarm(_a) {
|
|
1197
|
+
return __awaiter(this, arguments, void 0, function* ({ userWallet, farm, strategy, quarry, miner, minerVault, saberFarmRewarder, userPdaLp, userPdaReward, redemptionToken, redemptionVault, redeemer, minterInfo, mintWrapper, minter, claimFeeTokenAccount, ownerFee, }) {
|
|
1198
|
+
const user = (0, functions_1.generateUserPda)(userWallet, farm);
|
|
1199
|
+
// @ts-ignore
|
|
1200
|
+
const ix = yield anchor_1.Anchor.instance().iyfMain.methods
|
|
1201
|
+
.harvestFromFarm()
|
|
1202
|
+
.accounts({
|
|
1203
|
+
farm,
|
|
1204
|
+
user,
|
|
1205
|
+
strategy,
|
|
1206
|
+
authority: userWallet,
|
|
1207
|
+
systemProgram: web3.SystemProgram.programId,
|
|
1208
|
+
tokenProgram: addresses_1.TOKEN_PROGRAM_ID,
|
|
1209
|
+
saberFarmProgram: addresses_1.QUARRY_MINE_PROGRAM,
|
|
1210
|
+
redeemerProgram: addresses_1.REDEEMER_PROGRAM,
|
|
1211
|
+
mintProxyProgram: addresses_1.MINT_PROXY_PROGRAM,
|
|
1212
|
+
saberFarm: {
|
|
1213
|
+
quarry,
|
|
1214
|
+
miner,
|
|
1215
|
+
minerVault,
|
|
1216
|
+
},
|
|
1217
|
+
saberFarmRewarder,
|
|
1218
|
+
userPdaLp,
|
|
1219
|
+
userPdaReward,
|
|
1220
|
+
redemptionMint: addresses_1.SABER_MINT,
|
|
1221
|
+
redemptionToken,
|
|
1222
|
+
redemptionVault,
|
|
1223
|
+
redeemer,
|
|
1224
|
+
mintProxyState: addresses_1.SABER_MINT_PROXY_STATE,
|
|
1225
|
+
proxyMintAuthority: addresses_1.PROXY_MINT_AUTHORITY,
|
|
1226
|
+
minterInfo,
|
|
1227
|
+
mintWrapper,
|
|
1228
|
+
mintWrapperProgram: addresses_1.MINT_WRAPPER_PROGRAM,
|
|
1229
|
+
minter,
|
|
1230
|
+
rewardsTokenMint: addresses_1.SABER_IOU_MINT,
|
|
1231
|
+
claimFeeTokenAccount,
|
|
1232
|
+
ownerFee,
|
|
1233
|
+
})
|
|
1234
|
+
.instruction();
|
|
1235
|
+
return ix;
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
exports.IyfMainIxGenerator = IyfMainIxGenerator;
|