@lavarage/sdk 7.5.2 → 7.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +144 -1
- package/dist/index.d.ts +144 -1
- package/dist/index.js +513 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +512 -29
- package/dist/index.mjs.map +1 -1
- package/idl/referralVault.ts +266 -0
- package/index.ts +505 -29
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -43,7 +43,143 @@ var __async = (__this, __arguments, generator) => {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// index.ts
|
|
46
|
-
import { BN as BN2 } from "@coral-xyz/anchor";
|
|
46
|
+
import { BN as BN2, Program as Program2 } from "@coral-xyz/anchor";
|
|
47
|
+
|
|
48
|
+
// idl/referralVault.ts
|
|
49
|
+
var IDL = {
|
|
50
|
+
"version": "0.1.0",
|
|
51
|
+
"name": "user_vault",
|
|
52
|
+
"instructions": [
|
|
53
|
+
{
|
|
54
|
+
"name": "initializeVault",
|
|
55
|
+
"accounts": [
|
|
56
|
+
{
|
|
57
|
+
"name": "userVault",
|
|
58
|
+
"isMut": true,
|
|
59
|
+
"isSigner": false
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "user",
|
|
63
|
+
"isMut": true,
|
|
64
|
+
"isSigner": true
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "systemProgram",
|
|
68
|
+
"isMut": false,
|
|
69
|
+
"isSigner": false
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"args": []
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "claimSol",
|
|
76
|
+
"accounts": [
|
|
77
|
+
{
|
|
78
|
+
"name": "userVault",
|
|
79
|
+
"isMut": true,
|
|
80
|
+
"isSigner": false
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "signer",
|
|
84
|
+
"isMut": false,
|
|
85
|
+
"isSigner": true
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "recipient",
|
|
89
|
+
"isMut": true,
|
|
90
|
+
"isSigner": false
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "systemProgram",
|
|
94
|
+
"isMut": false,
|
|
95
|
+
"isSigner": false
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"args": [
|
|
99
|
+
{
|
|
100
|
+
"name": "amount",
|
|
101
|
+
"type": "u64"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"name": "claimToken",
|
|
107
|
+
"accounts": [
|
|
108
|
+
{
|
|
109
|
+
"name": "userVault",
|
|
110
|
+
"isMut": false,
|
|
111
|
+
"isSigner": false
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "vaultTokenAccount",
|
|
115
|
+
"isMut": true,
|
|
116
|
+
"isSigner": false
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "recipientTokenAccount",
|
|
120
|
+
"isMut": true,
|
|
121
|
+
"isSigner": false
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "tokenMint",
|
|
125
|
+
"isMut": false,
|
|
126
|
+
"isSigner": false
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "signer",
|
|
130
|
+
"isMut": false,
|
|
131
|
+
"isSigner": true
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"name": "tokenProgram",
|
|
135
|
+
"isMut": false,
|
|
136
|
+
"isSigner": false
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"args": [
|
|
140
|
+
{
|
|
141
|
+
"name": "amount",
|
|
142
|
+
"type": "u64"
|
|
143
|
+
}
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
"accounts": [
|
|
148
|
+
{
|
|
149
|
+
"name": "userVault",
|
|
150
|
+
"type": {
|
|
151
|
+
"kind": "struct",
|
|
152
|
+
"fields": [
|
|
153
|
+
{
|
|
154
|
+
"name": "user",
|
|
155
|
+
"type": "publicKey"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "authority",
|
|
159
|
+
"type": "publicKey"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"name": "bump",
|
|
163
|
+
"type": "u8"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"name": "totalSolClaimed",
|
|
167
|
+
"type": "u64"
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
"errors": [
|
|
174
|
+
{
|
|
175
|
+
"code": 6e3,
|
|
176
|
+
"name": "UnauthorizedClaim",
|
|
177
|
+
"msg": "Unauthorized: Only user or authority can claim"
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// index.ts
|
|
47
183
|
import bs58 from "bs58";
|
|
48
184
|
import {
|
|
49
185
|
AddressLookupTableAccount,
|
|
@@ -1563,7 +1699,7 @@ function getWithdrawalAccessList(lavarageProgram, params) {
|
|
|
1563
1699
|
}
|
|
1564
1700
|
|
|
1565
1701
|
// idl/lavarage.ts
|
|
1566
|
-
var
|
|
1702
|
+
var IDL2 = {
|
|
1567
1703
|
"version": "0.1.0",
|
|
1568
1704
|
"name": "lavarage",
|
|
1569
1705
|
"instructions": [
|
|
@@ -3160,9 +3296,9 @@ var IDL = {
|
|
|
3160
3296
|
// idl/lavaragev2.ts
|
|
3161
3297
|
var lavaragev2_exports = {};
|
|
3162
3298
|
__export(lavaragev2_exports, {
|
|
3163
|
-
IDL: () =>
|
|
3299
|
+
IDL: () => IDL3
|
|
3164
3300
|
});
|
|
3165
|
-
var
|
|
3301
|
+
var IDL3 = {
|
|
3166
3302
|
"version": "0.1.0",
|
|
3167
3303
|
"name": "lavarage",
|
|
3168
3304
|
"instructions": [
|
|
@@ -4850,6 +4986,7 @@ var IDL2 = {
|
|
|
4850
4986
|
};
|
|
4851
4987
|
|
|
4852
4988
|
// index.ts
|
|
4989
|
+
var REFFERAL_VAULT_PROGRAM_ID = new PublicKey2("FFe8xWs9iBdWB6vsxg8yBLirZHsbACFNbXqAM4K3fPPB");
|
|
4853
4990
|
function getPda(seed, programId) {
|
|
4854
4991
|
const seedsBuffer = Array.isArray(seed) ? seed : [seed];
|
|
4855
4992
|
return PublicKey2.findProgramAddressSync(seedsBuffer, programId)[0];
|
|
@@ -4961,8 +5098,325 @@ var getLiquidatedPositions = (lavarageProgram) => {
|
|
|
4961
5098
|
var getAllPositions = (lavarageProgram) => {
|
|
4962
5099
|
return lavarageProgram.account.position.all([{ dataSize: 178 }]);
|
|
4963
5100
|
};
|
|
5101
|
+
var borrowV1 = (lavarageProgram, offer, marginSOL, leverage, randomSeed, tokenProgram, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, discountBps, referralBps, referralVaultProgram) => __async(void 0, null, function* () {
|
|
5102
|
+
let partnerFeeMarkupAsPkey;
|
|
5103
|
+
if (partnerFeeMarkup) {
|
|
5104
|
+
const feeBuffer = Buffer.alloc(8);
|
|
5105
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
5106
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
5107
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
5108
|
+
partnerFeeMarkupAsPkey = new PublicKey2(feeBuffer32);
|
|
5109
|
+
}
|
|
5110
|
+
const positionAccount = getPositionAccountPDA(
|
|
5111
|
+
lavarageProgram,
|
|
5112
|
+
offer,
|
|
5113
|
+
randomSeed.publicKey
|
|
5114
|
+
);
|
|
5115
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
5116
|
+
lavarageProgram,
|
|
5117
|
+
lavarageProgram.provider.publicKey,
|
|
5118
|
+
offer.account.collateralType,
|
|
5119
|
+
tokenProgram
|
|
5120
|
+
);
|
|
5121
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
5122
|
+
lavarageProgram,
|
|
5123
|
+
positionAccount,
|
|
5124
|
+
offer.account.collateralType,
|
|
5125
|
+
tokenProgram
|
|
5126
|
+
);
|
|
5127
|
+
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5128
|
+
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
5129
|
+
let partnerFeeRecipientCreateIx;
|
|
5130
|
+
let userVaultPda;
|
|
5131
|
+
if (partnerFeeRecipient && referralBps !== void 0 && referralVaultProgram) {
|
|
5132
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
5133
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
5134
|
+
referralVaultProgram.programId
|
|
5135
|
+
);
|
|
5136
|
+
const vaultAccountInfo = yield lavarageProgram.provider.connection.getAccountInfo(userVaultPda);
|
|
5137
|
+
if (!vaultAccountInfo) {
|
|
5138
|
+
partnerFeeRecipientCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
5139
|
+
userVault: userVaultPda,
|
|
5140
|
+
user: lavarageProgram.provider.publicKey,
|
|
5141
|
+
systemProgram: SystemProgram2.programId
|
|
5142
|
+
}).instruction();
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
const tradingOpenBorrowInstruction = useReferral ? yield lavarageProgram.methods.tradingOpenBorrowWithReferral(
|
|
5146
|
+
new BN2((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
5147
|
+
marginSOL,
|
|
5148
|
+
new BN2(discountBps),
|
|
5149
|
+
new BN2(referralBps)
|
|
5150
|
+
).accountsStrict({
|
|
5151
|
+
nodeWallet: offer.account.nodeWallet,
|
|
5152
|
+
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5153
|
+
tradingPool: offer.publicKey,
|
|
5154
|
+
positionAccount,
|
|
5155
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5156
|
+
systemProgram: SystemProgram2.programId,
|
|
5157
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
5158
|
+
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
5159
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
5160
|
+
}).remainingAccounts(
|
|
5161
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5162
|
+
{
|
|
5163
|
+
pubkey: userVaultPda,
|
|
5164
|
+
isSigner: false,
|
|
5165
|
+
isWritable: true
|
|
5166
|
+
}
|
|
5167
|
+
] : []
|
|
5168
|
+
).instruction() : yield lavarageProgram.methods.tradingOpenBorrow(
|
|
5169
|
+
new BN2((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
5170
|
+
marginSOL
|
|
5171
|
+
).accountsStrict({
|
|
5172
|
+
nodeWallet: offer.account.nodeWallet,
|
|
5173
|
+
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5174
|
+
tradingPool: offer.publicKey,
|
|
5175
|
+
positionAccount,
|
|
5176
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5177
|
+
systemProgram: SystemProgram2.programId,
|
|
5178
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
5179
|
+
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
5180
|
+
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
5181
|
+
}).remainingAccounts(
|
|
5182
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
5183
|
+
{
|
|
5184
|
+
pubkey: partnerFeeRecipient,
|
|
5185
|
+
isSigner: false,
|
|
5186
|
+
isWritable: true
|
|
5187
|
+
},
|
|
5188
|
+
{
|
|
5189
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
5190
|
+
isSigner: false,
|
|
5191
|
+
isWritable: false
|
|
5192
|
+
}
|
|
5193
|
+
] : []
|
|
5194
|
+
).instruction();
|
|
5195
|
+
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
|
|
5196
|
+
tradingPool: offer.publicKey,
|
|
5197
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5198
|
+
mint: offer.account.collateralType,
|
|
5199
|
+
toTokenAccount: toTokenAccount.account.address,
|
|
5200
|
+
systemProgram: SystemProgram2.programId,
|
|
5201
|
+
positionAccount,
|
|
5202
|
+
randomAccountAsId: randomSeed.publicKey.toBase58()
|
|
5203
|
+
}).instruction();
|
|
5204
|
+
const computeFeeIx = ComputeBudgetProgram2.setComputeUnitPrice({
|
|
5205
|
+
microLamports: computeBudgetMicroLamports != null ? computeBudgetMicroLamports : 1e5
|
|
5206
|
+
});
|
|
5207
|
+
const allInstructions = [
|
|
5208
|
+
fromTokenAccount.instruction,
|
|
5209
|
+
toTokenAccount.instruction,
|
|
5210
|
+
partnerFeeRecipientCreateIx,
|
|
5211
|
+
tradingOpenBorrowInstruction,
|
|
5212
|
+
openAddCollateralInstruction,
|
|
5213
|
+
computeBudgetMicroLamports ? computeFeeIx : void 0
|
|
5214
|
+
].filter(Boolean);
|
|
5215
|
+
const messageV0 = new TransactionMessage2({
|
|
5216
|
+
payerKey: lavarageProgram.provider.publicKey,
|
|
5217
|
+
recentBlockhash: blockhash,
|
|
5218
|
+
instructions: allInstructions
|
|
5219
|
+
}).compileToV0Message();
|
|
5220
|
+
const tx = new VersionedTransaction2(messageV0);
|
|
5221
|
+
return tx;
|
|
5222
|
+
});
|
|
5223
|
+
var borrowV2 = (lavarageProgram, offer, marginSOL, leverage, randomSeed, quoteToken, tokenProgram, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, discountBps, referralBps, referralVaultProgram) => __async(void 0, null, function* () {
|
|
5224
|
+
let partnerFeeMarkupAsPkey;
|
|
5225
|
+
if (partnerFeeMarkup) {
|
|
5226
|
+
const feeBuffer = Buffer.alloc(8);
|
|
5227
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
5228
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
5229
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
5230
|
+
partnerFeeMarkupAsPkey = new PublicKey2(feeBuffer32);
|
|
5231
|
+
}
|
|
5232
|
+
const positionAccount = getPositionAccountPDA(
|
|
5233
|
+
lavarageProgram,
|
|
5234
|
+
offer,
|
|
5235
|
+
randomSeed.publicKey
|
|
5236
|
+
);
|
|
5237
|
+
const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
|
|
5238
|
+
const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
|
|
5239
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
5240
|
+
lavarageProgram,
|
|
5241
|
+
lavarageProgram.provider.publicKey,
|
|
5242
|
+
offer.account.collateralType,
|
|
5243
|
+
tokenProgram
|
|
5244
|
+
);
|
|
5245
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
5246
|
+
lavarageProgram,
|
|
5247
|
+
positionAccount,
|
|
5248
|
+
offer.account.collateralType,
|
|
5249
|
+
tokenProgram
|
|
5250
|
+
);
|
|
5251
|
+
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5252
|
+
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
5253
|
+
let partnerFeeRecipientVaultCreateIx;
|
|
5254
|
+
let partnerFeeRecipientTokenAccountCreateIx;
|
|
5255
|
+
let userVaultPda;
|
|
5256
|
+
if (partnerFeeRecipient && partnerFeeMarkupAsPkey && referralVaultProgram) {
|
|
5257
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
5258
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
5259
|
+
referralVaultProgram.programId
|
|
5260
|
+
);
|
|
5261
|
+
const vaultTokenAccount = getAssociatedTokenAddressSync2(
|
|
5262
|
+
quoteToken,
|
|
5263
|
+
userVaultPda,
|
|
5264
|
+
true,
|
|
5265
|
+
// allowOwnerOffCurve for PDA
|
|
5266
|
+
quoteTokenProgram
|
|
5267
|
+
);
|
|
5268
|
+
const [vaultAccountInfo, vaultTokenAccountInfo] = yield lavarageProgram.provider.connection.getMultipleAccountsInfo([
|
|
5269
|
+
userVaultPda,
|
|
5270
|
+
vaultTokenAccount
|
|
5271
|
+
]);
|
|
5272
|
+
if (!vaultAccountInfo) {
|
|
5273
|
+
partnerFeeRecipientVaultCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
5274
|
+
userVault: userVaultPda,
|
|
5275
|
+
user: lavarageProgram.provider.publicKey,
|
|
5276
|
+
systemProgram: SystemProgram2.programId
|
|
5277
|
+
}).instruction();
|
|
5278
|
+
}
|
|
5279
|
+
if (!vaultTokenAccountInfo) {
|
|
5280
|
+
partnerFeeRecipientTokenAccountCreateIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
5281
|
+
lavarageProgram.provider.publicKey,
|
|
5282
|
+
vaultTokenAccount,
|
|
5283
|
+
userVaultPda,
|
|
5284
|
+
quoteToken,
|
|
5285
|
+
quoteTokenProgram,
|
|
5286
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
5287
|
+
);
|
|
5288
|
+
}
|
|
5289
|
+
}
|
|
5290
|
+
const tradingOpenBorrowInstruction = useReferral ? yield lavarageProgram.methods.tradingOpenBorrowWithReferral(
|
|
5291
|
+
new BN2((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
5292
|
+
marginSOL,
|
|
5293
|
+
new BN2(discountBps),
|
|
5294
|
+
new BN2(referralBps)
|
|
5295
|
+
).accountsStrict({
|
|
5296
|
+
nodeWallet: offer.account.nodeWallet,
|
|
5297
|
+
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5298
|
+
tradingPool: offer.publicKey,
|
|
5299
|
+
positionAccount,
|
|
5300
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5301
|
+
systemProgram: SystemProgram2.programId,
|
|
5302
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
5303
|
+
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
5304
|
+
feeTokenAccount: getAssociatedTokenAddressSync2(
|
|
5305
|
+
quoteToken,
|
|
5306
|
+
new PublicKey2("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
5307
|
+
true,
|
|
5308
|
+
quoteTokenProgram
|
|
5309
|
+
),
|
|
5310
|
+
toTokenAccount: getAssociatedTokenAddressSync2(
|
|
5311
|
+
quoteToken,
|
|
5312
|
+
lavarageProgram.provider.publicKey,
|
|
5313
|
+
true,
|
|
5314
|
+
quoteTokenProgram
|
|
5315
|
+
),
|
|
5316
|
+
tokenProgram: quoteTokenProgram,
|
|
5317
|
+
fromTokenAccount: getAssociatedTokenAddressSync2(
|
|
5318
|
+
quoteToken,
|
|
5319
|
+
offer.account.nodeWallet,
|
|
5320
|
+
true,
|
|
5321
|
+
quoteTokenProgram
|
|
5322
|
+
)
|
|
5323
|
+
}).remainingAccounts(
|
|
5324
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5325
|
+
{
|
|
5326
|
+
pubkey: getAssociatedTokenAddressSync2(
|
|
5327
|
+
quoteToken,
|
|
5328
|
+
userVaultPda,
|
|
5329
|
+
true,
|
|
5330
|
+
// allowOwnerOffCurve for PDA
|
|
5331
|
+
quoteTokenProgram
|
|
5332
|
+
),
|
|
5333
|
+
isSigner: false,
|
|
5334
|
+
isWritable: true
|
|
5335
|
+
}
|
|
5336
|
+
] : []
|
|
5337
|
+
).instruction() : yield lavarageProgram.methods.tradingOpenBorrow(
|
|
5338
|
+
new BN2((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
5339
|
+
marginSOL
|
|
5340
|
+
).accountsStrict({
|
|
5341
|
+
nodeWallet: offer.account.nodeWallet,
|
|
5342
|
+
instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
5343
|
+
tradingPool: offer.publicKey,
|
|
5344
|
+
positionAccount,
|
|
5345
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5346
|
+
systemProgram: SystemProgram2.programId,
|
|
5347
|
+
clock: SYSVAR_CLOCK_PUBKEY,
|
|
5348
|
+
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
5349
|
+
feeTokenAccount: getAssociatedTokenAddressSync2(
|
|
5350
|
+
quoteToken,
|
|
5351
|
+
new PublicKey2("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
5352
|
+
true,
|
|
5353
|
+
quoteTokenProgram
|
|
5354
|
+
),
|
|
5355
|
+
toTokenAccount: getAssociatedTokenAddressSync2(
|
|
5356
|
+
quoteToken,
|
|
5357
|
+
lavarageProgram.provider.publicKey,
|
|
5358
|
+
true,
|
|
5359
|
+
quoteTokenProgram
|
|
5360
|
+
),
|
|
5361
|
+
tokenProgram: quoteTokenProgram,
|
|
5362
|
+
fromTokenAccount: getAssociatedTokenAddressSync2(
|
|
5363
|
+
quoteToken,
|
|
5364
|
+
offer.account.nodeWallet,
|
|
5365
|
+
true,
|
|
5366
|
+
quoteTokenProgram
|
|
5367
|
+
)
|
|
5368
|
+
}).remainingAccounts(
|
|
5369
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5370
|
+
{
|
|
5371
|
+
pubkey: getAssociatedTokenAddressSync2(
|
|
5372
|
+
quoteToken,
|
|
5373
|
+
userVaultPda,
|
|
5374
|
+
true,
|
|
5375
|
+
// allowOwnerOffCurve for PDA
|
|
5376
|
+
quoteTokenProgram
|
|
5377
|
+
),
|
|
5378
|
+
isSigner: false,
|
|
5379
|
+
isWritable: true
|
|
5380
|
+
},
|
|
5381
|
+
{
|
|
5382
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
5383
|
+
isSigner: false,
|
|
5384
|
+
isWritable: false
|
|
5385
|
+
}
|
|
5386
|
+
] : []
|
|
5387
|
+
).instruction();
|
|
5388
|
+
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate < 255 ? offer.account.interestRate + 1 : 255).accountsStrict({
|
|
5389
|
+
tradingPool: offer.publicKey,
|
|
5390
|
+
trader: lavarageProgram.provider.publicKey,
|
|
5391
|
+
mint: offer.account.collateralType,
|
|
5392
|
+
toTokenAccount: toTokenAccount.account.address,
|
|
5393
|
+
systemProgram: SystemProgram2.programId,
|
|
5394
|
+
positionAccount,
|
|
5395
|
+
randomAccountAsId: randomSeed.publicKey.toBase58()
|
|
5396
|
+
}).instruction();
|
|
5397
|
+
const computeFeeIx = ComputeBudgetProgram2.setComputeUnitPrice({
|
|
5398
|
+
microLamports: computeBudgetMicroLamports != null ? computeBudgetMicroLamports : 1e5
|
|
5399
|
+
});
|
|
5400
|
+
const allInstructions = [
|
|
5401
|
+
fromTokenAccount.instruction,
|
|
5402
|
+
toTokenAccount.instruction,
|
|
5403
|
+
partnerFeeRecipientVaultCreateIx,
|
|
5404
|
+
partnerFeeRecipientTokenAccountCreateIx,
|
|
5405
|
+
tradingOpenBorrowInstruction,
|
|
5406
|
+
openAddCollateralInstruction,
|
|
5407
|
+
computeBudgetMicroLamports ? computeFeeIx : void 0
|
|
5408
|
+
].filter(Boolean);
|
|
5409
|
+
const messageV0 = new TransactionMessage2({
|
|
5410
|
+
payerKey: lavarageProgram.provider.publicKey,
|
|
5411
|
+
recentBlockhash: blockhash,
|
|
5412
|
+
instructions: allInstructions
|
|
5413
|
+
}).compileToV0Message();
|
|
5414
|
+
const tx = new VersionedTransaction2(messageV0);
|
|
5415
|
+
return tx;
|
|
5416
|
+
});
|
|
4964
5417
|
var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, tokenProgram, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions, discountBps, referralBps) => __async(void 0, null, function* () {
|
|
4965
5418
|
let partnerFeeMarkupAsPkey;
|
|
5419
|
+
const referralVaultProgram = new Program2(IDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
4966
5420
|
if (partnerFeeMarkup) {
|
|
4967
5421
|
const feeBuffer = Buffer.alloc(8);
|
|
4968
5422
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -5048,14 +5502,19 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5048
5502
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5049
5503
|
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
5050
5504
|
let partnerFeeRecipientCreateIx;
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5505
|
+
let userVaultPda;
|
|
5506
|
+
if (partnerFeeRecipient && referralBps !== void 0 && referralVaultProgram) {
|
|
5507
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
5508
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
5509
|
+
referralVaultProgram.programId
|
|
5510
|
+
);
|
|
5511
|
+
const vaultAccountInfo = yield lavarageProgram.provider.connection.getAccountInfo(userVaultPda);
|
|
5512
|
+
if (!vaultAccountInfo) {
|
|
5513
|
+
partnerFeeRecipientCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
5514
|
+
userVault: userVaultPda,
|
|
5515
|
+
user: lavarageProgram.provider.publicKey,
|
|
5516
|
+
systemProgram: SystemProgram2.programId
|
|
5517
|
+
}).instruction();
|
|
5059
5518
|
}
|
|
5060
5519
|
}
|
|
5061
5520
|
const tradingOpenBorrowInstruction = useReferral ? yield lavarageProgram.methods.tradingOpenBorrowWithReferral(
|
|
@@ -5074,9 +5533,9 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5074
5533
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
5075
5534
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
5076
5535
|
}).remainingAccounts(
|
|
5077
|
-
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
5536
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5078
5537
|
{
|
|
5079
|
-
pubkey:
|
|
5538
|
+
pubkey: userVaultPda,
|
|
5080
5539
|
isSigner: false,
|
|
5081
5540
|
isWritable: true
|
|
5082
5541
|
}
|
|
@@ -5171,6 +5630,7 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5171
5630
|
});
|
|
5172
5631
|
var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, tokenProgram, partnerFeeRecipient, partnerFeeMarkup, computeBudgetMicroLamports, platformFeeRecipient, splitTransactions, discountBps, referralBps) => __async(void 0, null, function* () {
|
|
5173
5632
|
let partnerFeeMarkupAsPkey;
|
|
5633
|
+
const referralVaultProgram = new Program2(IDL, REFFERAL_VAULT_PROGRAM_ID, lavarageProgram.provider);
|
|
5174
5634
|
if (partnerFeeMarkup) {
|
|
5175
5635
|
const feeBuffer = Buffer.alloc(8);
|
|
5176
5636
|
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
@@ -5258,20 +5718,37 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5258
5718
|
);
|
|
5259
5719
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
5260
5720
|
const useReferral = discountBps !== void 0 && referralBps !== void 0;
|
|
5721
|
+
let partnerFeeRecipientVaultCreateIx;
|
|
5261
5722
|
let partnerFeeRecipientTokenAccountCreateIx;
|
|
5262
|
-
|
|
5263
|
-
|
|
5723
|
+
let userVaultPda;
|
|
5724
|
+
if (partnerFeeRecipient && partnerFeeMarkupAsPkey && referralVaultProgram) {
|
|
5725
|
+
[userVaultPda] = PublicKey2.findProgramAddressSync(
|
|
5726
|
+
[Buffer.from("user_vault"), new PublicKey2(partnerFeeRecipient).toBuffer()],
|
|
5727
|
+
referralVaultProgram.programId
|
|
5728
|
+
);
|
|
5729
|
+
const vaultTokenAccount = getAssociatedTokenAddressSync2(
|
|
5264
5730
|
quoteToken,
|
|
5265
|
-
|
|
5266
|
-
|
|
5731
|
+
userVaultPda,
|
|
5732
|
+
true,
|
|
5733
|
+
// allowOwnerOffCurve for PDA
|
|
5267
5734
|
quoteTokenProgram
|
|
5268
5735
|
);
|
|
5269
|
-
const
|
|
5270
|
-
|
|
5736
|
+
const [vaultAccountInfo, vaultTokenAccountInfo] = yield lavarageProgram.provider.connection.getMultipleAccountsInfo([
|
|
5737
|
+
userVaultPda,
|
|
5738
|
+
vaultTokenAccount
|
|
5739
|
+
]);
|
|
5740
|
+
if (!vaultAccountInfo) {
|
|
5741
|
+
partnerFeeRecipientVaultCreateIx = yield referralVaultProgram.methods.initializeVault().accountsStrict({
|
|
5742
|
+
userVault: userVaultPda,
|
|
5743
|
+
user: lavarageProgram.provider.publicKey,
|
|
5744
|
+
systemProgram: SystemProgram2.programId
|
|
5745
|
+
}).instruction();
|
|
5746
|
+
}
|
|
5747
|
+
if (!vaultTokenAccountInfo) {
|
|
5271
5748
|
partnerFeeRecipientTokenAccountCreateIx = createAssociatedTokenAccountIdempotentInstruction2(
|
|
5272
5749
|
lavarageProgram.provider.publicKey,
|
|
5273
|
-
|
|
5274
|
-
|
|
5750
|
+
vaultTokenAccount,
|
|
5751
|
+
userVaultPda,
|
|
5275
5752
|
quoteToken,
|
|
5276
5753
|
quoteTokenProgram,
|
|
5277
5754
|
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
@@ -5312,12 +5789,13 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5312
5789
|
quoteTokenProgram
|
|
5313
5790
|
)
|
|
5314
5791
|
}).remainingAccounts(
|
|
5315
|
-
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
5792
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5316
5793
|
{
|
|
5317
5794
|
pubkey: getAssociatedTokenAddressSync2(
|
|
5318
5795
|
quoteToken,
|
|
5319
|
-
|
|
5320
|
-
|
|
5796
|
+
userVaultPda,
|
|
5797
|
+
true,
|
|
5798
|
+
// allowOwnerOffCurve for PDA
|
|
5321
5799
|
quoteTokenProgram
|
|
5322
5800
|
),
|
|
5323
5801
|
isSigner: false,
|
|
@@ -5356,12 +5834,13 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5356
5834
|
quoteTokenProgram
|
|
5357
5835
|
)
|
|
5358
5836
|
}).remainingAccounts(
|
|
5359
|
-
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
5837
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey && userVaultPda ? [
|
|
5360
5838
|
{
|
|
5361
5839
|
pubkey: getAssociatedTokenAddressSync2(
|
|
5362
5840
|
quoteToken,
|
|
5363
|
-
|
|
5364
|
-
|
|
5841
|
+
userVaultPda,
|
|
5842
|
+
true,
|
|
5843
|
+
// allowOwnerOffCurve for PDA
|
|
5365
5844
|
quoteTokenProgram
|
|
5366
5845
|
),
|
|
5367
5846
|
isSigner: false,
|
|
@@ -5394,6 +5873,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5394
5873
|
const setUpInstructions = [
|
|
5395
5874
|
fromTokenAccount.instruction,
|
|
5396
5875
|
toTokenAccount.instruction,
|
|
5876
|
+
partnerFeeRecipientVaultCreateIx,
|
|
5397
5877
|
partnerFeeRecipientTokenAccountCreateIx,
|
|
5398
5878
|
...setupInstructions.map(deserializeInstruction)
|
|
5399
5879
|
].filter(Boolean);
|
|
@@ -5421,6 +5901,7 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
5421
5901
|
const allInstructions = [
|
|
5422
5902
|
fromTokenAccount.instruction,
|
|
5423
5903
|
toTokenAccount.instruction,
|
|
5904
|
+
partnerFeeRecipientVaultCreateIx,
|
|
5424
5905
|
partnerFeeRecipientTokenAccountCreateIx,
|
|
5425
5906
|
tradingOpenBorrowInstruction,
|
|
5426
5907
|
...jupiterIxs,
|
|
@@ -6264,8 +6745,10 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken,
|
|
|
6264
6745
|
return tx;
|
|
6265
6746
|
});
|
|
6266
6747
|
export {
|
|
6267
|
-
IDL,
|
|
6748
|
+
IDL2 as IDL,
|
|
6268
6749
|
lavaragev2_exports as IDLV2,
|
|
6750
|
+
borrowV1,
|
|
6751
|
+
borrowV2,
|
|
6269
6752
|
closePositionEvm,
|
|
6270
6753
|
closeTradeV1,
|
|
6271
6754
|
closeTradeV2,
|