create new change spot market form

This commit is contained in:
Maximilian Schneider 2022-01-30 16:00:08 +01:00
parent 64d034ce60
commit 3a0f104ed1
6 changed files with 226 additions and 41 deletions

View File

@ -5,7 +5,7 @@
"@ant-design/icons": "^4.4.0",
"@ant-design/pro-layout": "^6.7.0",
"@babel/preset-typescript": "^7.12.13",
"@blockworks-foundation/mango-client": "^3.2.8",
"@blockworks-foundation/mango-client": "^3.3.11",
"@craco/craco": "^5.7.0",
"@oyster/common": "0.0.1",
"@project-serum/anchor": "^0.11.1",

View File

@ -10,6 +10,7 @@ import { MangoAddSpotMarketForm } from './mangoAddSpotMarketForm';
import { MangoAddOracleForm } from './mangoAddOracleForm';
import { MangoCreatePerpMarketForm } from './mangoCreatePerpMarketForm';
import { MangoChangePerpMarketForm } from './mangoChangePerpMarketForm';
import { MangoChangeSpotMarketForm } from './mangoChangeSpotMarketForm';
export function getGovernanceInstructions(
realm: ParsedAccount<Realm>,
@ -32,6 +33,7 @@ export function getGovernanceInstructions(
instructions.push(InstructionType.MangoAddSpotMarket);
instructions.push(InstructionType.MangoCreatePerpMarket);
instructions.push(InstructionType.MangoChangePerpMarket);
instructions.push(InstructionType.MangoChangeSpotMarket);
}
return instructions;
@ -95,6 +97,13 @@ export function GovernanceInstructionForm({
onCreateInstruction={onCreateInstruction}
></MangoChangePerpMarketForm>
)}
{instruction === InstructionType.MangoChangeSpotMarket && (
<MangoChangeSpotMarketForm
form={form}
governance={governance}
onCreateInstruction={onCreateInstruction}
></MangoChangeSpotMarketForm>
)}
</>
);
}

View File

