mirror of https://github.com/certusone/oyster.git
Things are mostly working
This commit is contained in:
parent
fcd83b1493
commit
a17fd8d4e3
|
@ -0,0 +1,9 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"lerna": "3.4.3",
|
||||
"npmClient": "npm",
|
||||
"useWorkspaces": true,
|
||||
"packages": ["packages/*"],
|
||||
"version": "independent",
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
|
@ -40,6 +40,10 @@
|
|||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^8.2.0",
|
||||
"@commitlint/config-conventional": "^8.2.0",
|
||||
|
@ -64,6 +68,12 @@
|
|||
"rollup-plugin-typescript2": "^0.25.2",
|
||||
"ts-jest": "^24.0.0",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.1.3"
|
||||
"typescript": "^4.1.3",
|
||||
"@types/react": "^16.9.50",
|
||||
"@types/react-dom": "^16.9.8"
|
||||
},
|
||||
"resolutions": {
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -48,8 +48,8 @@
|
|||
"identicon.js": "^2.3.3",
|
||||
"jazzicon": "^1.5.0",
|
||||
"lodash": "^4.17.20",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-github-btn": "^1.2.0",
|
||||
"react-intl": "^5.10.2",
|
||||
"react-router-dom": "^5.2.0",
|
||||
|
@ -62,13 +62,19 @@
|
|||
"@types/identicon.js": "^2.3.0",
|
||||
"@types/jest": "^24.9.1",
|
||||
"@types/node": "^12.12.62",
|
||||
"@types/react": "^16.9.50",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"arweave-deploy": "^1.9.1",
|
||||
"gh-pages": "^3.1.0",
|
||||
"prettier": "^2.1.2"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
],
|
||||
"peerDependencies": {
|
||||
"react": "*",
|
||||
"react-dom": "*"
|
||||
},
|
||||
"resolutions": {
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,8 +33,8 @@
|
|||
"identicon.js": "^2.3.3",
|
||||
"jazzicon": "^1.5.0",
|
||||
"lodash": "^4.17.20",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-github-btn": "^1.2.0",
|
||||
"react-intl": "^5.10.2",
|
||||
"react-router-dom": "^5.2.0",
|
||||
|
@ -42,6 +42,7 @@
|
|||
"typescript": "^4.1.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prestart": "npm-link-shared ../common/node_modules/ . react",
|
||||
"start": "craco start --verbose",
|
||||
"start:lending": "craco start --verbose",
|
||||
"build": "craco build",
|
||||
|
@ -82,10 +83,17 @@
|
|||
"@types/identicon.js": "^2.3.0",
|
||||
"@types/jest": "^24.9.1",
|
||||
"@types/node": "^12.12.62",
|
||||
"@types/react": "^16.9.50",
|
||||
"@types/react-dom": "^16.9.8",
|
||||
"arweave-deploy": "^1.9.1",
|
||||
"gh-pages": "^3.1.0",
|
||||
"prettier": "^2.1.2"
|
||||
"prettier": "^2.1.2",
|
||||
"npm-link-shared": "0.5.6"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "*",
|
||||
"react-dom": "*"
|
||||
},
|
||||
"resolutions": {
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ export const useLending = () => {
|
|||
const programAccounts = await connection.getProgramAccounts(
|
||||
LENDING_PROGRAM_ID,
|
||||
);
|
||||
console.log('Accounts', programAccounts);
|
||||
|
||||
const accounts = programAccounts
|
||||
.map(processAccount)
|
||||
|
|
|
@ -7,7 +7,8 @@ import BN from 'bn.js';
|
|||
import * as BufferLayout from 'buffer-layout';
|
||||
import { LendingInstruction } from './lending';
|
||||
import { calculateUtilizationRatio, LendingReserve } from './reserve';
|
||||
import { Layout, utils } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
export enum BorrowAmountType {
|
||||
LiquidityBorrowAmount = 0,
|
||||
|
|
|
@ -8,7 +8,9 @@ import * as BufferLayout from 'buffer-layout';
|
|||
import { calculateBorrowAPY } from './borrow';
|
||||
import { LendingInstruction } from './lending';
|
||||
import { calculateUtilizationRatio, LendingReserve } from './reserve';
|
||||
import { Layout, utils } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
/// Deposit liquidity into a reserve. The output is a collateral token representing ownership
|
||||
/// of the reserve liquidity pool.
|
||||
|
|
|
@ -6,7 +6,9 @@ import {
|
|||
import BN from 'bn.js';
|
||||
import { LendingInstruction } from './lending';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { Layout, utils } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
/// Purchase collateral tokens at a discount rate if the chosen obligation is unhealthy.
|
||||
///
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { AccountInfo, PublicKey } from '@solana/web3.js';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { Layout } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
export const LendingMarketLayout: typeof BufferLayout.Structure = BufferLayout.struct(
|
||||
[
|
||||
BufferLayout.u8('version'),
|
||||
|
|
|
@ -8,7 +8,9 @@ import {
|
|||
import BN from 'bn.js';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { LendingInstruction } from '.';
|
||||
import { utils, Layout } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
|
||||
export const LendingObligationLayout: typeof BufferLayout.Structure = BufferLayout.struct(
|
||||
|
|
|
@ -6,7 +6,9 @@ import {
|
|||
import BN from 'bn.js';
|
||||
import { LendingInstruction } from './lending';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { utils, Layout } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
|
||||
/// Repay loaned tokens to a reserve and receive collateral tokens. The obligation balance
|
||||
|
|
|
@ -8,7 +8,9 @@ import {
|
|||
import BN from 'bn.js';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { LendingInstruction } from './lending';
|
||||
import { utils, Layout } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID, wadToLamports } = utils;
|
||||
|
||||
export const LendingReserveLayout: typeof BufferLayout.Structure = BufferLayout.struct(
|
||||
|
|
|
@ -6,7 +6,9 @@ import {
|
|||
import BN from 'bn.js';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
import { LendingInstruction } from './lending';
|
||||
import { utils, Layout } from '@oyster/common';
|
||||
import { utils } from '@oyster/common';
|
||||
import * as Layout from '../../utils/layout';
|
||||
|
||||
const { TOKEN_PROGRAM_ID, LENDING_PROGRAM_ID } = utils;
|
||||
|
||||
export const withdrawInstruction = (
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
import { PublicKey } from '@solana/web3.js';
|
||||
import BN from 'bn.js';
|
||||
import * as BufferLayout from 'buffer-layout';
|
||||
|
||||
/**
|
||||
* Layout for a public key
|
||||
*/
|
||||
export const publicKey = (property = 'publicKey'): unknown => {
|
||||
const publicKeyLayout = BufferLayout.blob(32, property);
|
||||
|
||||
const _decode = publicKeyLayout.decode.bind(publicKeyLayout);
|
||||
const _encode = publicKeyLayout.encode.bind(publicKeyLayout);
|
||||
|
||||
publicKeyLayout.decode = (buffer: Buffer, offset: number) => {
|
||||
const data = _decode(buffer, offset);
|
||||
return new PublicKey(data);
|
||||
};
|
||||
|
||||
publicKeyLayout.encode = (key: PublicKey, buffer: Buffer, offset: number) => {
|
||||
return _encode(key.toBuffer(), buffer, offset);
|
||||
};
|
||||
|
||||
return publicKeyLayout;
|
||||
};
|
||||
|
||||
/**
|
||||
* Layout for a 64bit unsigned value
|
||||
*/
|
||||
export const uint64 = (property = 'uint64'): unknown => {
|
||||
const layout = BufferLayout.blob(8, property);
|
||||
|
||||
const _decode = layout.decode.bind(layout);
|
||||
const _encode = layout.encode.bind(layout);
|
||||
|
||||
layout.decode = (buffer: Buffer, offset: number) => {
|
||||
const data = _decode(buffer, offset);
|
||||
return new BN(
|
||||
[...data]
|
||||
.reverse()
|
||||
.map(i => `00${i.toString(16)}`.slice(-2))
|
||||
.join(''),
|
||||
16,
|
||||
);
|
||||
};
|
||||
|
||||
layout.encode = (num: BN, buffer: Buffer, offset: number) => {
|
||||
const a = num.toArray().reverse();
|
||||
let b = Buffer.from(a);
|
||||
if (b.length !== 8) {
|
||||
const zeroPad = Buffer.alloc(8);
|
||||
b.copy(zeroPad);
|
||||
b = zeroPad;
|
||||
}
|
||||
return _encode(b, buffer, offset);
|
||||
};
|
||||
|
||||
return layout;
|
||||
};
|
||||
|
||||
// TODO: wrap in BN (what about decimals?)
|
||||
export const uint128 = (property = 'uint128'): unknown => {
|
||||
const layout = BufferLayout.blob(16, property);
|
||||
|
||||
const _decode = layout.decode.bind(layout);
|
||||
const _encode = layout.encode.bind(layout);
|
||||
|
||||
layout.decode = (buffer: Buffer, offset: number) => {
|
||||
const data = _decode(buffer, offset);
|
||||
return new BN(
|
||||
[...data]
|
||||
.reverse()
|
||||
.map(i => `00${i.toString(16)}`.slice(-2))
|
||||
.join(''),
|
||||
16,
|
||||
);
|
||||
};
|
||||
|
||||
layout.encode = (num: BN, buffer: Buffer, offset: number) => {
|
||||
const a = num.toArray().reverse();
|
||||
let b = Buffer.from(a);
|
||||
if (b.length !== 16) {
|
||||
const zeroPad = Buffer.alloc(16);
|
||||
b.copy(zeroPad);
|
||||
b = zeroPad;
|
||||
}
|
||||
|
||||
return _encode(b, buffer, offset);
|
||||
};
|
||||
|
||||
return layout;
|
||||
};
|
||||
|
||||
/**
|
||||
* Layout for a Rust String type
|
||||
*/
|
||||
export const rustString = (property = 'string'): unknown => {
|
||||
const rsl = BufferLayout.struct(
|
||||
[
|
||||
BufferLayout.u32('length'),
|
||||
BufferLayout.u32('lengthPadding'),
|
||||
BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars'),
|
||||
],
|
||||
property,
|
||||
);
|
||||
const _decode = rsl.decode.bind(rsl);
|
||||
const _encode = rsl.encode.bind(rsl);
|
||||
|
||||
rsl.decode = (buffer: Buffer, offset: number) => {
|
||||
const data = _decode(buffer, offset);
|
||||
return data.chars.toString('utf8');
|
||||
};
|
||||
|
||||
rsl.encode = (str: string, buffer: Buffer, offset: number) => {
|
||||
const data = {
|
||||
chars: Buffer.from(str, 'utf8'),
|
||||
};
|
||||
return _encode(data, buffer, offset);
|
||||
};
|
||||
|
||||
return rsl;
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
declare module "buffer-layout" {
|
||||
const bl: any;
|
||||
export = bl;
|
||||
}
|
||||
|
||||
declare module "jazzicon" {
|
||||
const jazzicon: any;
|
||||
export = jazzicon;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"moduleResolution": "node",
|
||||
"target": "es6",
|
||||
"module": "es2015",
|
||||
"lib": ["es2015", "es2016", "es2017", "dom"],
|
||||
"strict": true,
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"noImplicitAny": true,
|
||||
"typeRoots": ["types/", "node_modules/@types"]
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
Loading…
Reference in New Issue