aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'packages/order-utils/src/store')
-rw-r--r--packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts43
-rw-r--r--packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts45
2 files changed, 88 insertions, 0 deletions
diff --git a/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts b/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
index 5a2c1d7ff..8a65178b0 100644
--- a/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
+++ b/packages/order-utils/src/store/balance_and_proxy_allowance_lazy_store.ts
@@ -21,11 +21,21 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
[userAddress: string]: BigNumber;
};
};
+ /**
+ * Instantiates a BalanceAndProxyAllowanceLazyStore
+ * @param balanceAndProxyAllowanceFetcher Class the implements the AbstractBalanceAndProxyAllowanceFetcher
+ * @return Instance of BalanceAndProxyAllowanceLazyStore
+ */
constructor(balanceAndProxyAllowanceFetcher: AbstractBalanceAndProxyAllowanceFetcher) {
this._balanceAndProxyAllowanceFetcher = balanceAndProxyAllowanceFetcher;
this._balance = {};
this._proxyAllowance = {};
}
+ /**
+ * Get a users balance of an asset
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public async getBalanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
if (_.isUndefined(this._balance[assetData]) || _.isUndefined(this._balance[assetData][userAddress])) {
const balance = await this._balanceAndProxyAllowanceFetcher.getBalanceAsync(assetData, userAddress);
@@ -34,12 +44,22 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
const cachedBalance = this._balance[assetData][userAddress];
return cachedBalance;
}
+ /**
+ * Set the balance of an asset for a user
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public setBalance(assetData: string, userAddress: string, balance: BigNumber): void {
if (_.isUndefined(this._balance[assetData])) {
this._balance[assetData] = {};
}
this._balance[assetData][userAddress] = balance;
}
+ /**
+ * Clear the balance of an asset for a user
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public deleteBalance(assetData: string, userAddress: string): void {
if (!_.isUndefined(this._balance[assetData])) {
delete this._balance[assetData][userAddress];
@@ -48,6 +68,11 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
}
}
}
+ /**
+ * Get the 0x asset proxy allowance
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
if (
_.isUndefined(this._proxyAllowance[assetData]) ||
@@ -62,12 +87,22 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
const cachedProxyAllowance = this._proxyAllowance[assetData][userAddress];
return cachedProxyAllowance;
}
+ /**
+ * Set the 0x asset proxy allowance
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public setProxyAllowance(assetData: string, userAddress: string, proxyAllowance: BigNumber): void {
if (_.isUndefined(this._proxyAllowance[assetData])) {
this._proxyAllowance[assetData] = {};
}
this._proxyAllowance[assetData][userAddress] = proxyAllowance;
}
+ /**
+ * Clear the 0x asset proxy allowance
+ * @param assetData AssetData of interest
+ * @param userAddress Ethereum address of interest
+ */
public deleteProxyAllowance(assetData: string, userAddress: string): void {
if (!_.isUndefined(this._proxyAllowance[assetData])) {
delete this._proxyAllowance[assetData][userAddress];
@@ -76,6 +111,11 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
}
}
}
+ /**
+ * Clear all ERC721 0x proxy allowances a user has on all items of a specific ERC721 contract
+ * @param tokenAddress ERc721 token address
+ * @param userAddress Owner Ethereum address
+ */
public deleteAllERC721ProxyAllowance(tokenAddress: string, userAddress: string): void {
for (const assetData in this._proxyAllowance) {
if (this._proxyAllowance.hasOwnProperty(assetData)) {
@@ -90,6 +130,9 @@ export class BalanceAndProxyAllowanceLazyStore implements AbstractBalanceAndProx
}
}
}
+ /**
+ * Delete all balances & allowances
+ */
public deleteAll(): void {
this._balance = {};
this._proxyAllowance = {};
diff --git a/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts
index 336c6d0ba..6155c2064 100644
--- a/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts
+++ b/packages/order-utils/src/store/order_filled_cancelled_lazy_store.ts
@@ -15,11 +15,21 @@ export class OrderFilledCancelledLazyStore implements AbstractOrderFilledCancell
private _isCancelled: {
[orderHash: string]: boolean;
};
+ /**
+ * Instantiate a OrderFilledCancelledLazyStore
+ * @param orderFilledCancelledFetcher Class instance that implements the AbstractOrderFilledCancelledFetcher
+ * @returns An instance of OrderFilledCancelledLazyStore
+ */
constructor(orderFilledCancelledFetcher: AbstractOrderFilledCancelledFetcher) {
this._orderFilledCancelledFetcher = orderFilledCancelledFetcher;
this._filledTakerAmount = {};
this._isCancelled = {};
}
+ /**
+ * Get the filledTakerAssetAmount of an order
+ * @param orderHash OrderHash from order of interest
+ * @return filledTakerAssetAmount
+ */
public async getFilledTakerAmountAsync(orderHash: string): Promise<BigNumber> {
if (_.isUndefined(this._filledTakerAmount[orderHash])) {
const filledTakerAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
@@ -28,12 +38,26 @@ export class OrderFilledCancelledLazyStore implements AbstractOrderFilledCancell
const cachedFilledTakerAmount = this._filledTakerAmount[orderHash];
return cachedFilledTakerAmount;
}
+ /**
+ * Set the filledTakerAssetAmount of an order
+ * @param orderHash OrderHash from order of interest
+ * @param filledTakerAmount Desired filledTakerAssetAmount
+ */
public setFilledTakerAmount(orderHash: string, filledTakerAmount: BigNumber): void {
this._filledTakerAmount[orderHash] = filledTakerAmount;
}
+ /**
+ * Clear the filledTakerAssetAmount of an order
+ * @param orderHash OrderHash from order of interest
+ */
public deleteFilledTakerAmount(orderHash: string): void {
delete this._filledTakerAmount[orderHash];
}
+ /**
+ * Check if an order has been cancelled
+ * @param orderHash OrderHash from order of interest
+ * @return Whether the order has been cancelled
+ */
public async getIsCancelledAsync(orderHash: string): Promise<boolean> {
if (_.isUndefined(this._isCancelled[orderHash])) {
const isCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(orderHash);
@@ -42,22 +66,43 @@ export class OrderFilledCancelledLazyStore implements AbstractOrderFilledCancell
const cachedIsCancelled = this._isCancelled[orderHash]; // tslint:disable-line:boolean-naming
return cachedIsCancelled;
}
+ /**
+ * Set whether an order has been cancelled or not
+ * @param orderHash OrderHash from order of interest
+ * @param isCancelled Whether this order should be cancelled or not
+ */
public setIsCancelled(orderHash: string, isCancelled: boolean): void {
this._isCancelled[orderHash] = isCancelled;
}
+ /**
+ * Clear whether the order has been cancelled if already set
+ * @param orderHash OrderHash from order of interest
+ */
public deleteIsCancelled(orderHash: string): void {
delete this._isCancelled[orderHash];
}
+ /**
+ * Clear all filled/cancelled state
+ */
public deleteAll(): void {
this.deleteAllFilled();
this.deleteAllIsCancelled();
}
+ /**
+ * Clear all cancelled state
+ */
public deleteAllIsCancelled(): void {
this._isCancelled = {};
}
+ /**
+ * Clear all filled state
+ */
public deleteAllFilled(): void {
this._filledTakerAmount = {};
}
+ /**
+ * Get the ZRX assetData
+ */
public getZRXAssetData(): string {
const zrxAssetData = this._orderFilledCancelledFetcher.getZRXAssetData();
return zrxAssetData;