stash
This commit is contained in:
parent
9d87589c2b
commit
bb04675789
|
@ -8,7 +8,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/roboto": "^4.3.0",
|
"@fontsource/roboto": "^4.3.0",
|
||||||
"@project-serum/serum": "^0.13.34",
|
"@project-serum/serum": "^0.13.34",
|
||||||
"@project-serum/swap": "^0.1.0-alpha.15",
|
"@project-serum/swap": "^0.1.0-alpha.17",
|
||||||
"@solana/spl-token": "^0.1.4"
|
"@solana/spl-token": "^0.1.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
"@project-serum/anchor": "^0.7.0",
|
"@project-serum/anchor": "^0.7.0",
|
||||||
"@project-serum/serum": "^0.13.34",
|
"@project-serum/serum": "^0.13.34",
|
||||||
"@project-serum/sol-wallet-adapter": "^0.2.0",
|
"@project-serum/sol-wallet-adapter": "^0.2.0",
|
||||||
"@project-serum/swap": "^0.1.0-alpha.15",
|
"@project-serum/swap": "^0.1.0-alpha.17",
|
||||||
"@solana/spl-token": "^0.1.4",
|
"@solana/spl-token": "^0.1.4",
|
||||||
"@solana/spl-token-registry": "^0.2.86",
|
"@solana/spl-token-registry": "^0.2.86",
|
||||||
"@solana/web3.js": "^1.10.1",
|
"@solana/web3.js": "^1.10.1",
|
||||||
|
|
|
@ -25,6 +25,7 @@ import { Close } from "@material-ui/icons";
|
||||||
import { useMarket, useOpenOrders, useDexContext } from "../context/Dex";
|
import { useMarket, useOpenOrders, useDexContext } from "../context/Dex";
|
||||||
import { useTokenMap } from "../context/TokenList";
|
import { useTokenMap } from "../context/TokenList";
|
||||||
import { useMint, useOwnedTokenAccount } from "../context/Token";
|
import { useMint, useOwnedTokenAccount } from "../context/Token";
|
||||||
|
import { DEX_PID } from '../utils/pubkeys';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
table: {},
|
table: {},
|
||||||
|
@ -170,9 +171,15 @@ function OpenOrdersRow({
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeOpenOrders = async () => {
|
const closeOpenOrders = async () => {
|
||||||
// TODO.
|
await swapClient.program.rpc.closeAccount({
|
||||||
//
|
accounts: {
|
||||||
// Blocked by https://github.com/project-serum/serum-dex/pull/112.
|
openOrders: ooAccount.address,
|
||||||
|
authority: swapClient.program.provider.wallet.publicKey,
|
||||||
|
destination: swapClient.program.provider.wallet.publicKey,
|
||||||
|
market: marketClient!.address,
|
||||||
|
dexProgram: DEX_PID,
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -303,7 +303,7 @@ function TokenName({ mint, style }: { mint: PublicKey; style: any }) {
|
||||||
|
|
||||||
function SwapButton() {
|
function SwapButton() {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const { fromMint, toMint, fromAmount, slippage, isClosingNewAccounts } =
|
const { fromMint, toMint, fromAmount, slippage, isClosingNewAccounts, isStrict } =
|
||||||
useSwapContext();
|
useSwapContext();
|
||||||
const { swapClient } = useDexContext();
|
const { swapClient } = useDexContext();
|
||||||
const fromMintInfo = useMint(fromMint);
|
const fromMintInfo = useMint(fromMint);
|
||||||
|
@ -330,15 +330,18 @@ function SwapButton() {
|
||||||
if (!fair) {
|
if (!fair) {
|
||||||
throw new Error("Invalid fair");
|
throw new Error("Invalid fair");
|
||||||
}
|
}
|
||||||
const amount = new BN(fromAmount).mul(
|
if (!route || route.markets.length === 0) {
|
||||||
new BN(10).pow(new BN(fromMintInfo.decimals))
|
throw new Error('Invalid route');
|
||||||
);
|
}
|
||||||
|
const amount = new BN(fromAmount*10**fromMintInfo.decimals);
|
||||||
|
console.log('amount', route, fair.toString(), fromAmount.toString(), amount.toString());
|
||||||
const minExchangeRate = {
|
const minExchangeRate = {
|
||||||
rate: new BN(10 ** toMintInfo.decimals * (1 - BASE_TAKER_FEE_BPS))
|
rate: new BN(10 ** toMintInfo.decimals * (1 - BASE_TAKER_FEE_BPS)**route.markets.length)
|
||||||
.divn(fair)
|
.divn(fair)
|
||||||
.muln(100 - slippage)
|
.muln(100 - slippage)
|
||||||
.divn(100),
|
.divn(100),
|
||||||
decimals: fromMintInfo.decimals,
|
decimals: fromMintInfo.decimals,
|
||||||
|
strict: isStrict,
|
||||||
};
|
};
|
||||||
const fromOpenOrders = fromMarket
|
const fromOpenOrders = fromMarket
|
||||||
? openOrders.get(fromMarket?.address.toString())
|
? openOrders.get(fromMarket?.address.toString())
|
||||||
|
@ -353,7 +356,7 @@ function SwapButton() {
|
||||||
toWallet: toWallet ? toWallet.publicKey : undefined,
|
toWallet: toWallet ? toWallet.publicKey : undefined,
|
||||||
amount,
|
amount,
|
||||||
minExchangeRate,
|
minExchangeRate,
|
||||||
referral,
|
referral,
|
||||||
// Pass in the below parameters so that the client doesn't perform
|
// Pass in the below parameters so that the client doesn't perform
|
||||||
// wasteful network requests when we already have the data.
|
// wasteful network requests when we already have the data.
|
||||||
fromMarket,
|
fromMarket,
|
||||||
|
|
|
@ -56,6 +56,13 @@ export type SwapContext = {
|
||||||
// True if all newly created market accounts should be closed in the
|
// True if all newly created market accounts should be closed in the
|
||||||
// same user flow (ideally in the same transaction).
|
// same user flow (ideally in the same transaction).
|
||||||
isClosingNewAccounts: boolean;
|
isClosingNewAccounts: boolean;
|
||||||
|
|
||||||
|
// True if the swap exchange rate should be a function of nothing but the
|
||||||
|
// from and to tokens, ignoring any quote tokens that may have been
|
||||||
|
// accumulated by performing the swap.
|
||||||
|
isStrict: boolean;
|
||||||
|
setIsStrict: (isStrict: boolean) => void;
|
||||||
|
|
||||||
setIsClosingNewAccounts: (b: boolean) => void;
|
setIsClosingNewAccounts: (b: boolean) => void;
|
||||||
};
|
};
|
||||||
const _SwapContext = React.createContext<null | SwapContext>(null);
|
const _SwapContext = React.createContext<null | SwapContext>(null);
|
||||||
|
@ -66,6 +73,7 @@ export function SwapContextProvider(props: any) {
|
||||||
const [fromAmount, _setFromAmount] = useState(props.fromAmount ?? 0);
|
const [fromAmount, _setFromAmount] = useState(props.fromAmount ?? 0);
|
||||||
const [toAmount, _setToAmount] = useState(props.toAmount ?? 0);
|
const [toAmount, _setToAmount] = useState(props.toAmount ?? 0);
|
||||||
const [isClosingNewAccounts, setIsClosingNewAccounts] = useState(false);
|
const [isClosingNewAccounts, setIsClosingNewAccounts] = useState(false);
|
||||||
|
const [isStrict, setIsStrict] = useState(false);
|
||||||
const [slippage, setSlippage] = useState(DEFAULT_SLIPPAGE_PERCENT);
|
const [slippage, setSlippage] = useState(DEFAULT_SLIPPAGE_PERCENT);
|
||||||
const [fairOverride, setFairOverride] = useState<number | null>(null);
|
const [fairOverride, setFairOverride] = useState<number | null>(null);
|
||||||
const fair = _useSwapFair(fromMint, toMint, fairOverride);
|
const fair = _useSwapFair(fromMint, toMint, fairOverride);
|
||||||
|
@ -117,6 +125,8 @@ export function SwapContextProvider(props: any) {
|
||||||
fairOverride,
|
fairOverride,
|
||||||
setFairOverride,
|
setFairOverride,
|
||||||
isClosingNewAccounts,
|
isClosingNewAccounts,
|
||||||
|
isStrict,
|
||||||
|
setIsStrict,
|
||||||
setIsClosingNewAccounts,
|
setIsClosingNewAccounts,
|
||||||
referral,
|
referral,
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1654,10 +1654,10 @@
|
||||||
bs58 "^4.0.1"
|
bs58 "^4.0.1"
|
||||||
eventemitter3 "^4.0.4"
|
eventemitter3 "^4.0.4"
|
||||||
|
|
||||||
"@project-serum/swap@^0.1.0-alpha.15":
|
"@project-serum/swap@^0.1.0-alpha.17":
|
||||||
version "0.1.0-alpha.15"
|
version "0.1.0-alpha.17"
|
||||||
resolved "https://registry.yarnpkg.com/@project-serum/swap/-/swap-0.1.0-alpha.15.tgz#3650294c579e99c60dd502ce6bdea5ac55a90f3d"
|
resolved "https://registry.yarnpkg.com/@project-serum/swap/-/swap-0.1.0-alpha.17.tgz#06532c7ccbd2c2caf62b1b179bf39697b7f0aa17"
|
||||||
integrity sha512-/388h8vXzhZ5koeXjeXIJk8gErbGdDqVzhH/W09XLKl7p//eiJ7DWdFUKVPZxUaHe8XhYrWoRzbWdBOvUXmdYA==
|
integrity sha512-9SxUqtNzbbPo9ywxaTQEtbkalhQFfUUXiOmuQs2N5rLHl9gPm0u/SKrMi35ZtJ49f+v86ZVL4w4Gbqdclc6niA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@project-serum/serum" "^0.13.34"
|
"@project-serum/serum" "^0.13.34"
|
||||||
"@solana/spl-token" "^0.1.3"
|
"@solana/spl-token" "^0.1.3"
|
||||||
|
|
Loading…
Reference in New Issue