@ -14,6 +14,7 @@ export enum InstructionType {
MangoAddSpotMarket,
MangoCreatePerpMarket,
MangoChangePerpMarket,
MangoChangeSpotMarket,
}
const instructionNames = [
@ -29,6 +30,7 @@ const instructionNames = [
'mango add spot-market',
'mango create perp-market',
'mango change perp-market',
'mango change spot-market',
];
export function InstructionSelector({

View File

@ -12,6 +12,7 @@ import {
Config,
I80F48,
makeChangePerpMarketParams2Instruction,
optionalBNFromString,
} from '@blockworks-foundation/mango-client';
import BN from 'bn.js';
@ -41,17 +42,17 @@ export const MangoChangePerpMarketForm = ({
}: {
mangoGroupId: string;
perpMarketId: string;
rate: number;
maxDepthBps: number;
exp: number;
mngoPerPeriod: number;
maintLeverage: number;
initLeverage: number;
makerFee: number;
takerFee: number;
liquidationFee: number;
version: number;
lmSizeShift: number;
rate?: string;
maxDepthBps?: string;
exp?: string;
mngoPerPeriod?: string;
maintLeverage?: string;
initLeverage?: string;
makerFee?: string;
takerFee?: string;
liquidationFee?: string;
version?: string;
lmSizeShift?: string;
}) => {
const mangoGroup = new PublicKey(mangoGroupId);
const perpMarket = new PublicKey(perpMarketId);
@ -64,20 +65,22 @@ export const MangoChangePerpMarketForm = ({
mangoGroup,
perpMarket,
governance.pubkey,
maintLeverage ? I80F48.fromNumberOrUndef(maintLeverage) : undefined,
initLeverage ? I80F48.fromNumberOrUndef(initLeverage) : undefined,
liquidationFee ? I80F48.fromNumberOrUndef(liquidationFee) : undefined,
makerFee ? I80F48.fromNumberOrUndef(makerFee) : undefined,
takerFee ? I80F48.fromNumberOrUndef(takerFee) : undefined,
rate ? I80F48.fromNumberOrUndef(rate) : undefined,
maxDepthBps ? I80F48.fromNumberOrUndef(maxDepthBps) : undefined,
I80F48.fromOptionalString(maintLeverage),
I80F48.fromOptionalString(initLeverage),
I80F48.fromOptionalString(liquidationFee),
I80F48.fromOptionalString(makerFee),
I80F48.fromOptionalString(takerFee),
I80F48.fromOptionalString(rate),
I80F48.fromOptionalString(maxDepthBps),
undefined,
mngoPerPeriod
? new BN(Math.round(mngoPerPeriod * Math.pow(10, 6)))
? new BN(
Math.round(((mngoPerPeriod as any) as number) * Math.pow(10, 6)),
)
: undefined,
exp ? new BN(exp) : undefined,
version !== undefined ? new BN(version) : undefined,
lmSizeShift !== undefined ? new BN(lmSizeShift) : undefined,
optionalBNFromString(exp),
optionalBNFromString(version),
optionalBNFromString(lmSizeShift),
);
onCreateInstruction(instruction);

View File

@ -0,0 +1,148 @@
import React from 'react';
import { Form, FormInstance, Input } from 'antd';
import { TransactionInstruction } from '@solana/web3.js';
import { ExplorerLink, ParsedAccount, useConnection } from '@oyster/common';
import { Governance } from '../../../../models/accounts';
import { formDefaults } from '../../../../tools/forms';
import { AccountFormItem } from '../../../../components/AccountFormItem/accountFormItem';
import { PublicKey } from '@solana/web3.js';
import {
Config,
getSpotMarketByBaseSymbol,
getTokenBySymbol,
I80F48,
makeChangeSpotMarketParamsInstruction,
optionalBNFromString,
MangoClient,
} from '@blockworks-foundation/mango-client';
import { Market } from '@project-serum/serum';
export const MangoChangeSpotMarketForm = ({
form,
governance,
onCreateInstruction,
}: {
form: FormInstance;
governance: ParsedAccount<Governance>;
onCreateInstruction: (instruction: TransactionInstruction) => void;
}) => {
const connection = useConnection();
const onCreate = async ({
mangoGroupId,
symbol,
maintLeverage,
initLeverage,
liquidationFee,
optimalUtil,
optimalRate,
maxRate,
version,
}: {
mangoGroupId: string;
symbol: string;
maintLeverage?: string;
initLeverage?: string;
liquidationFee?: string;
optimalUtil?: string;
optimalRate?: string;
maxRate?: string;
version?: string;
}) => {
const mangoGroupPk = new PublicKey(mangoGroupId);
const groupConfig = Config.ids().groups.find(c =>
c.publicKey.equals(mangoGroupPk),
)!;
const client = new MangoClient(connection, groupConfig.mangoProgramId);
const mangoGroup = await client.getMangoGroup(groupConfig.publicKey);
const spotMarketConfig = getSpotMarketByBaseSymbol(groupConfig, symbol);
const spotMarket = await Market.load(
connection,
spotMarketConfig!.publicKey,
undefined,
groupConfig.serumProgramId,
);
const rootBanks = await mangoGroup.loadRootBanks(connection);
const tokenBySymbol = getTokenBySymbol(groupConfig, symbol);
const tokenIndex = mangoGroup.getTokenIndex(tokenBySymbol.mintKey);
const rootBank = rootBanks[tokenIndex];
const instruction = makeChangeSpotMarketParamsInstruction(
groupConfig.mangoProgramId,
mangoGroup.publicKey,
spotMarket.publicKey,
rootBank!.publicKey,
governance.pubkey,
I80F48.fromOptionalString(maintLeverage),
I80F48.fromOptionalString(initLeverage),
I80F48.fromOptionalString(liquidationFee),
I80F48.fromOptionalString(optimalUtil),
I80F48.fromOptionalString(optimalRate),
I80F48.fromOptionalString(maxRate),
optionalBNFromString(version),
);
console.log('changeSpot', {
maintLeverage,
initLeverage,
liquidationFee,
optimalUtil,
optimalRate,
maxRate,
version,
});
onCreateInstruction(instruction);
};
return (
<Form {...formDefaults} form={form} onFinish={onCreate}>
<Form.Item label="program id">
<ExplorerLink
address={governance.info.governedAccount}
type="address"
/>
</Form.Item>
<AccountFormItem
name="mangoGroupId"
label="mango group"
required
></AccountFormItem>
<Form.Item name="symbol" label="spot market base symbol">
<Input type="string" placeholder="" />
</Form.Item>
<Form.Item name="maintLeverage" label="Maint leverage">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="initLeverage" label="Init leverage">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="liquidationFee" label="Liquidation fee">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="optimalUtil" label="optimal utilization ratio">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="optimalRate" label="optimal utilization APR">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="maxRate" label="maximum APR">
<Input type="number" placeholder="" />
</Form.Item>
<Form.Item name="version" label="version">
<Input type="number" placeholder="" />
</Form.Item>
</Form>
);
};

View File

@ -1255,23 +1255,21 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"
"@blockworks-foundation/mango-client@^3.2.8":
version "3.2.8"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.2.8.tgz#1d9bbc01a8157db7abf9c98d2c43098011dd0e3d"
integrity sha512-6VkJ95dV/LTjC6mTHDadBndAHI/nJ8Z8k8ndhrAzjdc9Ki6yC0CZx4Y0cxN1anUyi3StDuX4tZ0ODGWa2l/Jjw==
"@blockworks-foundation/mango-client@^3.3.11":
version "3.3.11"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-client/-/mango-client-3.3.11.tgz#50f9bde9e0aaee7d444dd1afe2201ead9cf80c07"
integrity sha512-F0o7HcEQRv4lWc3J4VmFNzN2TTF/HloO24TCn/0g1kcYuDE0xeCH6EzsiPFVrpmfWBX2SmTvFpnUS+8pBqlYDA==
dependencies:
"@project-serum/anchor" "^0.16.2"
"@project-serum/serum" "0.13.55"
"@project-serum/sol-wallet-adapter" "^0.2.0"
"@solana/spl-token" "^0.1.6"
"@solana/web3.js" "1.21.0"
axios "^0.21.1"
"@solana/web3.js" "^1.31.0"
big.js "^6.1.1"
bigint-buffer "^1.1.5"
bn.js "^5.2.0"
buffer-layout "^1.2.1"
cross-fetch "^3.1.5"
dotenv "^10.0.0"
dotenv-expand "^5.1.0"
yargs "^17.0.1"
"@chaitanyapotti/random-id@^1.0.3":
@ -3213,7 +3211,7 @@
lodash "^4.17.20"
typescript "^4.1.3"
"@solana/web3.js@1.21.0", "@solana/web3.js@1.24.1", "@solana/web3.js@^0.86.2", "@solana/web3.js@^0.90.0", "@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0":
"@solana/web3.js@1.24.1", "@solana/web3.js@^0.86.2", "@solana/web3.js@^0.90.0", "@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.22.0", "@solana/web3.js@^1.31.0":
version "1.24.1"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.24.1.tgz#1fb29f344454669183206f452ab3b8792567cade"
integrity sha512-XImMWAvjcXteMQwe1FFjoe6u72xmcu+UYobPIxLEMX29XXWVTalyYRKBXvcOXwz6DliTYnFXmncNEwUDEFFHGg==
@ -6148,13 +6146,6 @@ big.js@^6.1.1:
resolved "https://registry.yarnpkg.com/big.js/-/big.js-6.1.1.tgz#63b35b19dc9775c94991ee5db7694880655d5537"
integrity sha512-1vObw81a8ylZO5ePrtMay0n018TcftpTA5HFKDaSuiUDBo8biRBtjIobw60OpwuvrGk+FsxKamqN4cnmj/eXdg==
bigint-buffer@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/bigint-buffer/-/bigint-buffer-1.1.5.tgz#d038f31c8e4534c1f8d0015209bf34b4fa6dd442"
integrity sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA==
dependencies:
bindings "^1.3.0"
bignumber.js@^9.0.0, bignumber.js@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5"
@ -6175,7 +6166,7 @@ bind-decorator@^1.0.11:
resolved "https://registry.yarnpkg.com/bind-decorator/-/bind-decorator-1.0.11.tgz#e41bc06a1f65dd9cec476c91c5daf3978488252f"
integrity sha1-5BvAah9l3ZzsR2yRxdrzl4SIJS8=
bindings@^1.2.1, bindings@^1.3.0, bindings@^1.5.0:
bindings@^1.2.1, bindings@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
@ -7669,6 +7660,13 @@ cross-fetch@^2.1.0, cross-fetch@^2.1.1:
node-fetch "2.1.2"
whatwg-fetch "2.0.4"
cross-fetch@^3.1.5:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"
cross-spawn@7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.1.tgz#0ab56286e0f7c24e153d04cc2aa027e43a9a5d14"
@ -8756,7 +8754,7 @@ dot-prop@^5.1.0, dot-prop@^5.2.0:
dependencies:
is-obj "^2.0.0"
dotenv-expand@5.1.0, dotenv-expand@^5.1.0:
dotenv-expand@5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==
@ -14533,6 +14531,13 @@ node-fetch@2.6.1, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0, node-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
node-fetch@2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"
node-fetch@~1.7.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
@ -19688,6 +19693,11 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"
tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
traverse-chain@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/traverse-chain/-/traverse-chain-0.1.0.tgz#61dbc2d53b69ff6091a12a168fd7d433107e40f1"
@ -20826,6 +20836,11 @@ webgl-constants@^1.1.1:
resolved "https://registry.yarnpkg.com/webgl-constants/-/webgl-constants-1.1.1.tgz#f9633ee87fea56647a60b9ce735cbdfb891c6855"
integrity sha512-LkBXKjU5r9vAW7Gcu3T5u+5cvSvh5WwINdr0C+9jpzVB41cjQAP5ePArDtk/WHYdVj0GefCgM73BA7FlIiNtdg==
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
@ -20998,6 +21013,14 @@ whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0, whatwg-mimetype@^2.3.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"
whatwg-url@^6.4.1:
version "6.5.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.5.0.tgz#f2df02bff176fd65070df74ad5ccbb5a199965a8"