@carrot-protocol/clend-rpc 0.0.1-mrgn-fork1-dev-7be6ef2
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/.prettierignore +1 -0
- package/makefile +12 -0
- package/package.json +32 -0
- package/src/addresses.ts +206 -0
- package/src/idl/clend.ts +7509 -0
- package/src/index.ts +31 -0
- package/src/instructions.ts +466 -0
- package/src/jupUtils.ts +347 -0
- package/src/jupiterUtils.ts +288 -0
- package/src/logger.ts +21 -0
- package/src/math.ts +684 -0
- package/src/mockJupiterUtils.ts +109 -0
- package/src/rpc.ts +1296 -0
- package/src/state.ts +512 -0
- package/src/utils.ts +249 -0
- package/test/bank.test.ts +95 -0
- package/test/interest-rate.test.ts +114 -0
- package/test/leverage.test.ts +867 -0
- package/test/token-amounts.test.ts +73 -0
- package/tsconfig.json +17 -0
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
idl/
|
package/makefile
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@carrot-protocol/clend-rpc",
|
|
3
|
+
"version": "0.0.1-mrgn-fork1-dev-7be6ef2",
|
|
4
|
+
"description": "rpc client and libs for carrot lend",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"clean": "rm -rf node_modules package-lock.json",
|
|
8
|
+
"build": "npm i && tsc && npm pack",
|
|
9
|
+
"fmt": "prettier --write src/",
|
|
10
|
+
"fmt:check": "prettier --check src/",
|
|
11
|
+
"test": "npx ts-mocha -p ./tsconfig.json -t 1000000 test/**/*.ts"
|
|
12
|
+
},
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/chai": "^4.3.20",
|
|
17
|
+
"@types/mocha": "^9.1.1",
|
|
18
|
+
"chai": "^4.5.0",
|
|
19
|
+
"mocha": "^9.2.2",
|
|
20
|
+
"prettier": "^3.5.3",
|
|
21
|
+
"ts-mocha": "^10.1.0",
|
|
22
|
+
"ts-node": "^10.9.2"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@coral-xyz/anchor": "0.29.0",
|
|
26
|
+
"@jup-ag/api": "6.0.30",
|
|
27
|
+
"@solana/spl-token": "^0.4.13",
|
|
28
|
+
"axios": "^1.8.4",
|
|
29
|
+
"decimal.js": "^10.5.0",
|
|
30
|
+
"winston": "^3.17.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/addresses.ts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { web3, BN } from "@coral-xyz/anchor";
|
|
2
|
+
|
|
3
|
+
export const CLEND_PROGRAM_ID = new web3.PublicKey(
|
|
4
|
+
"C73nDAFn23RYwiFa6vtHshSbcg8x6BLYjw3bERJ3vHxf",
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Derive the PDA for a bank account
|
|
9
|
+
* @param clendGroup The clend group public key
|
|
10
|
+
* @param mint The token mint public key
|
|
11
|
+
* @returns The bank PDA
|
|
12
|
+
*/
|
|
13
|
+
export function getBankPda(
|
|
14
|
+
clendGroup: web3.PublicKey,
|
|
15
|
+
mint: web3.PublicKey,
|
|
16
|
+
): web3.PublicKey {
|
|
17
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
18
|
+
[Buffer.from("bank"), clendGroup.toBuffer(), mint.toBuffer()],
|
|
19
|
+
CLEND_PROGRAM_ID,
|
|
20
|
+
);
|
|
21
|
+
return pubkey;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Derive the PDA for a bank with seed
|
|
26
|
+
* @param clendGroup The clend group public key
|
|
27
|
+
* @param mint The token mint public key
|
|
28
|
+
* @param seed The seed value
|
|
29
|
+
* @returns The bank PDA
|
|
30
|
+
*/
|
|
31
|
+
export function getBankWithSeedPda(
|
|
32
|
+
clendGroup: web3.PublicKey,
|
|
33
|
+
mint: web3.PublicKey,
|
|
34
|
+
seed: BN,
|
|
35
|
+
): web3.PublicKey {
|
|
36
|
+
const seedBuffer = Buffer.alloc(8);
|
|
37
|
+
seedBuffer.writeBigUInt64LE(BigInt(seed.toString()));
|
|
38
|
+
|
|
39
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
40
|
+
[
|
|
41
|
+
Buffer.from("bank_with_seed"),
|
|
42
|
+
clendGroup.toBuffer(),
|
|
43
|
+
mint.toBuffer(),
|
|
44
|
+
seedBuffer,
|
|
45
|
+
],
|
|
46
|
+
CLEND_PROGRAM_ID,
|
|
47
|
+
);
|
|
48
|
+
return pubkey;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Derive the PDA for a bank's liquidity vault authority
|
|
53
|
+
* @param bank The bank public key
|
|
54
|
+
* @returns The liquidity vault authority PDA
|
|
55
|
+
*/
|
|
56
|
+
export function getBankLiquidityVaultAuthorityPda(
|
|
57
|
+
bank: web3.PublicKey,
|
|
58
|
+
): web3.PublicKey {
|
|
59
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
60
|
+
[Buffer.from("liquidity_vault_auth"), bank.toBuffer()],
|
|
61
|
+
CLEND_PROGRAM_ID,
|
|
62
|
+
);
|
|
63
|
+
return pubkey;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Derive the PDA for a bank's insurance vault authority
|
|
68
|
+
* @param bank The bank public key
|
|
69
|
+
* @returns The insurance vault authority PDA
|
|
70
|
+
*/
|
|
71
|
+
export function getBankInsuranceVaultAuthorityPda(
|
|
72
|
+
bank: web3.PublicKey,
|
|
73
|
+
): web3.PublicKey {
|
|
74
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
75
|
+
[Buffer.from("insurance_vault_auth"), bank.toBuffer()],
|
|
76
|
+
CLEND_PROGRAM_ID,
|
|
77
|
+
);
|
|
78
|
+
return pubkey;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Derive the PDA for a bank's fee vault authority
|
|
83
|
+
* @param bank The bank public key
|
|
84
|
+
* @returns The fee vault authority PDA
|
|
85
|
+
*/
|
|
86
|
+
export function getBankFeeVaultAuthorityPda(
|
|
87
|
+
bank: web3.PublicKey,
|
|
88
|
+
): web3.PublicKey {
|
|
89
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
90
|
+
[Buffer.from("fee_vault_auth"), bank.toBuffer()],
|
|
91
|
+
CLEND_PROGRAM_ID,
|
|
92
|
+
);
|
|
93
|
+
return pubkey;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Derive the PDA for the fee state
|
|
98
|
+
* @returns The fee state PDA
|
|
99
|
+
*/
|
|
100
|
+
export function getFeeStatePda(): web3.PublicKey {
|
|
101
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
102
|
+
[Buffer.from("fee_state")],
|
|
103
|
+
CLEND_PROGRAM_ID,
|
|
104
|
+
);
|
|
105
|
+
return pubkey;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Derive the PDA for a clend account
|
|
110
|
+
* @param authority The authority public key
|
|
111
|
+
* @param clendGroup The clend group public key
|
|
112
|
+
* @returns The clend account PDA
|
|
113
|
+
*/
|
|
114
|
+
export function getClendAccountPda(
|
|
115
|
+
authority: web3.PublicKey,
|
|
116
|
+
clendGroup: web3.PublicKey,
|
|
117
|
+
): web3.PublicKey {
|
|
118
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
119
|
+
[Buffer.from("clend_account"), authority.toBuffer(), clendGroup.toBuffer()],
|
|
120
|
+
CLEND_PROGRAM_ID,
|
|
121
|
+
);
|
|
122
|
+
return pubkey;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Derive the PDA for a clend account with seed
|
|
127
|
+
* @param authority The authority public key
|
|
128
|
+
* @param clendGroup The clend group public key
|
|
129
|
+
* @param seed The seed value
|
|
130
|
+
* @returns The clend account PDA
|
|
131
|
+
*/
|
|
132
|
+
export function getClendAccountWithSeedPda(
|
|
133
|
+
authority: web3.PublicKey,
|
|
134
|
+
clendGroup: web3.PublicKey,
|
|
135
|
+
seed: BN,
|
|
136
|
+
): web3.PublicKey {
|
|
137
|
+
const seedBuffer = Buffer.alloc(8);
|
|
138
|
+
seedBuffer.writeBigUInt64LE(BigInt(seed.toString()));
|
|
139
|
+
|
|
140
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
141
|
+
[
|
|
142
|
+
Buffer.from("clend_account_with_seed"),
|
|
143
|
+
authority.toBuffer(),
|
|
144
|
+
clendGroup.toBuffer(),
|
|
145
|
+
seedBuffer,
|
|
146
|
+
],
|
|
147
|
+
CLEND_PROGRAM_ID,
|
|
148
|
+
);
|
|
149
|
+
return pubkey;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Derive the PDA for a position in a clend account
|
|
154
|
+
* @param clendAccount The clend account public key
|
|
155
|
+
* @param bank The bank public key
|
|
156
|
+
* @returns The position PDA
|
|
157
|
+
*/
|
|
158
|
+
export function getPositionPda(
|
|
159
|
+
clendAccount: web3.PublicKey,
|
|
160
|
+
bank: web3.PublicKey,
|
|
161
|
+
): web3.PublicKey {
|
|
162
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
163
|
+
[Buffer.from("position"), clendAccount.toBuffer(), bank.toBuffer()],
|
|
164
|
+
CLEND_PROGRAM_ID,
|
|
165
|
+
);
|
|
166
|
+
return pubkey;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Derive the PDA for a bank's liquidity vault
|
|
171
|
+
* @param bank The bank public key
|
|
172
|
+
* @returns The liquidity vault PDA
|
|
173
|
+
*/
|
|
174
|
+
export function getBankLiquidityVaultPda(bank: web3.PublicKey): web3.PublicKey {
|
|
175
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
176
|
+
[Buffer.from("liquidity_vault"), bank.toBuffer()],
|
|
177
|
+
CLEND_PROGRAM_ID,
|
|
178
|
+
);
|
|
179
|
+
return pubkey;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Derive the PDA for a bank's insurance vault
|
|
184
|
+
* @param bank The bank public key
|
|
185
|
+
* @returns The insurance vault PDA
|
|
186
|
+
*/
|
|
187
|
+
export function getBankInsuranceVaultPda(bank: web3.PublicKey): web3.PublicKey {
|
|
188
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
189
|
+
[Buffer.from("insurance_vault"), bank.toBuffer()],
|
|
190
|
+
CLEND_PROGRAM_ID,
|
|
191
|
+
);
|
|
192
|
+
return pubkey;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Derive the PDA for a bank's fee vault
|
|
197
|
+
* @param bank The bank public key
|
|
198
|
+
* @returns The fee vault PDA
|
|
199
|
+
*/
|
|
200
|
+
export function getBankFeeVaultPda(bank: web3.PublicKey): web3.PublicKey {
|
|
201
|
+
const [pubkey] = web3.PublicKey.findProgramAddressSync(
|
|
202
|
+
[Buffer.from("fee_vault"), bank.toBuffer()],
|
|
203
|
+
CLEND_PROGRAM_ID,
|
|
204
|
+
);
|
|
205
|
+
return pubkey;
|
|
206
|
+
}
|