@telaro/sdk 0.1.0
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/CHANGELOG.md +27 -0
- package/QUICKSTART.md +216 -0
- package/README.md +129 -0
- package/dist/accounts.d.ts +51 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +169 -0
- package/dist/accounts.js.map +1 -0
- package/dist/api.d.ts +177 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +158 -0
- package/dist/api.js.map +1 -0
- package/dist/borsh.d.ts +33 -0
- package/dist/borsh.d.ts.map +1 -0
- package/dist/borsh.js +100 -0
- package/dist/borsh.js.map +1 -0
- package/dist/client.d.ts +70 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +164 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +46 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/constants.js.map +1 -0
- package/dist/credit.d.ts +61 -0
- package/dist/credit.d.ts.map +1 -0
- package/dist/credit.js +133 -0
- package/dist/credit.js.map +1 -0
- package/dist/decimal.d.ts +36 -0
- package/dist/decimal.d.ts.map +1 -0
- package/dist/decimal.js +87 -0
- package/dist/decimal.js.map +1 -0
- package/dist/discriminators.d.ts +86 -0
- package/dist/discriminators.d.ts.map +1 -0
- package/dist/discriminators.js +100 -0
- package/dist/discriminators.js.map +1 -0
- package/dist/events.d.ts +268 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +223 -0
- package/dist/events.js.map +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +39 -0
- package/dist/format.js.map +1 -0
- package/dist/hash.d.ts +9 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +33 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +368 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +841 -0
- package/dist/instructions.js.map +1 -0
- package/dist/metaplex.d.ts +64 -0
- package/dist/metaplex.d.ts.map +1 -0
- package/dist/metaplex.js +123 -0
- package/dist/metaplex.js.map +1 -0
- package/dist/pda.d.ts +35 -0
- package/dist/pda.d.ts.map +1 -0
- package/dist/pda.js +84 -0
- package/dist/pda.js.map +1 -0
- package/dist/realtime.d.ts +67 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +112 -0
- package/dist/realtime.js.map +1 -0
- package/dist/score.d.ts +51 -0
- package/dist/score.d.ts.map +1 -0
- package/dist/score.js +63 -0
- package/dist/score.js.map +1 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +51 -0
- package/dist/types.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,841 @@
|
|
|
1
|
+
import { SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction, } from "@solana/web3.js";
|
|
2
|
+
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
3
|
+
import { PROGRAM_ID } from "./constants.js";
|
|
4
|
+
import { INSTRUCTION_DISC } from "./discriminators.js";
|
|
5
|
+
import { findActionLogPda, findAgentPda, findBondVaultPda, findCapabilityRegistryPda, findClaimPda, findCreditLinePda, findDepositVaultPda, findLpPositionPda, findPoolConfigPda, findPoolMintAuthPda, findPoolStusdcMintPda, findPoolVaultPda, findProtocolConfigPda, findScoreFeedPda, findTsusdcConfigPda, findTsusdcMintAuthPda, findTsusdcMintPda, LP_KIND_KAMINO, LP_KIND_MARGINFI, } from "./pda.js";
|
|
6
|
+
function writeString(s) {
|
|
7
|
+
const data = Buffer.from(s, "utf8");
|
|
8
|
+
const out = Buffer.alloc(4 + data.length);
|
|
9
|
+
out.writeUInt32LE(data.length, 0);
|
|
10
|
+
data.copy(out, 4);
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
function u64LE(v) {
|
|
14
|
+
const buf = Buffer.alloc(8);
|
|
15
|
+
buf.writeBigUInt64LE(v, 0);
|
|
16
|
+
return buf;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Step 1 of registration. Creates the Agent + ActionLog accounts. The agent
|
|
20
|
+
* is born frozen — it can't `record_action` until step 2 (`bond_agent`)
|
|
21
|
+
* posts a bond. Pair both ix in the same transaction for atomic registration.
|
|
22
|
+
*/
|
|
23
|
+
export function buildInitAgentIx(accounts, args, programId = PROGRAM_ID) {
|
|
24
|
+
const [agent] = findAgentPda(accounts.controller, programId);
|
|
25
|
+
const [log] = findActionLogPda(agent, programId);
|
|
26
|
+
const data = Buffer.concat([
|
|
27
|
+
INSTRUCTION_DISC.initAgent,
|
|
28
|
+
writeString(args.framework),
|
|
29
|
+
writeString(args.metadataUri),
|
|
30
|
+
args.scorer.toBuffer(),
|
|
31
|
+
args.bondMint.toBuffer(),
|
|
32
|
+
]);
|
|
33
|
+
return new TransactionInstruction({
|
|
34
|
+
programId,
|
|
35
|
+
keys: [
|
|
36
|
+
{ pubkey: agent, isSigner: false, isWritable: true },
|
|
37
|
+
{ pubkey: log, isSigner: false, isWritable: true },
|
|
38
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: true },
|
|
39
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
40
|
+
],
|
|
41
|
+
data,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Step 2 of registration (or a top-up later on). Initializes the bond vault
|
|
46
|
+
* if it doesn't exist yet, transfers USDC, and unfreezes the agent if its
|
|
47
|
+
* bond ≥ MIN_BOND_USDC.
|
|
48
|
+
*/
|
|
49
|
+
export function buildBondAgentIx(accounts, amount, programId = PROGRAM_ID) {
|
|
50
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
51
|
+
const data = Buffer.concat([INSTRUCTION_DISC.bondAgent, u64LE(amount)]);
|
|
52
|
+
return new TransactionInstruction({
|
|
53
|
+
programId,
|
|
54
|
+
keys: [
|
|
55
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
56
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
57
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
58
|
+
{ pubkey: accounts.payerBondAta, isSigner: false, isWritable: true },
|
|
59
|
+
{ pubkey: accounts.payer, isSigner: true, isWritable: true },
|
|
60
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
61
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
62
|
+
],
|
|
63
|
+
data,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function buildFullAgentSetup(args, programId = PROGRAM_ID) {
|
|
67
|
+
const ixs = [];
|
|
68
|
+
const [initIx, bondIx] = buildRegisterAndBondIxs({
|
|
69
|
+
controller: args.controller,
|
|
70
|
+
controllerBondAta: args.controllerBondAta,
|
|
71
|
+
framework: args.framework,
|
|
72
|
+
metadataUri: args.metadataUri,
|
|
73
|
+
scorer: args.scorer,
|
|
74
|
+
bondMint: args.bondMint,
|
|
75
|
+
bondAmount: args.bondAmount,
|
|
76
|
+
}, programId);
|
|
77
|
+
ixs.push(initIx, bondIx);
|
|
78
|
+
if (!args.marginfi) {
|
|
79
|
+
return { ixs, marginfiAccountKeypair: null };
|
|
80
|
+
}
|
|
81
|
+
// Need a fresh keypair for the new MarginfiAccount. Caller signs the
|
|
82
|
+
// tx with this in addition to controller.
|
|
83
|
+
const { Keypair } = require("@solana/web3.js");
|
|
84
|
+
const marginfiAccountKp = Keypair.generate();
|
|
85
|
+
const [agent] = findAgentPda(args.controller, programId);
|
|
86
|
+
const [bondVault] = findBondVaultPda(agent, programId);
|
|
87
|
+
ixs.push(buildInitMarginfiAccountIx({
|
|
88
|
+
agent,
|
|
89
|
+
marginfiAccount: marginfiAccountKp.publicKey,
|
|
90
|
+
bondVaultMintWitness: bondVault,
|
|
91
|
+
marginfiGroup: args.marginfi.marginfiGroup,
|
|
92
|
+
marginfiProgram: args.marginfi.marginfiProgram,
|
|
93
|
+
feePayer: args.controller,
|
|
94
|
+
}, programId));
|
|
95
|
+
ixs.push(buildInitLpPositionIx({ agent, payer: args.controller }, LP_KIND_MARGINFI, args.marginfi.yieldRouter, marginfiAccountKp.publicKey, args.marginfi.marginfiBank, programId));
|
|
96
|
+
return { ixs, marginfiAccountKeypair: marginfiAccountKp };
|
|
97
|
+
}
|
|
98
|
+
export function buildRecordActionIx(controller, args, programId = PROGRAM_ID) {
|
|
99
|
+
const [agent] = findAgentPda(controller, programId);
|
|
100
|
+
const [log] = findActionLogPda(agent, programId);
|
|
101
|
+
if (args.actionHash.length !== 32) {
|
|
102
|
+
throw new Error("actionHash must be 32 bytes");
|
|
103
|
+
}
|
|
104
|
+
const data = Buffer.concat([
|
|
105
|
+
INSTRUCTION_DISC.recordAction,
|
|
106
|
+
Buffer.from(args.actionHash),
|
|
107
|
+
Buffer.from([args.kind & 0xff]),
|
|
108
|
+
Buffer.from([args.outcome & 0xff]),
|
|
109
|
+
u64LE(args.valueAtomic),
|
|
110
|
+
]);
|
|
111
|
+
return new TransactionInstruction({
|
|
112
|
+
programId,
|
|
113
|
+
keys: [
|
|
114
|
+
{ pubkey: agent, isSigner: false, isWritable: true },
|
|
115
|
+
{ pubkey: log, isSigner: false, isWritable: true },
|
|
116
|
+
{ pubkey: controller, isSigner: true, isWritable: false },
|
|
117
|
+
],
|
|
118
|
+
data,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
export function buildTopUpIx(accounts, amount, programId = PROGRAM_ID) {
|
|
122
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
123
|
+
const data = Buffer.concat([INSTRUCTION_DISC.topUpBond, u64LE(amount)]);
|
|
124
|
+
return new TransactionInstruction({
|
|
125
|
+
programId,
|
|
126
|
+
keys: [
|
|
127
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
128
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
129
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
130
|
+
{ pubkey: accounts.payerBondAta, isSigner: false, isWritable: true },
|
|
131
|
+
{ pubkey: accounts.payer, isSigner: true, isWritable: true },
|
|
132
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
133
|
+
],
|
|
134
|
+
data,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export function buildSubmitClaimIx(accounts, args, programId = PROGRAM_ID) {
|
|
138
|
+
if (args.actionHash.length !== 32) {
|
|
139
|
+
throw new Error("actionHash must be 32 bytes");
|
|
140
|
+
}
|
|
141
|
+
const [claim] = findClaimPda(accounts.agent, args.actionHash, accounts.claimer, programId);
|
|
142
|
+
const [deposit] = findDepositVaultPda(claim, programId);
|
|
143
|
+
const data = Buffer.concat([
|
|
144
|
+
INSTRUCTION_DISC.submitClaim,
|
|
145
|
+
Buffer.from(args.actionHash),
|
|
146
|
+
u64LE(args.claimedAmount),
|
|
147
|
+
writeString(args.evidenceUri),
|
|
148
|
+
]);
|
|
149
|
+
return new TransactionInstruction({
|
|
150
|
+
programId,
|
|
151
|
+
keys: [
|
|
152
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
153
|
+
{ pubkey: claim, isSigner: false, isWritable: true },
|
|
154
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
155
|
+
{ pubkey: deposit, isSigner: false, isWritable: true },
|
|
156
|
+
{ pubkey: accounts.claimerBondAta, isSigner: false, isWritable: true },
|
|
157
|
+
{ pubkey: accounts.claimer, isSigner: true, isWritable: true },
|
|
158
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
159
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
160
|
+
],
|
|
161
|
+
data,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Convenience: build the two ix needed for full registration. Pack both into
|
|
166
|
+
* a single Transaction for atomic register-and-bond.
|
|
167
|
+
*/
|
|
168
|
+
export function buildRegisterAndBondIxs(args, programId = PROGRAM_ID) {
|
|
169
|
+
const [agent] = findAgentPda(args.controller, programId);
|
|
170
|
+
const initIx = buildInitAgentIx({ controller: args.controller }, {
|
|
171
|
+
framework: args.framework,
|
|
172
|
+
metadataUri: args.metadataUri,
|
|
173
|
+
scorer: args.scorer,
|
|
174
|
+
bondMint: args.bondMint,
|
|
175
|
+
}, programId);
|
|
176
|
+
const bondIx = buildBondAgentIx({
|
|
177
|
+
agent,
|
|
178
|
+
bondMint: args.bondMint,
|
|
179
|
+
payer: args.controller,
|
|
180
|
+
payerBondAta: args.controllerBondAta,
|
|
181
|
+
}, args.bondAmount, programId);
|
|
182
|
+
return [initIx, bondIx];
|
|
183
|
+
}
|
|
184
|
+
export function buildResolveClaimIx(accounts, action, programId = PROGRAM_ID) {
|
|
185
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
186
|
+
const [deposit] = findDepositVaultPda(accounts.claim, programId);
|
|
187
|
+
const data = Buffer.concat([
|
|
188
|
+
INSTRUCTION_DISC.resolveClaim,
|
|
189
|
+
Buffer.from([action & 0xff]),
|
|
190
|
+
]);
|
|
191
|
+
return new TransactionInstruction({
|
|
192
|
+
programId,
|
|
193
|
+
keys: [
|
|
194
|
+
{ pubkey: accounts.claim, isSigner: false, isWritable: true },
|
|
195
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
196
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
197
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
198
|
+
{ pubkey: deposit, isSigner: false, isWritable: true },
|
|
199
|
+
{ pubkey: accounts.claimerBondAta, isSigner: false, isWritable: true },
|
|
200
|
+
{ pubkey: accounts.signer, isSigner: true, isWritable: false },
|
|
201
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
202
|
+
],
|
|
203
|
+
data,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
export function buildUpdateScoreIx(agent, scorer, args, programId = PROGRAM_ID) {
|
|
207
|
+
const data = Buffer.alloc(8 + 2 + 4);
|
|
208
|
+
INSTRUCTION_DISC.updateScore.copy(data, 0);
|
|
209
|
+
data.writeUInt16LE(args.newScore, 8);
|
|
210
|
+
data.writeUInt32LE(args.bondRatioBps, 10);
|
|
211
|
+
return new TransactionInstruction({
|
|
212
|
+
programId,
|
|
213
|
+
keys: [
|
|
214
|
+
{ pubkey: agent, isSigner: false, isWritable: true },
|
|
215
|
+
{ pubkey: scorer, isSigner: true, isWritable: false },
|
|
216
|
+
],
|
|
217
|
+
data,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
export function buildWithdrawBondIx(accounts, amount, programId = PROGRAM_ID) {
|
|
221
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
222
|
+
const data = Buffer.concat([INSTRUCTION_DISC.withdrawBond, u64LE(amount)]);
|
|
223
|
+
return new TransactionInstruction({
|
|
224
|
+
programId,
|
|
225
|
+
keys: [
|
|
226
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
227
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
228
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
229
|
+
{ pubkey: accounts.controllerBondAta, isSigner: false, isWritable: true },
|
|
230
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: false },
|
|
231
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
232
|
+
],
|
|
233
|
+
data,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
export function buildViewBondIx(agent, args, programId = PROGRAM_ID) {
|
|
237
|
+
const data = Buffer.alloc(8 + 8 + 2);
|
|
238
|
+
INSTRUCTION_DISC.viewBond.copy(data, 0);
|
|
239
|
+
data.writeBigUInt64LE(args.minBond, 8);
|
|
240
|
+
data.writeUInt16LE(args.minScore, 16);
|
|
241
|
+
return new TransactionInstruction({
|
|
242
|
+
programId,
|
|
243
|
+
keys: [{ pubkey: agent, isSigner: false, isWritable: false }],
|
|
244
|
+
data,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Idempotently set the agent's declared capability bitmap. The bitmap
|
|
249
|
+
* is a u64 where bit `n` set means the agent has capability id `n`.
|
|
250
|
+
* Use `capabilitiesBitmap([CAPABILITY_SWAP, CAPABILITY_LP])` to compose.
|
|
251
|
+
*/
|
|
252
|
+
export function buildRegisterCapabilitiesIx(accounts, bitmap, programId = PROGRAM_ID) {
|
|
253
|
+
const [registry] = findCapabilityRegistryPda(accounts.agent, programId);
|
|
254
|
+
const data = Buffer.alloc(8 + 8);
|
|
255
|
+
INSTRUCTION_DISC.registerCapabilities.copy(data, 0);
|
|
256
|
+
data.writeBigUInt64LE(bitmap, 8);
|
|
257
|
+
return new TransactionInstruction({
|
|
258
|
+
programId,
|
|
259
|
+
keys: [
|
|
260
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
261
|
+
{ pubkey: registry, isSigner: false, isWritable: true },
|
|
262
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: true },
|
|
263
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
264
|
+
],
|
|
265
|
+
data,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Capability-aware view_bond. Same checks as `view_bond` PLUS the agent
|
|
270
|
+
* must have capability bit `capabilityBit` set in its registry. Use
|
|
271
|
+
* this when gating a specific surface (Jupiter for swap, Kamino for
|
|
272
|
+
* lending, etc.).
|
|
273
|
+
*/
|
|
274
|
+
/* ------------------------------------------------------------------ */
|
|
275
|
+
/* Score-as-Oracle */
|
|
276
|
+
/* ------------------------------------------------------------------ */
|
|
277
|
+
export function buildInitScoreFeedIx(agent, payer, programId = PROGRAM_ID) {
|
|
278
|
+
const [feed] = findScoreFeedPda(agent, programId);
|
|
279
|
+
return new TransactionInstruction({
|
|
280
|
+
programId,
|
|
281
|
+
keys: [
|
|
282
|
+
{ pubkey: agent, isSigner: false, isWritable: false },
|
|
283
|
+
{ pubkey: feed, isSigner: false, isWritable: true },
|
|
284
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
285
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
286
|
+
],
|
|
287
|
+
data: Buffer.from(INSTRUCTION_DISC.initScoreFeed),
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
export function buildPushScoreIx(agent, programId = PROGRAM_ID) {
|
|
291
|
+
const [feed] = findScoreFeedPda(agent, programId);
|
|
292
|
+
return new TransactionInstruction({
|
|
293
|
+
programId,
|
|
294
|
+
keys: [
|
|
295
|
+
{ pubkey: agent, isSigner: false, isWritable: false },
|
|
296
|
+
{ pubkey: feed, isSigner: false, isWritable: true },
|
|
297
|
+
],
|
|
298
|
+
data: Buffer.from(INSTRUCTION_DISC.pushScore),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* CPI gate for the score feed. `maxStalenessSecs = 0` disables the
|
|
303
|
+
* freshness check.
|
|
304
|
+
*/
|
|
305
|
+
export function buildViewScoreIx(agent, args, programId = PROGRAM_ID) {
|
|
306
|
+
const [feed] = findScoreFeedPda(agent, programId);
|
|
307
|
+
const data = Buffer.alloc(8 + 2 + 8);
|
|
308
|
+
INSTRUCTION_DISC.viewScore.copy(data, 0);
|
|
309
|
+
data.writeUInt16LE(args.minScore, 8);
|
|
310
|
+
data.writeBigInt64LE(args.maxStalenessSecs, 10);
|
|
311
|
+
return new TransactionInstruction({
|
|
312
|
+
programId,
|
|
313
|
+
keys: [{ pubkey: feed, isSigner: false, isWritable: false }],
|
|
314
|
+
data,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
export function buildViewBondCapabilityIx(agent, args, programId = PROGRAM_ID) {
|
|
318
|
+
const [registry] = findCapabilityRegistryPda(agent, programId);
|
|
319
|
+
const data = Buffer.alloc(8 + 8 + 2 + 1);
|
|
320
|
+
INSTRUCTION_DISC.viewBondCapability.copy(data, 0);
|
|
321
|
+
data.writeBigUInt64LE(args.minBond, 8);
|
|
322
|
+
data.writeUInt16LE(args.minScore, 16);
|
|
323
|
+
data.writeUInt8(args.capabilityBit & 0xff, 18);
|
|
324
|
+
return new TransactionInstruction({
|
|
325
|
+
programId,
|
|
326
|
+
keys: [
|
|
327
|
+
{ pubkey: agent, isSigner: false, isWritable: false },
|
|
328
|
+
{ pubkey: registry, isSigner: false, isWritable: false },
|
|
329
|
+
],
|
|
330
|
+
data,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
export function buildAccrueYieldIx(accounts, amount, programId = PROGRAM_ID) {
|
|
334
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
335
|
+
const data = Buffer.concat([INSTRUCTION_DISC.accrueYield, u64LE(amount)]);
|
|
336
|
+
return new TransactionInstruction({
|
|
337
|
+
programId,
|
|
338
|
+
keys: [
|
|
339
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
340
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
341
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
342
|
+
{ pubkey: accounts.sourceAta, isSigner: false, isWritable: true },
|
|
343
|
+
{ pubkey: accounts.scorer, isSigner: true, isWritable: true },
|
|
344
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
345
|
+
],
|
|
346
|
+
data,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
export function buildClaimBuilderYieldIx(accounts, amount, programId = PROGRAM_ID) {
|
|
350
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
351
|
+
const data = Buffer.concat([INSTRUCTION_DISC.claimBuilderYield, u64LE(amount)]);
|
|
352
|
+
return new TransactionInstruction({
|
|
353
|
+
programId,
|
|
354
|
+
keys: [
|
|
355
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
356
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
357
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
358
|
+
{ pubkey: accounts.controllerAta, isSigner: false, isWritable: true },
|
|
359
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: false },
|
|
360
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
361
|
+
],
|
|
362
|
+
data,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
export function buildClaimTreasuryYieldIx(accounts, amount, programId = PROGRAM_ID) {
|
|
366
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
367
|
+
const data = Buffer.concat([INSTRUCTION_DISC.claimTreasuryYield, u64LE(amount)]);
|
|
368
|
+
return new TransactionInstruction({
|
|
369
|
+
programId,
|
|
370
|
+
keys: [
|
|
371
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
372
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
373
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
374
|
+
{ pubkey: accounts.treasuryAta, isSigner: false, isWritable: true },
|
|
375
|
+
{ pubkey: accounts.scorer, isSigner: true, isWritable: false },
|
|
376
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
377
|
+
],
|
|
378
|
+
data,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/** User escalates a rejected claim. Pays additional 5% deposit; the
|
|
382
|
+
* protocol arbiter has 7d to rule. Only the original claimer can call,
|
|
383
|
+
* and only within ESCALATION_WINDOW_SECONDS (24h) of resolve. */
|
|
384
|
+
export function buildEscalateClaimIx(accounts, programId = PROGRAM_ID) {
|
|
385
|
+
const [deposit] = findDepositVaultPda(accounts.claim, programId);
|
|
386
|
+
return new TransactionInstruction({
|
|
387
|
+
programId,
|
|
388
|
+
keys: [
|
|
389
|
+
{ pubkey: accounts.claim, isSigner: false, isWritable: true },
|
|
390
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
391
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
392
|
+
{ pubkey: deposit, isSigner: false, isWritable: true },
|
|
393
|
+
{ pubkey: accounts.claimerBondAta, isSigner: false, isWritable: true },
|
|
394
|
+
{ pubkey: accounts.claimer, isSigner: true, isWritable: true },
|
|
395
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
396
|
+
],
|
|
397
|
+
data: INSTRUCTION_DISC.escalateClaim,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
/** ArbiterRuling: 0 = ForUser, 1 = ForBuilder. */
|
|
401
|
+
export var ArbiterRuling;
|
|
402
|
+
(function (ArbiterRuling) {
|
|
403
|
+
ArbiterRuling[ArbiterRuling["ForUser"] = 0] = "ForUser";
|
|
404
|
+
ArbiterRuling[ArbiterRuling["ForBuilder"] = 1] = "ForBuilder";
|
|
405
|
+
})(ArbiterRuling || (ArbiterRuling = {}));
|
|
406
|
+
export function buildArbiterResolveIx(accounts, ruling, programId = PROGRAM_ID) {
|
|
407
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
408
|
+
const [deposit] = findDepositVaultPda(accounts.claim, programId);
|
|
409
|
+
const data = Buffer.concat([
|
|
410
|
+
INSTRUCTION_DISC.arbiterResolve,
|
|
411
|
+
Buffer.from([ruling & 0xff]),
|
|
412
|
+
]);
|
|
413
|
+
return new TransactionInstruction({
|
|
414
|
+
programId,
|
|
415
|
+
keys: [
|
|
416
|
+
{ pubkey: accounts.claim, isSigner: false, isWritable: true },
|
|
417
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
418
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
419
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
420
|
+
{ pubkey: deposit, isSigner: false, isWritable: true },
|
|
421
|
+
{ pubkey: accounts.claimerBondAta, isSigner: false, isWritable: true },
|
|
422
|
+
{ pubkey: accounts.arbiter, isSigner: true, isWritable: false },
|
|
423
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
424
|
+
],
|
|
425
|
+
data,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
/** Anyone can crank after 7d arbiter window — defaults ForUser auto-payout. */
|
|
429
|
+
export function buildArbiterTimeoutIx(accounts, programId = PROGRAM_ID) {
|
|
430
|
+
const [vault] = findBondVaultPda(accounts.agent, programId);
|
|
431
|
+
const [deposit] = findDepositVaultPda(accounts.claim, programId);
|
|
432
|
+
return new TransactionInstruction({
|
|
433
|
+
programId,
|
|
434
|
+
keys: [
|
|
435
|
+
{ pubkey: accounts.claim, isSigner: false, isWritable: true },
|
|
436
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
437
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
438
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
439
|
+
{ pubkey: deposit, isSigner: false, isWritable: true },
|
|
440
|
+
{ pubkey: accounts.claimerBondAta, isSigner: false, isWritable: true },
|
|
441
|
+
{ pubkey: accounts.cranker, isSigner: true, isWritable: false },
|
|
442
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
443
|
+
],
|
|
444
|
+
data: INSTRUCTION_DISC.arbiterTimeout,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
/** One-shot init of the per-agent tsUSDC mint + config PDA. */
|
|
448
|
+
export function buildInitTsusdcMintIx(accounts, programId = PROGRAM_ID) {
|
|
449
|
+
const [config] = findTsusdcConfigPda(accounts.agent, programId);
|
|
450
|
+
const [mintAuth] = findTsusdcMintAuthPda(accounts.agent, programId);
|
|
451
|
+
const [mint] = findTsusdcMintPda(accounts.agent, programId);
|
|
452
|
+
return new TransactionInstruction({
|
|
453
|
+
programId,
|
|
454
|
+
keys: [
|
|
455
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
456
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
457
|
+
{ pubkey: mintAuth, isSigner: false, isWritable: false },
|
|
458
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
459
|
+
{ pubkey: accounts.payer, isSigner: true, isWritable: true },
|
|
460
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
461
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
462
|
+
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
|
|
463
|
+
],
|
|
464
|
+
data: INSTRUCTION_DISC.initTsusdcMint,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
/** First-mint tokenization (1:1 with current_bond). One-shot per agent. */
|
|
468
|
+
export function buildMintTsusdcIx(accounts, programId = PROGRAM_ID) {
|
|
469
|
+
const [config] = findTsusdcConfigPda(accounts.agent, programId);
|
|
470
|
+
const [mintAuth] = findTsusdcMintAuthPda(accounts.agent, programId);
|
|
471
|
+
const [mint] = findTsusdcMintPda(accounts.agent, programId);
|
|
472
|
+
return new TransactionInstruction({
|
|
473
|
+
programId,
|
|
474
|
+
keys: [
|
|
475
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
476
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
477
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
478
|
+
{ pubkey: mintAuth, isSigner: false, isWritable: false },
|
|
479
|
+
{ pubkey: accounts.recipientAta, isSigner: false, isWritable: true },
|
|
480
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: false },
|
|
481
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
482
|
+
],
|
|
483
|
+
data: INSTRUCTION_DISC.mintTsusdc,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/** Burn tsUSDC; anyone holding the token can call. */
|
|
487
|
+
export function buildBurnTsusdcIx(accounts, amount, programId = PROGRAM_ID) {
|
|
488
|
+
const [config] = findTsusdcConfigPda(accounts.agent, programId);
|
|
489
|
+
const [mint] = findTsusdcMintPda(accounts.agent, programId);
|
|
490
|
+
const data = Buffer.concat([INSTRUCTION_DISC.burnTsusdc, u64LE(amount)]);
|
|
491
|
+
return new TransactionInstruction({
|
|
492
|
+
programId,
|
|
493
|
+
keys: [
|
|
494
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
495
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
496
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
497
|
+
{ pubkey: accounts.holderAta, isSigner: false, isWritable: true },
|
|
498
|
+
{ pubkey: accounts.holder, isSigner: true, isWritable: false },
|
|
499
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
500
|
+
],
|
|
501
|
+
data,
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
export function buildInitUnderwriterPoolIx(accounts, depositCap, programId = PROGRAM_ID) {
|
|
505
|
+
const [pool] = findPoolConfigPda(programId);
|
|
506
|
+
const [mintAuth] = findPoolMintAuthPda(programId);
|
|
507
|
+
const [stusdcMint] = findPoolStusdcMintPda(programId);
|
|
508
|
+
const [vault] = findPoolVaultPda(programId);
|
|
509
|
+
const data = Buffer.concat([
|
|
510
|
+
INSTRUCTION_DISC.initUnderwriterPool,
|
|
511
|
+
u64LE(depositCap),
|
|
512
|
+
]);
|
|
513
|
+
return new TransactionInstruction({
|
|
514
|
+
programId,
|
|
515
|
+
keys: [
|
|
516
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
517
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
518
|
+
{ pubkey: mintAuth, isSigner: false, isWritable: false },
|
|
519
|
+
{ pubkey: stusdcMint, isSigner: false, isWritable: true },
|
|
520
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
521
|
+
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
522
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
523
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
524
|
+
// rent sysvar dropped — Anchor 0.30 inits don't require it, and the
|
|
525
|
+
// on-chain struct was trimmed for the same SBPF stack-frame reason.
|
|
526
|
+
],
|
|
527
|
+
data,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
export function buildDepositToPoolIx(accounts, amount, programId = PROGRAM_ID) {
|
|
531
|
+
const [pool] = findPoolConfigPda(programId);
|
|
532
|
+
const [vault] = findPoolVaultPda(programId);
|
|
533
|
+
const [mintAuth] = findPoolMintAuthPda(programId);
|
|
534
|
+
const [stusdcMint] = findPoolStusdcMintPda(programId);
|
|
535
|
+
const data = Buffer.concat([INSTRUCTION_DISC.depositToPool, u64LE(amount)]);
|
|
536
|
+
return new TransactionInstruction({
|
|
537
|
+
programId,
|
|
538
|
+
keys: [
|
|
539
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
540
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
541
|
+
{ pubkey: mintAuth, isSigner: false, isWritable: false },
|
|
542
|
+
{ pubkey: stusdcMint, isSigner: false, isWritable: true },
|
|
543
|
+
{ pubkey: accounts.depositorAta, isSigner: false, isWritable: true },
|
|
544
|
+
{ pubkey: accounts.depositorStusdcAta, isSigner: false, isWritable: true },
|
|
545
|
+
{ pubkey: accounts.depositor, isSigner: true, isWritable: false },
|
|
546
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
547
|
+
],
|
|
548
|
+
data,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
export function buildWithdrawFromPoolIx(accounts, stusdcAmount, programId = PROGRAM_ID) {
|
|
552
|
+
const [pool] = findPoolConfigPda(programId);
|
|
553
|
+
const [vault] = findPoolVaultPda(programId);
|
|
554
|
+
const [mintAuth] = findPoolMintAuthPda(programId);
|
|
555
|
+
const [stusdcMint] = findPoolStusdcMintPda(programId);
|
|
556
|
+
const data = Buffer.concat([
|
|
557
|
+
INSTRUCTION_DISC.withdrawFromPool,
|
|
558
|
+
u64LE(stusdcAmount),
|
|
559
|
+
]);
|
|
560
|
+
return new TransactionInstruction({
|
|
561
|
+
programId,
|
|
562
|
+
keys: [
|
|
563
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
564
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
565
|
+
{ pubkey: mintAuth, isSigner: false, isWritable: false },
|
|
566
|
+
{ pubkey: stusdcMint, isSigner: false, isWritable: true },
|
|
567
|
+
{ pubkey: accounts.holderStusdcAta, isSigner: false, isWritable: true },
|
|
568
|
+
{ pubkey: accounts.holderAta, isSigner: false, isWritable: true },
|
|
569
|
+
{ pubkey: accounts.holder, isSigner: true, isWritable: false },
|
|
570
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
571
|
+
],
|
|
572
|
+
data,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
export function buildProcessPoolYieldIx(accounts, amount, programId = PROGRAM_ID) {
|
|
576
|
+
const [pool] = findPoolConfigPda(programId);
|
|
577
|
+
const [vault] = findPoolVaultPda(programId);
|
|
578
|
+
const data = Buffer.concat([INSTRUCTION_DISC.processPoolYield, u64LE(amount)]);
|
|
579
|
+
return new TransactionInstruction({
|
|
580
|
+
programId,
|
|
581
|
+
keys: [
|
|
582
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
583
|
+
{ pubkey: vault, isSigner: false, isWritable: true },
|
|
584
|
+
{ pubkey: accounts.sourceAta, isSigner: false, isWritable: true },
|
|
585
|
+
{ pubkey: accounts.sourceAuthority, isSigner: true, isWritable: false },
|
|
586
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
587
|
+
],
|
|
588
|
+
data,
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
/* ------------------------------------------------------------------ */
|
|
592
|
+
/* Yield routing (Phase 1.0 — MarginFi) */
|
|
593
|
+
/* ------------------------------------------------------------------ */
|
|
594
|
+
export { LP_KIND_MARGINFI } from "./pda.js";
|
|
595
|
+
/**
|
|
596
|
+
* One-shot init for a per-agent LP position. Pins which MarginFi account
|
|
597
|
+
* + bank this agent routes into. Caller supplies `marginfiAccount` (the
|
|
598
|
+
* MarginfiAccount must already have been created off-chain via the
|
|
599
|
+
* MarginFi SDK with bond_vault PDA as authority).
|
|
600
|
+
*/
|
|
601
|
+
export function buildInitLpPositionIx(accounts, lpKind, yieldRouter, marginfiAccount, marginfiBank, programId = PROGRAM_ID) {
|
|
602
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, lpKind, programId);
|
|
603
|
+
const data = Buffer.concat([
|
|
604
|
+
INSTRUCTION_DISC.initLpPosition,
|
|
605
|
+
Buffer.from([lpKind]),
|
|
606
|
+
yieldRouter.toBuffer(),
|
|
607
|
+
marginfiAccount.toBuffer(),
|
|
608
|
+
marginfiBank.toBuffer(),
|
|
609
|
+
]);
|
|
610
|
+
return new TransactionInstruction({
|
|
611
|
+
programId,
|
|
612
|
+
keys: [
|
|
613
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
614
|
+
{ pubkey: lpPosition, isSigner: false, isWritable: true },
|
|
615
|
+
{ pubkey: accounts.payer, isSigner: true, isWritable: true },
|
|
616
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
617
|
+
],
|
|
618
|
+
data,
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
export function buildInitMarginfiAccountIx(accounts, programId = PROGRAM_ID) {
|
|
622
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
623
|
+
const data = INSTRUCTION_DISC.initMarginfiAccount;
|
|
624
|
+
return new TransactionInstruction({
|
|
625
|
+
programId,
|
|
626
|
+
keys: [
|
|
627
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
628
|
+
{ pubkey: accounts.marginfiGroup, isSigner: false, isWritable: false },
|
|
629
|
+
{ pubkey: accounts.marginfiAccount, isSigner: true, isWritable: true },
|
|
630
|
+
{ pubkey: bondVault, isSigner: false, isWritable: false },
|
|
631
|
+
{ pubkey: accounts.bondVaultMintWitness, isSigner: false, isWritable: false },
|
|
632
|
+
{ pubkey: accounts.marginfiProgram, isSigner: false, isWritable: false },
|
|
633
|
+
{ pubkey: accounts.feePayer, isSigner: true, isWritable: true },
|
|
634
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
635
|
+
],
|
|
636
|
+
data,
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
export function buildRouteToMarginfiIx(accounts, amount, programId = PROGRAM_ID) {
|
|
640
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_MARGINFI, programId);
|
|
641
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
642
|
+
const data = Buffer.concat([INSTRUCTION_DISC.routeToMarginfi, u64LE(amount)]);
|
|
643
|
+
return new TransactionInstruction({
|
|
644
|
+
programId,
|
|
645
|
+
keys: [
|
|
646
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
647
|
+
{ pubkey: lpPosition, isSigner: false, isWritable: true },
|
|
648
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
649
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
650
|
+
{ pubkey: accounts.marginfiGroup, isSigner: false, isWritable: false },
|
|
651
|
+
{ pubkey: accounts.marginfiBank, isSigner: false, isWritable: false },
|
|
652
|
+
{ pubkey: accounts.marginfiAccount, isSigner: false, isWritable: true },
|
|
653
|
+
{ pubkey: accounts.marginfiBankLiquidityVault, isSigner: false, isWritable: true },
|
|
654
|
+
{ pubkey: accounts.marginfiProgram, isSigner: false, isWritable: false },
|
|
655
|
+
{ pubkey: accounts.yieldRouter, isSigner: true, isWritable: false },
|
|
656
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
657
|
+
],
|
|
658
|
+
data,
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
export function buildHarvestMarginfiYieldIx(accounts, yieldAmount, programId = PROGRAM_ID) {
|
|
662
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_MARGINFI, programId);
|
|
663
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
664
|
+
const data = Buffer.concat([INSTRUCTION_DISC.harvestMarginfiYield, u64LE(yieldAmount)]);
|
|
665
|
+
return new TransactionInstruction({
|
|
666
|
+
programId,
|
|
667
|
+
keys: [
|
|
668
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
669
|
+
{ pubkey: lpPosition, isSigner: false, isWritable: true },
|
|
670
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
671
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
672
|
+
{ pubkey: accounts.marginfiGroup, isSigner: false, isWritable: false },
|
|
673
|
+
{ pubkey: accounts.marginfiAccount, isSigner: false, isWritable: true },
|
|
674
|
+
{ pubkey: accounts.marginfiBank, isSigner: false, isWritable: false },
|
|
675
|
+
{ pubkey: accounts.marginfiBankLiquidityVaultAuthority, isSigner: false, isWritable: false },
|
|
676
|
+
{ pubkey: accounts.marginfiBankLiquidityVault, isSigner: false, isWritable: true },
|
|
677
|
+
{ pubkey: accounts.marginfiProgram, isSigner: false, isWritable: false },
|
|
678
|
+
{ pubkey: accounts.yieldRouter, isSigner: true, isWritable: false },
|
|
679
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
680
|
+
],
|
|
681
|
+
data,
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
export function buildUnrouteFromMarginfiIx(accounts, amount, reason, programId = PROGRAM_ID) {
|
|
685
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_MARGINFI, programId);
|
|
686
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
687
|
+
const data = Buffer.concat([
|
|
688
|
+
INSTRUCTION_DISC.unrouteFromMarginfi,
|
|
689
|
+
u64LE(amount),
|
|
690
|
+
Buffer.from([reason]),
|
|
691
|
+
]);
|
|
692
|
+
return new TransactionInstruction({
|
|
693
|
+
programId,
|
|
694
|
+
keys: [
|
|
695
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
696
|
+
{ pubkey: lpPosition, isSigner: false, isWritable: true },
|
|
697
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
698
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
699
|
+
{ pubkey: accounts.marginfiGroup, isSigner: false, isWritable: false },
|
|
700
|
+
{ pubkey: accounts.marginfiAccount, isSigner: false, isWritable: true },
|
|
701
|
+
{ pubkey: accounts.marginfiBank, isSigner: false, isWritable: false },
|
|
702
|
+
{ pubkey: accounts.marginfiBankLiquidityVaultAuthority, isSigner: false, isWritable: false },
|
|
703
|
+
{ pubkey: accounts.marginfiBankLiquidityVault, isSigner: false, isWritable: true },
|
|
704
|
+
{ pubkey: accounts.marginfiProgram, isSigner: false, isWritable: false },
|
|
705
|
+
{ pubkey: accounts.yieldRouter, isSigner: true, isWritable: false },
|
|
706
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
707
|
+
],
|
|
708
|
+
data,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
export function buildInitKaminoObligationIx(accounts, programId = PROGRAM_ID) {
|
|
712
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
713
|
+
return new TransactionInstruction({
|
|
714
|
+
programId,
|
|
715
|
+
keys: [
|
|
716
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
717
|
+
{ pubkey: accounts.kaminoLendingMarket, isSigner: false, isWritable: false },
|
|
718
|
+
{ pubkey: accounts.obligation, isSigner: true, isWritable: true },
|
|
719
|
+
{ pubkey: bondVault, isSigner: false, isWritable: false },
|
|
720
|
+
{ pubkey: accounts.bondVaultMintWitness, isSigner: false, isWritable: false },
|
|
721
|
+
{ pubkey: accounts.kaminoProgram, isSigner: false, isWritable: false },
|
|
722
|
+
{ pubkey: accounts.feePayer, isSigner: true, isWritable: true },
|
|
723
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
724
|
+
],
|
|
725
|
+
data: INSTRUCTION_DISC.initKaminoObligation,
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
function kaminoKeys(accounts, lpPosition, bondVault, agentWritable) {
|
|
729
|
+
return [
|
|
730
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: agentWritable },
|
|
731
|
+
{ pubkey: lpPosition, isSigner: false, isWritable: true },
|
|
732
|
+
{ pubkey: accounts.bondMint, isSigner: false, isWritable: false },
|
|
733
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
734
|
+
{ pubkey: accounts.kaminoLendingMarket, isSigner: false, isWritable: false },
|
|
735
|
+
{ pubkey: accounts.kaminoLendingMarketAuthority, isSigner: false, isWritable: false },
|
|
736
|
+
{ pubkey: accounts.kaminoReserve, isSigner: false, isWritable: true },
|
|
737
|
+
{ pubkey: accounts.kaminoObligation, isSigner: false, isWritable: true },
|
|
738
|
+
{ pubkey: accounts.kaminoReserveLiquiditySupply, isSigner: false, isWritable: true },
|
|
739
|
+
{ pubkey: accounts.kaminoReserveCollateralMint, isSigner: false, isWritable: true },
|
|
740
|
+
{ pubkey: accounts.bondVaultCollateralAta, isSigner: false, isWritable: true },
|
|
741
|
+
{ pubkey: accounts.kaminoProgram, isSigner: false, isWritable: false },
|
|
742
|
+
{ pubkey: accounts.yieldRouter, isSigner: true, isWritable: false },
|
|
743
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
744
|
+
];
|
|
745
|
+
}
|
|
746
|
+
export function buildRouteToKaminoIx(accounts, amount, programId = PROGRAM_ID) {
|
|
747
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_KAMINO, programId);
|
|
748
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
749
|
+
return new TransactionInstruction({
|
|
750
|
+
programId,
|
|
751
|
+
keys: kaminoKeys(accounts, lpPosition, bondVault, /* agentWritable */ false),
|
|
752
|
+
data: Buffer.concat([INSTRUCTION_DISC.routeToKamino, u64LE(amount)]),
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
export function buildHarvestKaminoYieldIx(accounts, yieldAmount, programId = PROGRAM_ID) {
|
|
756
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_KAMINO, programId);
|
|
757
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
758
|
+
return new TransactionInstruction({
|
|
759
|
+
programId,
|
|
760
|
+
keys: kaminoKeys(accounts, lpPosition, bondVault, /* agentWritable */ true),
|
|
761
|
+
data: Buffer.concat([INSTRUCTION_DISC.harvestKaminoYield, u64LE(yieldAmount)]),
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
export function buildUnrouteFromKaminoIx(accounts, amount, reason, programId = PROGRAM_ID) {
|
|
765
|
+
const [lpPosition] = findLpPositionPda(accounts.agent, LP_KIND_KAMINO, programId);
|
|
766
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
767
|
+
return new TransactionInstruction({
|
|
768
|
+
programId,
|
|
769
|
+
keys: kaminoKeys(accounts, lpPosition, bondVault, /* agentWritable */ false),
|
|
770
|
+
data: Buffer.concat([
|
|
771
|
+
INSTRUCTION_DISC.unrouteFromKamino,
|
|
772
|
+
u64LE(amount),
|
|
773
|
+
Buffer.from([reason]),
|
|
774
|
+
]),
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
export function buildInitProtocolConfigIx(accounts, initialArbiter, programId = PROGRAM_ID) {
|
|
778
|
+
const [config] = findProtocolConfigPda(programId);
|
|
779
|
+
return new TransactionInstruction({
|
|
780
|
+
programId,
|
|
781
|
+
keys: [
|
|
782
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
783
|
+
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
784
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
785
|
+
],
|
|
786
|
+
data: Buffer.concat([INSTRUCTION_DISC.initProtocolConfig, initialArbiter.toBuffer()]),
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
export function buildSetProtocolArbiterIx(accounts, newArbiter, programId = PROGRAM_ID) {
|
|
790
|
+
const [config] = findProtocolConfigPda(programId);
|
|
791
|
+
return new TransactionInstruction({
|
|
792
|
+
programId,
|
|
793
|
+
keys: [
|
|
794
|
+
{ pubkey: config, isSigner: false, isWritable: true },
|
|
795
|
+
{ pubkey: accounts.admin, isSigner: true, isWritable: false },
|
|
796
|
+
],
|
|
797
|
+
data: Buffer.concat([INSTRUCTION_DISC.setProtocolArbiter, newArbiter.toBuffer()]),
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
export function buildRequestCreditIx(accounts, amount, programId = PROGRAM_ID) {
|
|
801
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
802
|
+
const [creditLine] = findCreditLinePda(accounts.agent, programId);
|
|
803
|
+
const [pool] = findPoolConfigPda(programId);
|
|
804
|
+
const [poolVault] = findPoolVaultPda(programId);
|
|
805
|
+
const [poolMintAuth] = findPoolMintAuthPda(programId);
|
|
806
|
+
return new TransactionInstruction({
|
|
807
|
+
programId,
|
|
808
|
+
keys: [
|
|
809
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: true },
|
|
810
|
+
{ pubkey: creditLine, isSigner: false, isWritable: true },
|
|
811
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
812
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
813
|
+
{ pubkey: poolVault, isSigner: false, isWritable: true },
|
|
814
|
+
{ pubkey: poolMintAuth, isSigner: false, isWritable: false },
|
|
815
|
+
{ pubkey: accounts.controller, isSigner: true, isWritable: true },
|
|
816
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
817
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
818
|
+
],
|
|
819
|
+
data: Buffer.concat([INSTRUCTION_DISC.requestCredit, u64LE(amount)]),
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
export function buildRepayCreditIx(accounts, amount, programId = PROGRAM_ID) {
|
|
823
|
+
const [bondVault] = findBondVaultPda(accounts.agent, programId);
|
|
824
|
+
const [creditLine] = findCreditLinePda(accounts.agent, programId);
|
|
825
|
+
const [pool] = findPoolConfigPda(programId);
|
|
826
|
+
const [poolVault] = findPoolVaultPda(programId);
|
|
827
|
+
return new TransactionInstruction({
|
|
828
|
+
programId,
|
|
829
|
+
keys: [
|
|
830
|
+
{ pubkey: accounts.agent, isSigner: false, isWritable: false },
|
|
831
|
+
{ pubkey: creditLine, isSigner: false, isWritable: true },
|
|
832
|
+
{ pubkey: bondVault, isSigner: false, isWritable: true },
|
|
833
|
+
{ pubkey: pool, isSigner: false, isWritable: true },
|
|
834
|
+
{ pubkey: poolVault, isSigner: false, isWritable: true },
|
|
835
|
+
{ pubkey: accounts.payer, isSigner: true, isWritable: false },
|
|
836
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
837
|
+
],
|
|
838
|
+
data: Buffer.concat([INSTRUCTION_DISC.repayCredit, u64LE(amount)]),
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
//# sourceMappingURL=instructions.js.map
|