mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-28 00:28:04 +03:00
add useExchageBalance function, add balance and allowance validation
This commit is contained in:
@@ -58,7 +58,7 @@ async function getExchangeBalanceERC20(
|
||||
exchangeAddress = await addressLikeToString(exchangeAddress);
|
||||
tokenAddress = await addressLikeToString(tokenAddress);
|
||||
|
||||
const exchange = <Exchange>Exchange__factory.connect(exchangeAddress, provider)
|
||||
const exchange = <Exchange>Exchange__factory.connect(exchangeAddress, provider);
|
||||
const exchangeBalance = await exchange.getBalance(tokenAddress, walletAddress);
|
||||
|
||||
if (convertToNativeDecimals) {
|
||||
@@ -79,7 +79,7 @@ async function getExchangeBalanceNative(
|
||||
) {
|
||||
walletAddress = await addressLikeToString(walletAddress);
|
||||
exchangeAddress = await addressLikeToString(exchangeAddress);
|
||||
const exchange = <Exchange>Exchange__factory.connect(exchangeAddress, provider)
|
||||
const exchange = <Exchange>Exchange__factory.connect(exchangeAddress, provider);
|
||||
const exchangeBalance = await exchange.getBalance(ZeroAddress, walletAddress);
|
||||
|
||||
if (convertToNativeDecimals) {
|
||||
@@ -107,6 +107,25 @@ export async function getExchangeBalance(
|
||||
}
|
||||
}
|
||||
|
||||
export async function getExchangeAllowance(
|
||||
tokenAddress: AddressLike,
|
||||
walletAddress: AddressLike,
|
||||
exchangeAddress: AddressLike,
|
||||
provider: ethers.Provider
|
||||
) {
|
||||
if (typeof tokenAddress === "string" && tokenAddress === ZeroAddress) {
|
||||
return 0n;
|
||||
} else {
|
||||
walletAddress = await addressLikeToString(walletAddress);
|
||||
tokenAddress = await addressLikeToString(tokenAddress);
|
||||
|
||||
const tokenContract = ERC20__factory.connect(tokenAddress, provider);
|
||||
let allowance = await tokenContract.allowance(walletAddress, exchangeAddress);
|
||||
|
||||
return allowance;
|
||||
}
|
||||
}
|
||||
|
||||
async function getWalletBalanceERC20(
|
||||
tokenAddress: AddressLike,
|
||||
walletAddress: AddressLike,
|
||||
@@ -172,5 +191,9 @@ export async function getTotalBalance(
|
||||
provider,
|
||||
convertToNativeDecimals
|
||||
);
|
||||
return walletBalance + exchangeBalance;
|
||||
return {
|
||||
walletBalance,
|
||||
exchangeBalance,
|
||||
totalBalance: walletBalance + exchangeBalance
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user