diff --git a/javascript/solana.js/src/accounts/oracleAccount.ts b/javascript/solana.js/src/accounts/oracleAccount.ts index 1383166..c3c9b08 100644 --- a/javascript/solana.js/src/accounts/oracleAccount.ts +++ b/javascript/solana.js/src/accounts/oracleAccount.ts @@ -176,7 +176,9 @@ export class OracleAccount extends Account { queueAccount: QueueAccount; } & OracleInitParams & OracleStakeParams - ): Promise<[OracleAccount, TransactionObject]> { + ): Promise<[OracleAccount, Array]> { + const txns: Array = []; + const tokenWallet = params.stakingWalletKeypair ?? Keypair.generate(); const authority = params.authority?.publicKey ?? payer; @@ -238,6 +240,8 @@ export class OracleAccount extends Account { params.authority ? [params.authority, tokenWallet] : [tokenWallet] ); + txns.push(oracleInit); + if (params.stakeAmount && params.stakeAmount > 0) { const depositTxn = await oracleAccount.stakeInstructions(payer, { stakeAmount: params.stakeAmount, @@ -245,10 +249,10 @@ export class OracleAccount extends Account { funderTokenAccount: params.funderTokenAccount, tokenAccount: tokenWallet.publicKey, }); - oracleInit.combine(depositTxn); + txns.push(depositTxn); } - return [oracleAccount, oracleInit]; + return [oracleAccount, txns]; } public static async create( @@ -257,16 +261,16 @@ export class OracleAccount extends Account { queueAccount: QueueAccount; } & OracleInitParams & OracleStakeParams - ): Promise<[OracleAccount, TransactionSignature]> { - const [oracleAccount, txnObject] = await OracleAccount.createInstructions( + ): Promise<[OracleAccount, Array]> { + const [oracleAccount, txns] = await OracleAccount.createInstructions( program, program.walletPubkey, params ); - const txnSignature = await program.signAndSend(txnObject); + const signatures = await program.signAndSendAll(txns); - return [oracleAccount, txnSignature]; + return [oracleAccount, signatures]; } async stakeInstructions( diff --git a/javascript/solana.js/src/accounts/queueAccount.ts b/javascript/solana.js/src/accounts/queueAccount.ts index 37ea81a..85c5b14 100644 --- a/javascript/solana.js/src/accounts/queueAccount.ts +++ b/javascript/solana.js/src/accounts/queueAccount.ts @@ -374,7 +374,7 @@ export class QueueAccount extends Account { return [ oracleAccount, TransactionObject.pack([ - createOracleTxnObject, + ...createOracleTxnObject, createPermissionTxnObject, ]), ]; diff --git a/javascript/solana.js/src/mint.ts b/javascript/solana.js/src/mint.ts index 5633d69..f80423f 100644 --- a/javascript/solana.js/src/mint.ts +++ b/javascript/solana.js/src/mint.ts @@ -411,9 +411,7 @@ export class NativeMint extends Mint { } wrapAmount = params.fundUpTo.sub(userTokenBalance); } else if ('amount' in params) { - wrapAmount = new Big(params.amount).mul( - new Big(10).pow(this.mint.decimals) - ); + wrapAmount = new Big(params.amount); } else { throw new Error( `Must specify fundUpTo or amount to perform this actions` diff --git a/javascript/solana.js/test/mint.spec.ts b/javascript/solana.js/test/mint.spec.ts index 4f091ae..398f3af 100644 --- a/javascript/solana.js/test/mint.spec.ts +++ b/javascript/solana.js/test/mint.spec.ts @@ -4,6 +4,7 @@ import assert from 'assert'; import * as anchor from '@project-serum/anchor'; import { setupTest, TestContext } from './utilts'; import { Keypair, PublicKey } from '@solana/web3.js'; +import Big from 'big.js'; describe('Mint Tests', () => { let ctx: TestContext; @@ -22,66 +23,77 @@ describe('Mint Tests', () => { ); await ctx.program.connection.confirmTransaction(airdropTxn); - const [tokenAddress] = await ctx.program.mint.createAssocatedUser( + [userTokenAddress] = await ctx.program.mint.createAssocatedUser( ctx.payer.publicKey, user.publicKey ); - userTokenAddress = tokenAddress; const userTokenBalance = (await ctx.program.mint.getAssociatedBalance(user.publicKey)) ?? 0; - if (userTokenBalance !== 0) { - throw new Error( - `Incorrect user token balance, expected 0, received ${userTokenBalance}` - ); - } + assert( + userTokenBalance === 0, + `Incorrect user token balance, expected 0, received ${userTokenBalance}` + ); }); it('Wraps SOL', async () => { - if (!userTokenAddress) { - throw new Error(`User token address does not exist`); - } + assert(userTokenAddress, `User token address does not exist`); - await ctx.program.mint.wrap(ctx.payer.publicKey, { amount: 0.25 }, user); + const WRAP_AMOUNT = 0.25; + + await ctx.program.mint.wrap( + ctx.payer.publicKey, + { amount: WRAP_AMOUNT }, + user + ); const userTokenBalance = (await ctx.program.mint.getAssociatedBalance(user.publicKey)) ?? 0; - if (userTokenBalance !== 0.25) { - throw new Error( - `Incorrect user token balance, expected 0.25, received ${userTokenBalance}` - ); - } + + assert( + userTokenBalance === WRAP_AMOUNT, + `Incorrect user token balance, expected ${WRAP_AMOUNT} wSOL, received ${userTokenBalance}` + ); }); it('Unwraps SOL', async () => { - if (!userTokenAddress) { - throw new Error(`User token address does not exist`); - } + assert(userTokenAddress, `User token address does not exist`); - const initialUserTokenBalance = + const UNWRAP_AMOUNT = 0.1; + + let initialUserTokenBalance = (await ctx.program.mint.getAssociatedBalance(user.publicKey)) ?? 0; - const expectedFinalBalance = initialUserTokenBalance - 0.1; - if (expectedFinalBalance < 0) { - throw new Error(`Final user token address would be negative`); + // if previous test failed, wrap some funds + if (initialUserTokenBalance <= 0) { + await ctx.program.mint.wrap( + ctx.payer.publicKey, + { fundUpTo: new Big(0.25) }, + user + ); + initialUserTokenBalance = + (await ctx.program.mint.getAssociatedBalance(user.publicKey)) ?? 0; } - await ctx.program.mint.unwrap(ctx.payer.publicKey, 0.1, user); + const expectedFinalBalance = initialUserTokenBalance - UNWRAP_AMOUNT; + assert( + expectedFinalBalance >= 0, + `Final user token address would be negative` + ); + + await ctx.program.mint.unwrap(ctx.payer.publicKey, UNWRAP_AMOUNT, user); const userTokenBalance = await ctx.program.mint.getAssociatedBalance( user.publicKey ); - if (userTokenBalance !== expectedFinalBalance) { - throw new Error( - `Incorrect user token balance, expected ${expectedFinalBalance}, received ${userTokenBalance}` - ); - } + assert( + userTokenBalance === expectedFinalBalance, + `Incorrect user token balance, expected ${expectedFinalBalance}, received ${userTokenBalance}` + ); }); it('Closes associated token account', async () => { - if (!userTokenAddress) { - throw new Error(`User token address does not exist`); - } + assert(userTokenAddress, `User token address does not exist`); await ctx.program.mint.getAssociatedBalance(user.publicKey); @@ -90,8 +102,9 @@ describe('Mint Tests', () => { const userTokenAccount = await ctx.program.connection.getAccountInfo( userTokenAddress ); - if (userTokenAccount !== null) { - throw new Error(`Failed to close associated token account`); - } + assert( + userTokenAccount === null, + `Failed to close associated token account` + ); }); });