-
Notifications
You must be signed in to change notification settings - Fork 79
/
index.ts
64 lines (60 loc) · 1.81 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { AnchorProvider, BN, Program } from '@coral-xyz/anchor';
import { MarinadeFinance, IDL } from './types';
import {
PublicKey,
SystemProgram,
TransactionInstruction,
} from '@solana/web3.js';
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
const marinadeFinanceProgramId = new PublicKey(
'MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD'
);
export function getMarinadeFinanceProgram(
provider: AnchorProvider
): Program<MarinadeFinance> {
return new Program<MarinadeFinance>(IDL, marinadeFinanceProgramId, provider);
}
export function getMarinadeDepositIx({
program,
amount,
mSOLAccount,
transferFrom,
}: {
amount: BN;
mSOLAccount: PublicKey;
transferFrom: PublicKey;
program: Program<MarinadeFinance>;
}): Promise<TransactionInstruction> {
return program.methods
.deposit(amount)
.accountsStrict({
reservePda: new PublicKey('Du3Ysj1wKbxPKkuPPnvzQLQh8oMSVifs3jGZjJWXFmHN'),
state: new PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC'),
msolMint: new PublicKey('mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So'),
msolMintAuthority: new PublicKey(
'3JLPCS1qM2zRw3Dp6V4hZnYHd4toMNPkNesXdX9tg6KM'
),
liqPoolMsolLegAuthority: new PublicKey(
'EyaSjUtSgo9aRD1f8LWXwdvkpDTmXAW54yoSHZRF14WL'
),
liqPoolMsolLeg: new PublicKey(
'7GgPYjS5Dza89wV6FpZ23kUJRG5vbQ1GM25ezspYFSoE'
),
liqPoolSolLegPda: new PublicKey(
'UefNb6z6yvArqe4cJHTXCqStRsKmWhGxnZzuHbikP5Q'
),
mintTo: mSOLAccount,
transferFrom,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction();
}
export async function getMarinadeMSolPrice(
program: Program<MarinadeFinance>
): Promise<number> {
const state = await program.account.state.fetch(
new PublicKey('8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC')
);
return state.msolPrice.toNumber() / 0x1_0000_0000;
}