From 39a5dc692c00ebe1013f840f8014d3f75bfc7ff8 Mon Sep 17 00:00:00 2001 From: Conner Gallagher Date: Wed, 8 Mar 2023 10:57:15 -0700 Subject: [PATCH] solana.js: fix lease withdraw timing --- javascript/solana.js/package.json | 8 ++- .../solana.js/src/accounts/leaseAccount.ts | 2 +- javascript/solana.js/src/index.ts | 1 - javascript/solana.js/src/mint.ts | 51 ++++++++++--------- programs/anchor-vrf-parser/package-lock.json | 8 +-- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/javascript/solana.js/package.json b/javascript/solana.js/package.json index 7b3e979..2fa840d 100644 --- a/javascript/solana.js/package.json +++ b/javascript/solana.js/package.json @@ -1,6 +1,6 @@ { "name": "@switchboard-xyz/solana.js", - "version": "2.0.134", + "version": "2.0.135-beta.0", "author": "", "license": "MIT", "description": "API wrapper for integrating with the Switchboard V2 program on Solana", @@ -15,7 +15,11 @@ "import": "./lib/esm/index.js", "require": "./lib/cjs/index.js" }, - "./package.json": "./package.json" + "./package.json": "./package.json", + "./test": { + "import": "./lib/esm/test/index.js", + "require": "./lib/cjs/test/index.js" + } }, "main": "lib/cjs/index.js", "module": "lib/esm/index.js", diff --git a/javascript/solana.js/src/accounts/leaseAccount.ts b/javascript/solana.js/src/accounts/leaseAccount.ts index 7d5961b..803efce 100644 --- a/javascript/solana.js/src/accounts/leaseAccount.ts +++ b/javascript/solana.js/src/accounts/leaseAccount.ts @@ -502,7 +502,7 @@ export class LeaseAccount extends Account { oracleRequestBatchSize: number, queueReward: BN ): BN { - return queueReward.mul(new BN(oracleRequestBatchSize + 1)); + return queueReward.mul(new BN(oracleRequestBatchSize + 1)).mul(new BN(2)); } /** diff --git a/javascript/solana.js/src/index.ts b/javascript/solana.js/src/index.ts index 45c9fdf..24b664a 100644 --- a/javascript/solana.js/src/index.ts +++ b/javascript/solana.js/src/index.ts @@ -9,6 +9,5 @@ export * from './SwitchboardError'; export * from './SwitchboardEvents'; export * from './SwitchboardNetwork'; export * from './SwitchboardProgram'; -export * from './test'; export * from './TransactionObject'; export * from './utils'; diff --git a/javascript/solana.js/src/mint.ts b/javascript/solana.js/src/mint.ts index 95dd42c..81e3706 100644 --- a/javascript/solana.js/src/mint.ts +++ b/javascript/solana.js/src/mint.ts @@ -352,29 +352,34 @@ export class NativeMint extends Mint { owner, Mint.native ), - spl.createAssociatedTokenAccountInstruction( - payer, - ephemeralWallet, - ephemeralAccount.publicKey, - spl.NATIVE_MINT - ), - SystemProgram.transfer({ - fromPubkey: owner, - toPubkey: ephemeralWallet, - lamports: wrapAmountLamports, - }), - spl.createSyncNativeInstruction(ephemeralWallet), - spl.createTransferInstruction( - ephemeralWallet, - associatedAddress, - ephemeralAccount.publicKey, - wrapAmountLamports - ), - spl.createCloseAccountInstruction( - ephemeralWallet, - owner, - ephemeralAccount.publicKey - ), + // only wrap funds if needed + ...(amount > 0 + ? [ + spl.createAssociatedTokenAccountInstruction( + payer, + ephemeralWallet, + ephemeralAccount.publicKey, + spl.NATIVE_MINT + ), + SystemProgram.transfer({ + fromPubkey: owner, + toPubkey: ephemeralWallet, + lamports: wrapAmountLamports, + }), + spl.createSyncNativeInstruction(ephemeralWallet), + spl.createTransferInstruction( + ephemeralWallet, + associatedAddress, + ephemeralAccount.publicKey, + wrapAmountLamports + ), + spl.createCloseAccountInstruction( + ephemeralWallet, + owner, + ephemeralAccount.publicKey + ), + ] + : []), ], user ? [user, ephemeralAccount] : [ephemeralAccount] ), diff --git a/programs/anchor-vrf-parser/package-lock.json b/programs/anchor-vrf-parser/package-lock.json index f731d72..4e72374 100644 --- a/programs/anchor-vrf-parser/package-lock.json +++ b/programs/anchor-vrf-parser/package-lock.json @@ -42,14 +42,15 @@ }, "../../javascript/solana.js": { "name": "@switchboard-xyz/solana.js", - "version": "2.0.119", + "version": "2.0.133", "license": "MIT", "dependencies": { "@coral-xyz/anchor": "^0.26.0", "@coral-xyz/borsh": "^0.26.0", "@solana/spl-token": "^0.3.6", "@solana/web3.js": "^1.73.0", - "@switchboard-xyz/common": "^2.1.29", + "@switchboard-xyz/common": "^2.1.33", + "@switchboard-xyz/oracle": "^2.1.11", "dotenv": "^16.0.3", "lodash": "^4.17.21" }, @@ -4920,7 +4921,8 @@ "@coral-xyz/borsh": "^0.26.0", "@solana/spl-token": "^0.3.6", "@solana/web3.js": "^1.73.0", - "@switchboard-xyz/common": "^2.1.29", + "@switchboard-xyz/common": "^2.1.33", + "@switchboard-xyz/oracle": "^2.1.11", "@types/chai": "^4.3.4", "@types/expect": "^24.3.0", "@types/lodash": "^4.14.191",