Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Lending: cross-collateral+ support #75

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
26418b9
make typeRoots consistent
jordaaash Apr 13, 2021
0a04850
config/tokens.json doesn't exist
jordaaash Apr 13, 2021
91b6fff
simplify parent paths
jordaaash Apr 13, 2021
c4be0d7
models
jordaaash Apr 22, 2021
b9a71a4
actions
jordaaash Apr 22, 2021
1fd342b
hooks
jordaaash Apr 22, 2021
0624bb1
components
jordaaash Apr 22, 2021
7020d41
views
jordaaash Apr 22, 2021
251f2fe
utils
jordaaash Apr 22, 2021
65e65f6
contexts
jordaaash Apr 22, 2021
6296ef3
root
jordaaash Apr 22, 2021
97bc5f7
refactoring
jordaaash Apr 30, 2021
cee89c0
refactoring
jordaaash May 6, 2021
002723f
Merge branch 'main' into lending/xcl-master
jordaaash Jun 10, 2021
955ade8
update state and instructions
jordaaash Jun 11, 2021
5c89ff1
remove quote token mint
jordaaash Jun 11, 2021
3d021c1
add pyth program id
jordaaash Jun 15, 2021
c054734
oracle/dex fixes
jordaaash Jun 15, 2021
df62cdc
fix all actions
jordaaash Jun 15, 2021
5e6daf6
add and fix buffer layout types
jordaaash Jun 15, 2021
934cf06
todos
jordaaash Jun 15, 2021
86ed2f1
sort exports
jordaaash Jun 15, 2021
4a5362b
fix all typescript and lint errors
jordaaash Jun 15, 2021
b013894
add pyth client + hook
jordaaash Jun 17, 2021
30e26ba
mintPubkey is defined
jordaaash Jun 17, 2021
dfc05c4
revise fixme comments
jordaaash Jun 17, 2021
9827db6
pyth context + refactor
jordaaash Jun 17, 2021
33a3fa3
don't parse liquidity oracle as dex market
jordaaash Jun 17, 2021
b95301d
remove bad connections
jordaaash Jun 18, 2021
4769706
add pyth program id
jordaaash Jun 18, 2021
e751324
use oyster/common from file
jordaaash Jun 18, 2021
c2b1dc3
remove unused import
jordaaash Jun 18, 2021
99783c0
add placeholders for lending program ids
jordaaash Jun 18, 2021
258a01c
Merge branch 'main' into lending/xcl
jordaaash Jun 18, 2021
29b352a
update serum, buffer-layout deps
jordaaash Jun 18, 2021
f39b03e
fixing pubkeys
jordaaash Jun 23, 2021
4580be5
fixing config
jordaaash Jun 23, 2021
f811d7a
working on fixing dex market init
jordaaash Jun 23, 2021
aeadf50
refresh reserves and obligation as needed
jordaaash Jun 25, 2021
0027e7d
add devnet tokens from mango
jordaaash Jun 25, 2021
b865087
remove old pyth hook
jordaaash Jun 25, 2021
11d8ba6
fix pyth subscription
jordaaash Jun 25, 2021
1256f4e
fix dex market
jordaaash Jun 25, 2021
ce889d9
shorthand object literals
jordaaash Jun 25, 2021
9d8ad54
[WIP] fix borrowing
jordaaash Jun 25, 2021
64f7ee3
Merge branch 'main' into lending/xcl
jordaaash Jun 25, 2021
05571e5
fix compilation
jordaaash Jun 28, 2021
230582d
add flashloan placeholder
jordaaash Jun 28, 2021
5719ae9
make route components consistent
jordaaash Jun 28, 2021
16ad2b1
obligation init working
jordaaash Jun 29, 2021
9cbb9dd
wallet.info.account doesn't exist
jordaaash Jun 29, 2021
effeeeb
check for reserves, obligations also have a lendingMarket pubkey
jordaaash Jun 29, 2021
6fcbdf1
handle new obligations
jordaaash Jun 29, 2021
fd48391
obligations view
jordaaash Jun 29, 2021
8898bb5
fix setter name
jordaaash Jun 29, 2021
b4255ea
update deps, add @solana/spl-token-lending
jordaaash Jul 2, 2021
dce8607
remove broken views
jordaaash Jul 2, 2021
682c1ed
models and instructions extracted to lib
jordaaash Jul 2, 2021
944758b
refactor after lib move
jordaaash Jul 2, 2021
dde74ae
more ui refactoring after views removed
jordaaash Jul 2, 2021
10a6a5d
Merge branch 'main' into lending/xcl
jordaaash Jul 2, 2021
e8fae31
more refactoring
jordaaash Jul 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"prepare": "run-s clean build"
},
"dependencies": {
"@project-serum/serum": "^0.13.11",
"@project-serum/serum": "^0.13.38",
"@project-serum/sol-wallet-adapter": "^0.1.4",
"@solana/spl-token": "0.0.13",
"@solana/spl-token-swap": "0.1.0",
Expand All @@ -44,7 +44,7 @@
"bn.js": "^5.1.3",
"borsh": "^0.3.1",
"bs58": "^4.0.1",
"buffer-layout": "^1.2.0",
"buffer-layout": "^1.2.1",
"eventemitter3": "^4.0.7",
"identicon.js": "^2.3.3",
"jazzicon": "^1.5.0",
Expand Down
80 changes: 49 additions & 31 deletions packages/common/src/contexts/connection.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { sleep, useLocalStorageState } from '../utils/utils';
import {
ENV as ChainId,
TokenInfo,
TokenListProvider,
} from '@solana/spl-token-registry';
import {
Account,
BlockhashAndFeeCalculator,
Expand All @@ -13,24 +18,17 @@ import {
TransactionSignature,
} from '@solana/web3.js';
import React, { useContext, useEffect, useMemo, useState } from 'react';
import { notify } from '../utils/notifications';
import { ExplorerLink } from '../components/ExplorerLink';
import { setProgramIds } from '../utils/ids';
import {
TokenInfo,
TokenListProvider,
ENV as ChainId,
} from '@solana/spl-token-registry';
import { notify } from '../utils/notifications';
import { SendTransactionError, SignTransactionError } from '../utils/errors';

export type ENV =
| 'mainnet-beta (Serum)'
| 'mainnet-beta'
| 'mainnet-beta (Serum)'
| 'testnet'
| 'devnet'
| 'localnet'
| 'lending';
| 'localnet';

export const ENDPOINTS = [
{
Expand Down Expand Up @@ -58,16 +56,6 @@ export const ENDPOINTS = [
endpoint: 'http://127.0.0.1:8899',
ChainId: ChainId.Devnet,
},
{
name: 'Oyster Dev' as ENV,
endpoint: 'http://oyster-dev.solana.com/',
ChainId: ChainId.Devnet,
},
{
name: 'Lending' as ENV,
endpoint: 'https://tln.solana.com/',
ChainId: ChainId.Devnet,
},
];

const DEFAULT = ENDPOINTS[0].endpoint;
Expand Down Expand Up @@ -108,14 +96,12 @@ export function ConnectionProvider({ children = undefined as any }) {
DEFAULT_SLIPPAGE.toString(),
);

const connection = useMemo(
() => new Connection(endpoint, 'recent'),
[endpoint],
);
const sendConnection = useMemo(
() => new Connection(endpoint, 'recent'),
[endpoint],
);
const connection = useMemo(() => new Connection(endpoint, 'recent'), [
endpoint,
]);
const sendConnection = useMemo(() => new Connection(endpoint, 'recent'), [
endpoint,
]);

const env =
ENDPOINTS.find(end => end.endpoint === endpoint)?.name || ENDPOINTS[0].name;
Expand All @@ -125,21 +111,53 @@ export function ConnectionProvider({ children = undefined as any }) {
useEffect(() => {
// fetch token files
new TokenListProvider().resolve().then(container => {
const list = container
const tokens = container
.excludeByTag('nft')
.filterByChainId(
ENDPOINTS.find(end => end.endpoint === endpoint)?.ChainId ||
ChainId.MainnetBeta,
)
.getList();

const knownMints = [...list].reduce((map, item) => {
// @FIXME: remove hardcoded values
if (endpoint.ChainId === ChainId.Devnet) {
tokens.push(
{
chainId: 103,
address: '9FbAMDvXqNjPqZSYt4EWTguJuDrGkfvwr3gSFpiSbX9S',
symbol: 'SRM',
name: 'Serum',
decimals: 6,
logoURI:
'https://cdn.jsdelivr.net/gh/trustwallet/assets@master/blockchains/ethereum/assets/0x476c5E26a75bd202a9683ffD34359C0CC15be0fF/logo.png',
tags: [],
extensions: {
website: 'https://projectserum.com/',
},
},
{
chainId: 103,
address: '7KBVenLz5WNH4PA5MdGkJNpDDyNKnBQTwnz1UqJv9GUm',
symbol: 'USDT',
name: 'USDT',
decimals: 6,
logoURI:
'https://cdn.jsdelivr.net/gh/solana-labs/explorer/public/tokens/usdt.svg',
tags: ['stablecoin'],
extensions: {
website: 'https://tether.to/',
},
},
);
}

const tokenMap = tokens.reduce((map, item) => {
map.set(item.address, item);
return map;
}, new Map<string, TokenInfo>());

setTokenMap(knownMints);
setTokens(list);
setTokenMap(tokenMap);
setTokens(tokens);
});
}, [env]);

Expand Down
23 changes: 9 additions & 14 deletions packages/common/src/utils/ids.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { PublicKey } from '@solana/web3.js';
import { TokenSwapLayout, TokenSwapLayoutV1 } from '../models/tokenSwap';

export let SYSTEM = new PublicKey('11111111111111111111111111111111');
export const WRAPPED_SOL_MINT = new PublicKey(
'So11111111111111111111111111111111111111112',
);
export let TOKEN_PROGRAM_ID = new PublicKey(
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
);

export let LENDING_PROGRAM_ID = new PublicKey(
'LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi',
);

export let SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = new PublicKey(
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
);
Expand All @@ -21,24 +20,21 @@ export let BPF_UPGRADE_LOADER_ID = new PublicKey(
export let METADATA_PROGRAM_ID = new PublicKey(
'metaTA73sFPqA8whreUbBsbn3SLJH2vhrW9fP5dmfdC',
);

export const MEMO_ID = new PublicKey(
'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr',
);

export const VAULT_ID = new PublicKey(
'94wRaYAQdC2gYF76AUTYSugNJ3rAC4EimjAMPwM7uYry',
);

export const AUCTION_ID = new PublicKey(
'C9nHkL6BfGx9M9MyYrJqAD5hPsGJd1fHpp1uAJA6vTCn',
);

export const METAPLEX_ID = new PublicKey(
'EPtpKdKW8qciGVd1UFyGjgbBHTbSAyvbY61h9uQGVgeu',
);

export let SYSTEM = new PublicKey('11111111111111111111111111111111');
export const PYTH_PROGRAM_ID = new PublicKey(
'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
);

let WORMHOLE_BRIDGE: {
pubkey: PublicKey;
Expand Down Expand Up @@ -84,6 +80,7 @@ export const PROGRAM_IDS = [
// new PublicKey("9qvG1zUp8xF1Bi4m6UdRNby1BAAuaDrUxSpv4CmRRMjL"),
],
}),
lending: () => new PublicKey('LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi'),
},
{
name: 'testnet',
Expand All @@ -102,8 +99,8 @@ export const PROGRAM_IDS = [
},
legacy: [],
}),
lending: () => new PublicKey('6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH'),
},

{
name: 'devnet',
governance: () => ({
Expand All @@ -121,6 +118,7 @@ export const PROGRAM_IDS = [
},
legacy: [new PublicKey('BSfTAcBdqmvX5iE2PW88WFNNp2DHhLUaBKk5WrnxVkcJ')],
}),
lending: () => new PublicKey('6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH'),
},
{
name: 'localnet',
Expand All @@ -139,6 +137,7 @@ export const PROGRAM_IDS = [
},
legacy: [],
}),
lending: () => new PublicKey('6TvznH3B2e3p2mbhufNBpgSrLx6UkgvxtVQvopEZ2kuH'),
},
];

