added more of the fee tier functions

This commit is contained in:
dd 2021-02-17 10:36:48 -05:00
parent 0273db2c5b
commit fa266a6e89
3 changed files with 46 additions and 18 deletions

View File

@ -1,7 +1,5 @@
CLUSTER=devnet
DEX_PROGRAM_ID=7ZTHT7CnBrXiEmGAiTTdAzgu2RdRyP61Knwy2ifGhL1x
KEYPAIR=~/.config/solana/id.json
BTCUSD=6pZpjgfwKJhQ93ZYNjbJFtWEaB8kZjErsiGAEXn9WNjn
BTC_WALLET=HLoPtihB8oETm1kkTpx17FEnXm7afQdS4hojTNvbg3Rg
USDC_WALLET=GBBtcVE7WA8qdrHyhWTZkYDaz71EVHsg7wVaca9iq9xs
BTC=C6kYXcaRUMqeBF5fhg165RWU7AnpT9z92fvKNoMqjmz6

View File

@ -28,7 +28,7 @@ import {
zeroKey,
} from './utils';
import { Market, OpenOrders, Orderbook } from '@project-serum/serum';
import { TOKEN_PROGRAM_ID } from '@project-serum/serum/lib/token-instructions';
import { SRM_DECIMALS, TOKEN_PROGRAM_ID } from '@project-serum/serum/lib/token-instructions';
import { Order } from '@project-serum/serum/lib/market';
import Wallet from '@project-serum/sol-wallet-adapter';
@ -49,6 +49,7 @@ export class MangoGroup {
totalBorrows!: number[];
maintCollRatio!: number;
initCollRatio!: number;
srmVault!: PublicKey;
mintDecimals!: number[];
oracleDecimals!: number[];
@ -421,8 +422,7 @@ export class MangoClient {
{ isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID },
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
...marginAccount.openOrders.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.oracles.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.tokens.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.oracles.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey }))
]
const data = encodeMangoInstruction({Withdraw: {quantity: nativeQuantity}})
@ -456,7 +456,6 @@ export class MangoClient {
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
...marginAccount.openOrders.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.oracles.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.tokens.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
]
const data = encodeMangoInstruction({Borrow: {tokenIndex: new BN(tokenIndex), quantity: nativeQuantity}})
@ -603,7 +602,6 @@ export class MangoClient {
...mangoGroup.oracles.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
...mangoGroup.vaults.map( (pubkey) => ( { isSigner: false, isWritable: true, pubkey })),
...tokenAccs.map( (pubkey) => ( { isSigner: false, isWritable: true, pubkey })),
...mangoGroup.tokens.map( (pubkey) => ( { isSigner: false, isWritable: false, pubkey })),
]
const data = encodeMangoInstruction({Liquidate: {depositQuantities: depositsBN}})
@ -617,6 +615,38 @@ export class MangoClient {
return await this.sendTransaction(connection, transaction, liqor, additionalSigners)
}
async depositSrm(
connection: Connection,
programId: PublicKey,
mangoGroup: MangoGroup,
marginAccount: MarginAccount,
owner: Account,
srmAccount: PublicKey,
quantity: number
): Promise<TransactionSignature> {
const nativeQuantity = uiToNative(quantity, SRM_DECIMALS)
const keys = [
{ isSigner: false, isWritable: true, pubkey: mangoGroup.publicKey },
{ isSigner: false, isWritable: true, pubkey: marginAccount.publicKey },
{ isSigner: true, isWritable: false, pubkey: owner.publicKey },
{ isSigner: false, isWritable: true, pubkey: srmAccount },
{ isSigner: false, isWritable: true, pubkey: mangoGroup.srmVault },
{ isSigner: false, isWritable: false, pubkey: TOKEN_PROGRAM_ID },
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY }
]
const data = encodeMangoInstruction({DepositSrm: {quantity: nativeQuantity}})
const instruction = new TransactionInstruction( { keys, data, programId })
const transaction = new Transaction()
transaction.add(instruction)
const additionalSigners = []
return await this.sendTransaction(connection, transaction, owner, additionalSigners)
}
async placeOrder(
connection: Connection,
programId: PublicKey,

View File

@ -6,11 +6,11 @@
"testnet": "https://testnet.solana.com"
},
"devnet": {
"dex_program_id": "7ZTHT7CnBrXiEmGAiTTdAzgu2RdRyP61Knwy2ifGhL1x",
"dex_program_id": "6XffKSLZRxmQcRinmb4K32AegYnmkoTm6TLR2Ezp9FBR",
"fee_symbol": "SRM",
"mango_groups": {
"BTC_ETH_USDC": {
"mango_group_pk": "Fc23A6NHH7uaAvVEpKAn4pgJ8FDs4LCSoNcRybPCKKfC",
"mango_group_pk": "8YGmg6rNc3bcZ7wDxu5CAhrSFCdJvzJUKjvmQcC7tjTr",
"mint_pks": [
"C6kYXcaRUMqeBF5fhg165RWU7AnpT9z92fvKNoMqjmz6",
"8p968u9m7jZzKSsqxFDqki69MjqdFkwPM9FN4AN8hvHR",
@ -21,8 +21,8 @@
"DBiZZ6riT6QVoGVBMBnSsYFwkie1GAxWdac3NCpyrDR1"
],
"spot_market_pks": [
"FeLCvwGXvd6WYwAFTWaFrXH74uVzHLAtfwpSAU7jn3fu",
"3SuA63cG46PDZCbS2FfS7mMESBQdJwWwhj1QeUAGjpBh"
"DY6X83vWk5VdHQEtVxFdecmEsGXHyLskkeQeo8BHn75s",
"CQwr1dHHPeoUpzGcQHLtEYE1LdXkszxha8oG6Y7v5KWZ"
],
"symbols": {
"BTC": "C6kYXcaRUMqeBF5fhg165RWU7AnpT9z92fvKNoMqjmz6",
@ -30,9 +30,9 @@
"USDC": "Fq939Y5hycK62ZGwBjftLY2VyxqAQ8f1MxRqBMdAaBS7"
},
"vault_pks": [
"8WPAJohEVoytU2YkdzDeFyygR3274vU35i7o2XiUvYkT",
"2Sdwi6Q66bmva7e4XBTzuMBSJG6T7TWQKusZcYFmSGxV",
"DXX8Tg8b5KPAqJ9FBymMmTpJHyhtVJ6Zw8Ys2sCaKR5A"
"FEg4ZjKMJFeKXLatYXpMCmQZGh8GAidy2yCqBVVKGQhA",
"FQTRzLbKpcX3mSGWASD2m2QfAhSDUx4eVYjb2bSFq9ry",
"2bQtsdueSHcBmtsbq9NhjegVzXvwU8yLCKkkQXbarEbr"
]
}
},
@ -42,14 +42,14 @@
"ETH/USDC": "DBiZZ6riT6QVoGVBMBnSsYFwkie1GAxWdac3NCpyrDR1"
},
"spot_markets": {
"BTC/USDC": "FeLCvwGXvd6WYwAFTWaFrXH74uVzHLAtfwpSAU7jn3fu",
"ETH/USDC": "3SuA63cG46PDZCbS2FfS7mMESBQdJwWwhj1QeUAGjpBh"
"BTC/USDC": "DY6X83vWk5VdHQEtVxFdecmEsGXHyLskkeQeo8BHn75s",
"ETH/USDC": "CQwr1dHHPeoUpzGcQHLtEYE1LdXkszxha8oG6Y7v5KWZ"
},
"symbols": {
"BTC": "C6kYXcaRUMqeBF5fhg165RWU7AnpT9z92fvKNoMqjmz6",
"ETH": "8p968u9m7jZzKSsqxFDqki69MjqdFkwPM9FN4AN8hvHR",
"MSRM": "ZbVY71sQNng1uFNvgimLfWXeWyasDvou9bEcqexzYaT",
"SRM": "2i6G2zTaJNeuuJUjrFAvdP7xvquDZREubRUWNwB3xsKQ",
"MSRM": "934bNdNw9QfE8dXD4mKQiKajYURfSkPhxfYZzpvmygca",
"SRM": "9FbAMDvXqNjPqZSYt4EWTguJuDrGkfvwr3gSFpiSbX9S",
"USDC": "Fq939Y5hycK62ZGwBjftLY2VyxqAQ8f1MxRqBMdAaBS7",
"USDT": "7tSPGVhneTBWZjLGJGZb9V2UntC7T98cwtSLtgcXjeSs"
}