mirror of https://github.com/certusone/oyster.git
feat: revoke instruction
This commit is contained in:
parent
29387bb974
commit
51862fcbde
|
@ -25,6 +25,7 @@ import {
|
|||
LendingMarket,
|
||||
BorrowAmountType,
|
||||
LendingObligation,
|
||||
approve,
|
||||
} from "../models";
|
||||
import { toLamports } from "../utils/utils";
|
||||
|
||||
|
@ -161,15 +162,13 @@ export const borrow = async (
|
|||
);
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
fromLamports
|
||||
)
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
fromLamports
|
||||
);
|
||||
|
||||
const dexMarketAddress = borrowReserve.info.dexMarketOption
|
||||
|
|
|
@ -11,14 +11,14 @@ import {
|
|||
initReserveInstruction,
|
||||
LendingReserve,
|
||||
} from "./../models/lending";
|
||||
import { AccountLayout, Token } from "@solana/spl-token";
|
||||
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../constants/ids";
|
||||
import { AccountLayout } from "@solana/spl-token";
|
||||
import { LENDING_PROGRAM_ID } from "../constants/ids";
|
||||
import {
|
||||
createUninitializedAccount,
|
||||
ensureSplAccount,
|
||||
findOrCreateAccountByMint,
|
||||
} from "./account";
|
||||
import { TokenAccount } from "../models";
|
||||
import { approve, TokenAccount } from "../models";
|
||||
|
||||
export const deposit = async (
|
||||
from: TokenAccount,
|
||||
|
@ -60,15 +60,13 @@ export const deposit = async (
|
|||
);
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
amountLamports
|
||||
)
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
amountLamports
|
||||
);
|
||||
|
||||
let toAccount: PublicKey;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { liquidateInstruction } from "./../models/lending/liquidate";
|
|||
import { AccountLayout, Token } from "@solana/spl-token";
|
||||
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../constants/ids";
|
||||
import { createTempMemoryAccount, ensureSplAccount, findOrCreateAccountByMint } from "./account";
|
||||
import { LendingMarket, LendingObligation, TokenAccount } from "../models";
|
||||
import { approve, LendingMarket, LendingObligation, TokenAccount } from "../models";
|
||||
import { cache, ParsedAccount } from "../contexts/accounts";
|
||||
|
||||
export const liquidate = async (
|
||||
|
@ -58,15 +58,13 @@ export const liquidate = async (
|
|||
);
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
amountLamports
|
||||
)
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
amountLamports
|
||||
);
|
||||
|
||||
// get destination account
|
||||
|
|
|
@ -11,7 +11,7 @@ import { repayInstruction } from "./../models/lending/repay";
|
|||
import { AccountLayout, Token } from "@solana/spl-token";
|
||||
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../constants/ids";
|
||||
import { findOrCreateAccountByMint } from "./account";
|
||||
import { LendingObligation, TokenAccount } from "../models";
|
||||
import { approve, LendingObligation, TokenAccount } from "../models";
|
||||
import { ParsedAccount } from "../contexts/accounts";
|
||||
|
||||
export const repay = async (
|
||||
|
@ -53,15 +53,13 @@ export const repay = async (
|
|||
const fromAccount = from.pubkey;
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
amountLamports
|
||||
)
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
amountLamports
|
||||
);
|
||||
|
||||
// get destination account
|
||||
|
@ -76,15 +74,13 @@ export const repay = async (
|
|||
);
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
obligationToken.pubkey,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
obligationToken.info.amount.toNumber()
|
||||
)
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
obligationToken.pubkey,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
obligationToken.info.amount.toNumber()
|
||||
);
|
||||
|
||||
// TODO: add obligation
|
||||
|
|
|
@ -10,7 +10,7 @@ import { LendingReserve, withdrawInstruction } from "./../models/lending";
|
|||
import { AccountLayout, Token } from "@solana/spl-token";
|
||||
import { LENDING_PROGRAM_ID, TOKEN_PROGRAM_ID } from "../constants/ids";
|
||||
import { findOrCreateAccountByMint } from "./account";
|
||||
import { TokenAccount } from "../models";
|
||||
import { approve, TokenAccount } from "../models";
|
||||
|
||||
export const withdraw = async (
|
||||
from: TokenAccount, // CollateralAccount
|
||||
|
@ -43,15 +43,13 @@ export const withdraw = async (
|
|||
const fromAccount = from.pubkey;
|
||||
|
||||
// create approval for transfer transactions
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
TOKEN_PROGRAM_ID,
|
||||
approve(
|
||||
instructions,
|
||||
cleanupInstructions,
|
||||
fromAccount,
|
||||
authority,
|
||||
wallet.publicKey,
|
||||
[],
|
||||
amountLamports
|
||||
)
|
||||
);
|
||||
|
||||
// get destination account
|
||||
|
|
|
@ -1,9 +1,39 @@
|
|||
import { AccountInfo, PublicKey } from "@solana/web3.js";
|
||||
import { AccountInfo, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
||||
|
||||
import { AccountInfo as TokenAccountInfo } from "@solana/spl-token";
|
||||
import { AccountInfo as TokenAccountInfo, Token } from "@solana/spl-token";
|
||||
import { TOKEN_PROGRAM_ID } from "../constants";
|
||||
|
||||
export interface TokenAccount {
|
||||
pubkey: PublicKey;
|
||||
account: AccountInfo<Buffer>;
|
||||
info: TokenAccountInfo;
|
||||
}
|
||||
|
||||
export function approve(
|
||||
instructions: TransactionInstruction[],
|
||||
cleanupInstructions: TransactionInstruction[],
|
||||
account: PublicKey,
|
||||
delegate: PublicKey,
|
||||
owner: PublicKey,
|
||||
amount: number,
|
||||
): void {
|
||||
const tokenProgram = TOKEN_PROGRAM_ID;
|
||||
instructions.push(
|
||||
Token.createApproveInstruction(
|
||||
tokenProgram,
|
||||
account,
|
||||
delegate,
|
||||
owner,
|
||||
[],
|
||||
amount
|
||||
)
|
||||
);
|
||||
|
||||
cleanupInstructions.push(
|
||||
Token.createRevokeInstruction(
|
||||
tokenProgram,
|
||||
account,
|
||||
owner,
|
||||
[]),
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue