Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 3591f80

Browse files
authored
lending: Command Line Interface (#1676)
1 parent 3460757 commit 3591f80

File tree

8 files changed

+1000
-11
lines changed

8 files changed

+1000
-11
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ members = [
1717
"shared-memory/program",
1818
"stake-pool/cli",
1919
"stake-pool/program",
20+
"token-lending/cli",
2021
"token-lending/program",
2122
"token-swap/program",
2223
"token-swap/program/fuzz",

token-lending/README.md

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,116 @@
1-
# Token-lending program
1+
# Token Lending program
22

33
A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound.
44

55
Full documentation is available at https://spl.solana.com/token-lending
66

77
Web3 bindings are available in the `./js` directory.
88

9-
### On-Chain Programs
9+
### On-chain programs
10+
11+
Please note that only the lending program deployed to devnet is currently operational.
1012

1113
| Cluster | Program Address |
1214
| --- | --- |
1315
| Mainnet Beta | [`LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi`](https://explorer.solana.com/address/LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi) |
14-
| Testnet | [`LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi`](https://explorer.solana.com/address/LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi?cluster=testnet) |
15-
| Devnet | [`LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi`](https://explorer.solana.com/address/LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi?cluster=devnet) |
16+
| Testnet | [`6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH`](https://explorer.solana.com/address/6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH?cluster=testnet) |
17+
| Devnet | [`6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH`](https://explorer.solana.com/address/6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH?cluster=devnet) |
18+
19+
### Deploy a lending program (optional)
20+
21+
This is optional! You can skip these steps and use the [Token Lending CLI](./cli/README.md) with one of the on-chain programs listed above to create a lending market and add reserves to it.
22+
23+
1. [Install the Solana CLI](https://docs.solana.com/cli/install-solana-cli-tools)
24+
25+
1. Install the Token and Token Lending CLIs:
26+
```shell
27+
cargo install spl-token-cli
28+
cargo install spl-token-lending-cli
29+
```
30+
31+
1. Clone the SPL repo:
32+
```shell
33+
git clone https://github.com/solana-labs/solana-program-library.git
34+
```
35+
36+
1. Go to the new directory:
37+
```shell
38+
cd solana-program-library
39+
```
40+
41+
1. Generate a keypair for yourself:
42+
```shell
43+
solana-keygen new -o owner.json
44+
45+
# Wrote new keypair to owner.json
46+
# ================================================================================
47+
# pubkey: JAgN4SZLNeCo9KTnr8EWt4FzEV1UDgHkcZwkVtWtfp6P
48+
# ================================================================================
49+
# Save this seed phrase and your BIP39 passphrase to recover your new keypair:
50+
# your seed words here never share them not even with your mom
51+
# ================================================================================
52+
```
53+
This pubkey will be the owner of the lending market that can add reserves to it.
54+
55+
1. Generate a keypair for the program:
56+
```shell
57+
solana-keygen new -o lending.json
58+
59+
# Wrote new keypair to lending.json
60+
# ============================================================================
61+
# pubkey: 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH
62+
# ============================================================================
63+
# Save this seed phrase and your BIP39 passphrase to recover your new keypair:
64+
# your seed words here never share them not even with your mom
65+
# ============================================================================
66+
```
67+
This pubkey will be your Program ID.
68+
69+
1. Open `./token-lending/program/src/lib.rs` in your editor. In the line
70+
```rust
71+
solana_program::declare_id!("6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH");
72+
```
73+
replace the Program ID with yours.
74+
75+
1. Build the program binaries:
76+
```shell
77+
cargo build
78+
cargo build-bpf
79+
```
80+
81+
1. Prepare to deploy to devnet:
82+
```shell
83+
solana config set --url https://api.devnet.solana.com
84+
```
85+
86+
1. Score yourself some sweet SOL:
87+
```shell
88+
solana airdrop -k owner.json 10
89+
solana airdrop -k owner.json 10
90+
solana airdrop -k owner.json 10
91+
```
92+
You'll use this for transaction fees, rent for your program accounts, and initial reserve liquidity.
93+
94+
1. Deploy the program:
95+
```shell
96+
solana program deploy \
97+
-k owner.json \
98+
--program-id lending.json \
99+
target/deploy/spl_token_lending.so
100+
101+
# Program Id: 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH
102+
```
103+
If the deployment doesn't succeed, follow [this guide](https://docs.solana.com/cli/deploy-a-program#resuming-a-failed-deploy) to resume it.
104+
105+
1. Wrap some of your SOL as an SPL Token:
106+
```shell
107+
spl-token wrap \
108+
--fee-payer owner.json \
109+
10.0 \
110+
-- owner.json
111+
112+
# Wrapping 10 SOL into AJ2sgpgj6ZeQazPPiDyTYqN9vbj58QMaZQykB9Sr6XY
113+
```
114+
You'll use this for initial reserve liquidity. Note the SPL Token account pubkey (e.g. `AJ2sgpgj6ZeQazPPiDyTYqN9vbj58QMaZQykB9Sr6XY`).
115+
116+
1. Use the [Token Lending CLI](./cli/README.md) to create a lending market and add reserves to it.

token-lending/cli/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
authors = ["Solana Maintainers <[email protected]>"]
3+
description = "SPL Token Lending CLI"
4+
edition = "2018"
5+
homepage = "https://spl.solana.com/token-lending"
6+
license = "Apache-2.0"
7+
name = "spl-token-lending-cli"
8+
repository = "https://github.com/solana-labs/solana-program-library"
9+
version = "0.1.0"
10+
11+
[dependencies]
12+
clap = "2.33.3"
13+
solana-clap-utils = "1.6.6"
14+
solana-cli-config = "1.6.6"
15+
solana-client = "1.6.6"
16+
solana-logger = "1.6.6"
17+
solana-sdk = "1.6.6"
18+
solana-program = "1.6.6"
19+
spl-token-lending = { path="../program", features = [ "no-entrypoint" ] }
20+
spl-token = { path="../../token/program", features = [ "no-entrypoint" ] }
21+
22+
[[bin]]
23+
name = "spl-token-lending"
24+
path = "src/main.rs"

token-lending/cli/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SPL Token Lending CLI
2+
3+
A basic command line interface for initializing lending markets and reserves for SPL Token Lending.
4+
5+
See https://spl.solana.com/token-lending for more details
6+
7+
## Install the CLI
8+
```shell
9+
cargo install spl-token-lending-cli
10+
```
11+
12+
## Deploy a lending program (optional)
13+
14+
This is optional! You can simply add your own market and reserves to the existing [on-chain programs](../README.md#On-chain-programs).
15+
16+
If you want to deploy your own program, follow [this guide](../README.md#Deploy-a-lending-program) and note the program ID.
17+
18+
## Create a lending market
19+
20+
A lending market is a collection of reserves that can be configured to borrow and lend with each other.
21+
22+
The lending market owner must sign to add reserves.
23+
24+
### Usage
25+
```shell
26+
spl-token-lending \
27+
--program PUBKEY \
28+
--fee-payer SIGNER \
29+
create-market \
30+
--market-owner PUBKEY
31+
```
32+
- `--program` is the lending program ID.
33+
- `--fee-payer` will sign to pay transaction fees.
34+
- `--market-owner` is the lending market owner pubkey.
35+
36+
Run `spl-token-lending create-market --help` for more details and options.
37+
38+
### Example
39+
```shell
40+
spl-token-lending \
41+
--program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \
42+
--fee-payer owner.json \
43+
create-market \
44+
--market-owner JAgN4SZLNeCo9KTnr8EWt4FzEV1UDgHkcZwkVtWtfp6P
45+
46+
# Creating lending market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT
47+
# Signature: 51mi4Ve42h4PQ1RXjfz141T6KCdqnB3UDyhEejviVHrX4SnQCMx86TZa9CWUT3efFYkkmfmseG5ZQr2TZTHJ8S95
48+
```
49+
Note the lending market pubkey (e.g. `7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT`). You'll use this to add reserves.
50+
51+
## Add a reserve to your market
52+
53+
A reserve is a liquidity pool that can be deposited into, borrowed from, and optionally used as collateral for borrows.
54+
55+
### Usage
56+
```shell
57+
spl-token-lending \
58+
--program PUBKEY \
59+
--fee-payer SIGNER \
60+
add-reserve \
61+
--market-owner SIGNER \
62+
--source-owner SIGNER \
63+
--market PUBKEY \
64+
--source PUBKEY \
65+
--amount DECIMAL_AMOUNT \
66+
--pyth-product PUBKEY \
67+
--pyth-price PUBKEY
68+
```
69+
- `--program` is the lending program ID.
70+
- `--fee-payer` will sign to pay transaction fees.
71+
- `--market-owner` will sign as the lending market owner.
72+
- `--source-owner` will sign as the source liquidity owner.
73+
- `--market` is the lending market pubkey.
74+
- `--source` is the SPL Token account pubkey (owned by `--source-owner`).
75+
- `--amount` is the amount of tokens to deposit.
76+
- `--pyth-product` and `--pyth-price` are oracle
77+
accounts [provided by Pyth](https://pyth.network/developers/consumers/accounts).
78+
79+
Run `spl-token-lending add-reserve --help` for more details and options.
80+
81+
### Example
82+
```shell
83+
spl-token-lending \
84+
--program 6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH \
85+
--fee-payer owner.json \
86+
add-reserve \
87+
--market-owner owner.json \
88+
--source-owner owner.json \
89+
--market 7uX9ywsk1X2j6wLoywMDVQLNWAqhDpVqZzL4qm4CuMMT \
90+
--source AJ2sgpgj6ZeQazPPiDyTYqN9vbj58QMaZQykB9Sr6XY \
91+
--amount 5.0 \
92+
--pyth-product 8yrQMUyJRnCJ72NWwMiPV9dNGw465Z8bKUvnUC8P5L6F \
93+
--pyth-price BdgHsXrH1mXqhdosXavYxZgX6bGqTdj5mh2sxDhF8bJy
94+
95+
# Adding reserve 69BwFhpQBzZfcp9MCj9V8TLvdv9zGfQQPQbb8dUHsaEa
96+
# Signature: 2yKHnmBSqBpbGdsxW75nnmZMys1bZMbHiczdZitMeQHYdpis4eVhuMWGE29hhgtHpNDjdPj5YVbqkWoAEBw1WaU
97+
# Signature: 33x8gbn2RkiA5844eCZq151DuVrYTvUoF1bQ5xA3mqkibJZaJja2hj8RoyjKZpZqg2ckcSKMAeqWbMeWC6vAySQS
98+
# Signature: 3dk79hSgzFhxPrmctYnS5dxRhojfKkDwwLxEda9bTXqVELHSL4ux8au4jwvL8xuraVhaZAmugCn4TA1YCfLM4sVL
99+
```
100+
101+
Note the reserve pubkey (e.g. `69BwFhpQBzZfcp9MCj9V8TLvdv9zGfQQPQbb8dUHsaEa`). You'll use this to deposit liquidity, redeem collateral, borrow, repay, and liquidate.

0 commit comments

Comments
 (0)