diff --git a/.env b/.env new file mode 100644 index 0000000..4d6b3ef --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +REACT_APP_USDT_REFERRAL_FEES_ADDRESS='' +REACT_APP_USDC_REFERRAL_FEES_ADDRESS='' diff --git a/package.json b/package.json index 73555a5..3fd502d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "@ant-design/icons": "^4.2.1", "@craco/craco": "^5.6.4", - "@project-serum/serum": "^0.12.17", + "@project-serum/serum": "^0.12.19", "@project-serum/sol-wallet-adapter": "^0.1.0", "@solana/web3.js": "^0.71.10", "@testing-library/jest-dom": "^4.2.4", diff --git a/src/utils/connection.js b/src/utils/connection.js index 0f2bb0b..fb2421f 100644 --- a/src/utils/connection.js +++ b/src/utils/connection.js @@ -87,7 +87,6 @@ export function useAccountInfo(publicKey) { cacheKey, { refreshInterval: 60_000 }, ); - let id = publicKey?.toBase58(); useEffect(() => { if (!publicKey) { return; diff --git a/src/utils/markets.js b/src/utils/markets.js index 07834cd..92e08ff 100644 --- a/src/utils/markets.js +++ b/src/utils/markets.js @@ -595,7 +595,12 @@ export function useBalances() { openOrders && openOrders.baseTokenTotal && openOrders.baseTokenFree; const quoteExists = openOrders && openOrders.quoteTokenTotal && openOrders.quoteTokenFree; - if (baseCurrency === 'UNKNOWN' || quoteCurrency === 'UNKNOWN') { + if ( + baseCurrency === 'UNKNOWN' || + quoteCurrency === 'UNKNOWN' || + !baseCurrency || + !quoteCurrency + ) { return []; } return [ diff --git a/src/utils/send.js b/src/utils/send.js index 10d632b..2c427f7 100644 --- a/src/utils/send.js +++ b/src/utils/send.js @@ -1,7 +1,12 @@ import { notify } from './notifications'; import { getDecimalCount, sleep } from './utils'; -import { Account, SystemProgram, Transaction } from '@solana/web3.js'; -import { TokenInstructions } from '@project-serum/serum'; +import { + Account, + SystemProgram, + Transaction, + PublicKey, +} from '@solana/web3.js'; +import { TOKEN_MINTS, TokenInstructions } from '@project-serum/serum'; export async function createTokenAccountTransaction({ connection, @@ -75,7 +80,28 @@ export async function settleFunds({ createAccountTransaction = result?.transaction; createAccountSigner = result?.signer; } - + let referrerQuoteWallet = null; + if (market.supportsReferralFees) { + if ( + process.env.REACT_APP_USDT_REFERRAL_FEES_ADDRESS && + market.quoteMintAddress.equals( + TOKEN_MINTS.find(({ name }) => name === 'USDT').address, + ) + ) { + referrerQuoteWallet = new PublicKey( + process.env.REACT_APP_USDT_REFERRAL_FEES_ADDRESS, + ); + } else if ( + process.env.REACT_APP_USDC_REFERRAL_FEES_ADDRESS && + market.quoteMintAddress.equals( + TOKEN_MINTS.find(({ name }) => name === 'USDC').address, + ) + ) { + referrerQuoteWallet = new PublicKey( + process.env.REACT_APP_USDC_REFERRAL_FEES_ADDRESS, + ); + } + } const { transaction: settleFundsTransaction, signers: settleFundsSigners, @@ -84,6 +110,7 @@ export async function settleFunds({ openOrders, baseCurrencyAccountPubkey, quoteCurrencyAccountPubkey, + referrerQuoteWallet, ); let transaction = mergeTransactions([ diff --git a/yarn.lock b/yarn.lock index e5e09da..a84d9f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1467,10 +1467,10 @@ resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw== -"@project-serum/serum@^0.12.17": - version "0.12.17" - resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.12.17.tgz#f22dbfd4ef659a722f7720ef87a8f4d4bc929a9f" - integrity sha512-4Tkzg+Hx3F6YvKGDyR5bQ3PlMLf2fLwvWjRhjIeJWAUqyX7ZiGqvZz+NJ2VTFESo9wRoMcBPZccd52E/pkSUXQ== +"@project-serum/serum@^0.12.19": + version "0.12.19" + resolved "https://registry.yarnpkg.com/@project-serum/serum/-/serum-0.12.19.tgz#a86ed3590bdbd51380f6062810c40734c1bfe548" + integrity sha512-QWy6mw2Swm1eqs1rLWhjqHYIg0mAsjnye8kcW5Ko1QeDcSfkj9asgxPK7ft7IS+npSbbSBAO4IZdm189FBOV6Q== dependencies: "@solana/web3.js" "^0.71.10" bn.js "^5.1.2"