solana.js: added payer verification
This commit is contained in:
parent
03cdd248d2
commit
e6b5499758
|
@ -90,7 +90,7 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
payer: PublicKey,
|
||||
params: {
|
||||
loadAmount?: number;
|
||||
funder?: PublicKey;
|
||||
funderTokenAccount?: PublicKey;
|
||||
funderAuthority?: Keypair;
|
||||
queuePubkey: PublicKey;
|
||||
aggregatorPubkey: PublicKey;
|
||||
|
@ -107,11 +107,14 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
const funderAuthority = params.funderAuthority
|
||||
? params.funderAuthority.publicKey
|
||||
: payer;
|
||||
const funder = params.funder
|
||||
? params.funder
|
||||
const funderTokenAccount = params.funderTokenAccount
|
||||
? params.funderTokenAccount
|
||||
: program.mint.getAssociatedAddress(funderAuthority);
|
||||
const funderBalance = (await program.mint.getBalance(funderAuthority)) ?? 0;
|
||||
if (loadAmount && funderBalance < loadAmount) {
|
||||
|
||||
const funderTokenBalance =
|
||||
(await program.mint.getBalance(funderAuthority)) ?? 0;
|
||||
|
||||
if (loadAmount && funderTokenBalance < loadAmount) {
|
||||
const wrapIxns = await program.mint.wrapInstruction(
|
||||
payer,
|
||||
{ amount: loadAmount },
|
||||
|
@ -166,7 +169,7 @@ export class LeaseAccount extends Account<types.LeaseAccountData> {
|
|||
payer: payer,
|
||||
systemProgram: SystemProgram.programId,
|
||||
tokenProgram: spl.TOKEN_PROGRAM_ID,
|
||||
funder: funder,
|
||||
funder: funderTokenAccount,
|
||||
owner: funderAuthority,
|
||||
escrow: escrow,
|
||||
programState: program.programState.publicKey,
|
||||
|
|
|
@ -336,6 +336,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
const userTokenAccountInfo = await this.program.connection.getAccountInfo(
|
||||
userTokenAddress
|
||||
);
|
||||
|
||||
if (userTokenAccountInfo === null) {
|
||||
const [createTokenAccount] =
|
||||
this.program.mint.createAssocatedUserInstruction(payer);
|
||||
|
@ -387,7 +388,7 @@ export class QueueAccount extends Account<types.OracleQueueAccountData> {
|
|||
payer,
|
||||
{
|
||||
loadAmount: params.fundAmount,
|
||||
funder: params.funderTokenAccount,
|
||||
funderTokenAccount: params.funderTokenAccount,
|
||||
funderAuthority: params.funderAuthority,
|
||||
aggregatorPubkey: aggregatorAccount.publicKey,
|
||||
queuePubkey: this.publicKey,
|
||||
|
|
|
@ -220,18 +220,18 @@ export class Mint {
|
|||
// );
|
||||
// }
|
||||
|
||||
const balance = userAccount
|
||||
const tokenBalance = userAccount
|
||||
? new Big(this.fromTokenAmount(userAccount.amount))
|
||||
: new Big(0);
|
||||
|
||||
let wrapAmount: Big;
|
||||
if ('fundUpTo' in params) {
|
||||
if (balance.gte(params.fundUpTo)) {
|
||||
if (tokenBalance.gte(params.fundUpTo)) {
|
||||
return new TransactionObject(payer, [], []);
|
||||
}
|
||||
wrapAmount = params.fundUpTo.sub(balance);
|
||||
wrapAmount = params.fundUpTo.sub(tokenBalance);
|
||||
} else if ('amount' in params) {
|
||||
wrapAmount = balance.add(params.amount);
|
||||
wrapAmount = tokenBalance.add(params.amount);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Must specify fundUpTo or amount to perform this actions`
|
||||
|
|
|
@ -177,6 +177,12 @@ export class SwitchboardProgram {
|
|||
);
|
||||
}
|
||||
|
||||
public verifyPayer(): void {
|
||||
if (this.isReadOnly) {
|
||||
throw new errors.SwitchboardProgramReadOnlyError();
|
||||
}
|
||||
}
|
||||
|
||||
public get account(): anchor.AccountNamespace {
|
||||
return this._program.account;
|
||||
}
|
||||
|
|
|
@ -104,6 +104,11 @@ export class TransactionObject implements ITransactionObject {
|
|||
ixns: Array<TransactionInstruction>,
|
||||
signers: Array<Keypair>
|
||||
) {
|
||||
// verify payer is not default pubkey
|
||||
if (payer.equals(PublicKey.default)) {
|
||||
throw new errors.SwitchboardProgramReadOnlyError();
|
||||
}
|
||||
|
||||
// verify num ixns
|
||||
if (ixns.length > 10) {
|
||||
throw new errors.TransactionInstructionOverflowError(ixns.length);
|
||||
|
|
Loading…
Reference in New Issue