Skip to content

Commit 2a6b28c

Browse files
committed
Add examples
1 parent c9a5515 commit 2a6b28c

17 files changed

+1154
-1101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
node_modules
33
/.idea/
4+
/build/

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# openleverage-ts-sdk
1+
# OpenLeverage TypeScript SDK
2+
3+
## Alpha Software
4+
This SDK is currently considered Alpha software and is under active development. It may contain bugs or undergo significant changes. If you have questions or encounter issues, feel free to join our #dev-chat channel on Discord. Pull requests are welcome!
5+
6+
## Description
7+
OpenLeverage TypeScript SDK provides a set of utilities and tools for interacting with the OpenLeverage protocol. This SDK is designed to help developers build and integrate applications with OpenLeverage more efficiently.
8+
9+
## Current Features:
10+
- JSON API to read lending pool information.
11+
- Lending:
12+
- Deposit: Users can deposit their tokens to any pool.
13+
- Withdrawal: Users can withdraw their tokens.
14+
15+
## Upcoming Features:
16+
- Borrowing: Users will be able to borrow assets.
17+
- Margin Trade: Enabling leveraged trading of assets with DEX and aggregator integration.
18+
19+
## Build
20+
```console
21+
yarn build
22+
```
23+
24+
## Run Examples
25+
```console
26+
tsx src/examples/<example_script_name>.ts
27+
```
28+
29+
## Contributing
30+
We welcome contributions! Please see our [Grants Program](https://openleverage.notion.site/OpenLeverage-Grants-Program-63bcd1cd95f242ae8f654230d54340a4?pvs=4) for more details.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@openleverage/sdk",
33
"license": "MIT",
4-
"version": "1.0.0",
4+
"version": "0.1.0",
55
"type": "module",
66
"description": "⚒️ An SDK for building applications on top of OpenLeverage",
77
"main": "dist/index.js",
@@ -20,15 +20,15 @@
2020
"scripts": {
2121
"build": "tsdx build",
2222
"start": "tsdx watch",
23-
"test": "tsdx test",
24-
"prepublishOnly": "tsdx build"
23+
"test": "tsdx test"
2524
},
2625
"dependencies": {
2726
"@ethersproject/address": "^5.0.2",
2827
"big.js": "^5.2.2",
2928
"decimal.js-light": "^2.5.0",
3029
"ethers": "^6.8.0",
3130
"jsbi": "^3.1.4",
31+
"node-fetch": "^3.3.2",
3232
"tiny-invariant": "^1.1.0",
3333
"toformat": "^2.0.0"
3434
},

src/addresses.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/chains.ts

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,61 @@
1-
export enum ChainId {
2-
MAINNET = 1,
3-
GOERLI = 5,
4-
SEPOLIA = 11155111,
5-
OPTIMISM = 10,
6-
OPTIMISM_GOERLI = 420,
7-
ARBITRUM_ONE = 42161,
8-
ARBITRUM_GOERLI = 421613,
9-
POLYGON = 137,
10-
POLYGON_MUMBAI = 80001,
11-
CELO = 42220,
12-
CELO_ALFAJORES = 44787,
13-
GNOSIS = 100,
14-
MOONBEAM = 1284,
15-
BNB = 56,
16-
AVALANCHE = 43114,
17-
BASE_GOERLI = 84531,
18-
BASE = 8453
1+
export enum Chain {
2+
ETHEREUM = "ETHEREUM",
3+
ARBITRUM_ONE = "ARBITRUM_ONE",
4+
BNB = "BNB"
195
}
206

21-
export const SUPPORTED_CHAINS = [
22-
ChainId.MAINNET,
23-
ChainId.ARBITRUM_ONE,
24-
ChainId.BNB
25-
] as const
26-
export type SupportedChainsType = typeof SUPPORTED_CHAINS[number]
7+
type ChainAddresses = {
8+
lpoolDepositor: string
9+
}
2710

2811
export enum NativeCurrencyName {
2912
// Strings match input for CLI
3013
ETHER = 'ETH',
31-
MATIC = 'MATIC',
32-
CELO = 'CELO',
33-
GNOSIS = 'XDAI',
34-
MOONBEAM = 'GLMR',
35-
BNB = 'BNB',
36-
AVAX = 'AVAX'
14+
BNB = 'BNB'
15+
}
16+
17+
type ChainInfo = {
18+
chainId: number;
19+
rpc: string;
20+
addresses: ChainAddresses;
21+
nativeCurrency: NativeCurrencyName;
22+
poolInfoUrl: string;
23+
};
24+
25+
26+
const MAINNET_ADDRESSES: ChainAddresses = {
27+
lpoolDepositor: '0xA6C4bB39F031CC74d4bd005A764E152970762561'
3728
}
29+
30+
const BNB_ADDRESSES: ChainAddresses = {
31+
lpoolDepositor: '0x73FB88ffF5F22ea7276F73832C6334696b7A3541'
32+
}
33+
34+
const ARBITRUM_ONE_ADDRESSES: ChainAddresses = {
35+
lpoolDepositor: '0x3C54c8309c6aE22cEaef9b6aeb94668d7ad7846b'
36+
}
37+
38+
export const chainInfos: { [key in Chain]: ChainInfo } = {
39+
[Chain.ETHEREUM]: {
40+
chainId: 1,
41+
rpc: "https://ethereum.publicnode.com",
42+
addresses: MAINNET_ADDRESSES,
43+
nativeCurrency: NativeCurrencyName.ETHER,
44+
poolInfoUrl: "N/A"
45+
},
46+
[Chain.BNB]: {
47+
chainId: 56,
48+
rpc: "https://bsc-dataseed4.binance.org",
49+
addresses: BNB_ADDRESSES,
50+
nativeCurrency: NativeCurrencyName.BNB,
51+
poolInfoUrl: "https://bnb.openleverage.finance/api/info/pools/interest"
52+
},
53+
[Chain.ARBITRUM_ONE]: {
54+
chainId: 42161,
55+
rpc: "https://arb1.arbitrum.io/rpc",
56+
addresses: ARBITRUM_ONE_ADDRESSES,
57+
nativeCurrency: NativeCurrencyName.ETHER,
58+
poolInfoUrl: "https://arbitrum.openleverage.finance/api/info/pools/interest"
59+
},
60+
};
61+

src/examples.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/examples.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {ethers} from "ethers";
2+
import {LPoolDepositor} from "../lpoolDepositor";
3+
import {chainInfos} from "../chains";
4+
5+
// Example of depositing ERC20 tokens
6+
7+
const PRIVATE_KEY = "YOUR_PRIVATE_KEY_HERE";
8+
9+
let chain = chainInfos.BNB;
10+
const provider = new ethers.JsonRpcProvider(chain.rpc);
11+
12+
// Create a wallet from a private key
13+
const wallet = new ethers.Wallet(PRIVATE_KEY);
14+
15+
// Connect the wallet to the provider
16+
const signer = wallet.connect(provider);
17+
const lpoolDepositor = new LPoolDepositor({provider, signer, contractAddress: chain.addresses.lpoolDepositor});
18+
const usdcAddress = "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d";
19+
20+
const erc20Abi = [
21+
"function approve(address spender, uint256 amount) public returns (bool)"
22+
];
23+
24+
const usdcContract = new ethers.Contract(usdcAddress, erc20Abi, signer);
25+
26+
// You can change poolAddress and amount
27+
const usdcEthPool = "0x360e4262c1eb19529c00009eab9f91360d664bf3";
28+
const amount = 10;
29+
30+
// First, approve the LPoolDepositor contract to move your USDC
31+
const approveTx = await usdcContract.approve(chain.addresses.lpoolDepositor, ethers.parseUnits(amount.toString(), 18));
32+
await approveTx.wait();
33+
34+
await lpoolDepositor.deposit(usdcEthPool, ethers.parseUnits(amount.toString(), 18));
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
import {ethers} from "ethers";
3+
import {LPoolDepositor} from "../lpoolDepositor";
4+
import {chainInfos} from "../chains";
5+
6+
let chain = chainInfos.BNB;
7+
8+
const PRIVATE_KEY = "YOUR_PRIVATE_KEY_HERE";
9+
10+
const provider = new ethers.JsonRpcProvider(chain.rpc);
11+
const wallet = new ethers.Wallet(PRIVATE_KEY);
12+
const signer = wallet.connect(provider);
13+
const lpoolDepositor = new LPoolDepositor({ provider, signer, contractAddress: chain.addresses.lpoolDepositor });
14+
const bnbUsdtPool = "0x7c5e04894410e98b1788fbdb181ffacbf8e60617";
15+
const amount = 0.001;
16+
17+
await lpoolDepositor.depositNative(bnbUsdtPool, amount);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import {PoolDataFetcher} from "../poolDataFetcher";
3+
import {chainInfos} from "../chains";
4+
5+
const fetcher = new PoolDataFetcher(chainInfos.BNB.poolInfoUrl);
6+
7+
fetcher.fetchPoolData()
8+
.then(data => {
9+
// Do something with the data
10+
console.log(data);
11+
})
12+
.catch(error => {
13+
// Handle the error
14+
console.error(`Error fetching data: ${error}`);
15+
});

0 commit comments

Comments
 (0)