Auto approve ray transactions (#99)

This commit is contained in:
Armani Ferrante 2021-02-21 23:52:30 +08:00 committed by GitHub
parent ea7781a1d8
commit 427d0e9cd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 1 deletions

View File

@ -328,7 +328,9 @@ function isSafeInstruction(publicKeys, owner, txInstructions) {
if (!instruction) {
unsafe = true;
} else {
if (['cancelOrder', 'matchOrders'].includes(instruction.type)) {
if (instruction.type === 'raydium') {
// Whitelist raydium for now.
} else if (['cancelOrder', 'matchOrders'].includes(instruction.type)) {
// It is always considered safe to cancel orders, match orders
} else if (instruction.type === 'systemCreate') {
let { newAccountPubkey } = instruction.data;

View File

@ -11,8 +11,12 @@ import {
NEW_ORDER_OPEN_ORDERS_INDEX,
NEW_ORDER_OWNER_INDEX,
} from '@project-serum/serum';
import { PublicKey } from '@solana/web3.js';
import { TOKEN_PROGRAM_ID } from './tokens/instructions';
const RAYDIUM_STAKE_PROGRAM_ID = new PublicKey('EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q');
const RAYDIUM_LP_PROGRAM_ID = new PublicKey('RVKd61ztZW9GUwhRbbLoYVRE5Xf1B2tVscKqwZqXgEr');
const marketCache = {};
let marketCacheConnection = null;
const cacheDuration = 15 * 1000;
@ -99,6 +103,24 @@ const toInstruction = async (
accountKeys,
decodedInstruction,
);
} else if (programId.equals(RAYDIUM_STAKE_PROGRAM_ID)) {
console.log('[' + index + '] Handled as raydium stake instruction');
const decodedInstruction = decodeStakeInstruction(decoded);
return await handleRayStakeInstruction(
connection,
instruction,
accountKeys,
decodedInstruction,
);
} else if (programId.equals(RAYDIUM_LP_PROGRAM_ID)) {
console.log('[' + index + '] Handled as raydium lp instruction');
const decodedInstruction = decodeLpInstruction(decoded);
return await handleRayLpInstruction(
connection,
instruction,
accountKeys,
decodedInstruction,
);
}
} catch {}
@ -108,6 +130,40 @@ const toInstruction = async (
return;
};
const handleRayStakeInstruction = async (
connection,
instruction,
accountKeys,
decodedInstruction,
) => {
// TODO
return {
type: 'raydium',
};
};
const handleRayLpInstruction = async (
connection,
instruction,
accountKeys,
decodedInstruction,
) => {
// TODO
return {
type: 'raydium',
};
};
const decodeStakeInstruction = () => {
// TODO
return undefined;
};
const decodeLpInstruction = () => {
// TODO
return undefined;
};
const handleDexInstruction = async (
connection,
instruction,