Expand All @@ -158,11 +157,7 @@ export const setProgramIds = (envName: string) => {

GOVERNANCE = instance.governance();

if (envName === 'mainnet-beta') {
LENDING_PROGRAM_ID = new PublicKey(
'LendZqTs7gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi',
);
}
LENDING_PROGRAM_ID = instance.lending();
};

export const programIds = () => {
Expand Down
1 change: 1 addition & 0 deletions packages/lending/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
24 changes: 13 additions & 11 deletions packages/lending/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "lending",
"version": "0.1.0",
"dependencies": {
"@solana/wallet-base": "0.0.1",
"@solana/wallet-ledger": "0.0.1",
"@ant-design/icons": "^4.4.0",
"@ant-design/pro-layout": "^6.7.0",
"@babel/preset-typescript": "^7.12.13",
"@craco/craco": "^5.7.0",
"@oyster/common": "0.0.1",
"@project-serum/serum": "^0.13.11",
"@project-serum/serum": "^0.13.38",
"@project-serum/sol-wallet-adapter": "^0.1.4",
"@solana/spl-token": "0.0.13",
"@solana/spl-token-swap": "0.1.0",
"@solana/web3.js": "^1.5.0",
"@pythnetwork/client": "^2.0.0",
"@solana/spl-token": "^0.1.6",
"@solana/spl-token-lending": "^0.3.3",
"@solana/spl-token-swap": "^0.1.0",
"@solana/wallet-base": "0.0.1",
"@solana/wallet-ledger": "0.0.1",
"@solana/web3.js": "^1.20.0",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
Expand All @@ -23,9 +25,9 @@
"@types/testing-library__react": "^10.2.0",
"@welldone-software/why-did-you-render": "^6.0.5",
"antd": "^4.6.6",
"bignumber.js": "^9.0.1",
"bn.js": "^5.1.3",
"bs58": "^4.0.1",
"buffer-layout": "^1.2.0",
"chart.js": "^2.9.4",
"craco-alias": "^2.1.1",
"craco-babel-loader": "^0.1.4",
Expand All @@ -46,7 +48,6 @@
"scripts": {
"prestart": "npm-link-shared ../common/node_modules/ . react",
"start": "craco start --verbose",
"start:lending": "craco start --verbose",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
Expand Down Expand Up @@ -87,15 +88,16 @@
"@types/node": "^12.12.62",
"arweave-deploy": "^1.9.1",
"gh-pages": "^3.1.0",
"prettier": "^2.1.2",
"npm-link-shared": "0.5.6"
"npm-link-shared": "0.5.6",
"prettier": "^2.1.2"
},
"peerDependencies": {
"react": "*",
"react-dom": "*"
},
"resolutions": {
"react": "16.13.1",
"react-dom": "16.13.1"
"react-dom": "16.13.1",
"@oyster/common": "file:../common/dist/lib"
}
}
6 changes: 3 additions & 3 deletions packages/lending/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import "./App.less";
import { Routes } from "./routes";
import React from 'react';
import './App.less';
import { Routes } from './routes';

function App() {
return <Routes />;
Expand Down
Loading