Modify batch allowances to take an array of spenders
This commit is contained in:
@@ -162,7 +162,7 @@ contract LibAssetData is
|
|||||||
|
|
||||||
/// @dev Calls getAllowance() for each element of assetData.
|
/// @dev Calls getAllowance() for each element of assetData.
|
||||||
/// @param owner Owner of the tokens specified by assetData.
|
/// @param owner Owner of the tokens specified by assetData.
|
||||||
/// @param spender Address whose authority to spend is in question.
|
/// @param spenders Array of addresses whose authority to spend is in question for each corresponding assetData.
|
||||||
/// @param assetData Description of tokens, per the AssetProxy contract
|
/// @param assetData Description of tokens, per the AssetProxy contract
|
||||||
/// specification.
|
/// specification.
|
||||||
/// @return An array of token allowances from getAllowance(), with each
|
/// @return An array of token allowances from getAllowance(), with each
|
||||||
@@ -170,7 +170,7 @@ contract LibAssetData is
|
|||||||
/// input.
|
/// input.
|
||||||
function getBatchAllowances(
|
function getBatchAllowances(
|
||||||
address owner,
|
address owner,
|
||||||
address spender,
|
address[] memory spenders,
|
||||||
bytes[] memory assetData
|
bytes[] memory assetData
|
||||||
)
|
)
|
||||||
public
|
public
|
||||||
@@ -180,7 +180,7 @@ contract LibAssetData is
|
|||||||
uint256 length = assetData.length;
|
uint256 length = assetData.length;
|
||||||
allowances = new uint256[](length);
|
allowances = new uint256[](length);
|
||||||
for (uint256 i = 0; i != length; i++) {
|
for (uint256 i = 0; i != length; i++) {
|
||||||
allowances[i] = getAllowance(owner, spender, assetData[i]);
|
allowances[i] = getAllowance(owner, spenders[i], assetData[i]);
|
||||||
}
|
}
|
||||||
return allowances;
|
return allowances;
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ contract LibAssetData is
|
|||||||
/// @dev Calls getBatchBalances() and getBatchAllowances() for each element
|
/// @dev Calls getBatchBalances() and getBatchAllowances() for each element
|
||||||
/// of assetData.
|
/// of assetData.
|
||||||
/// @param owner Owner of the tokens specified by assetData.
|
/// @param owner Owner of the tokens specified by assetData.
|
||||||
/// @param spender Address whose authority to spend is in question.
|
/// @param spenders Array of addresses whose authority to spend is in question for each corresponding assetData.
|
||||||
/// @param assetData Description of tokens, per the AssetProxy contract
|
/// @param assetData Description of tokens, per the AssetProxy contract
|
||||||
/// specification.
|
/// specification.
|
||||||
/// @return An array of token balances from getBalance(), and an array of
|
/// @return An array of token balances from getBalance(), and an array of
|
||||||
@@ -218,7 +218,7 @@ contract LibAssetData is
|
|||||||
/// corresponding to the same-indexed element in the assetData input.
|
/// corresponding to the same-indexed element in the assetData input.
|
||||||
function getBatchBalancesAndAllowances(
|
function getBatchBalancesAndAllowances(
|
||||||
address owner,
|
address owner,
|
||||||
address spender,
|
address[] memory spenders,
|
||||||
bytes[] memory assetData
|
bytes[] memory assetData
|
||||||
)
|
)
|
||||||
public
|
public
|
||||||
@@ -229,7 +229,7 @@ contract LibAssetData is
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
balances = getBatchBalances(owner, assetData);
|
balances = getBatchBalances(owner, assetData);
|
||||||
allowances = getBatchAllowances(owner, spender, assetData);
|
allowances = getBatchAllowances(owner, spenders, assetData);
|
||||||
return (balances, allowances);
|
return (balances, allowances);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +470,7 @@ contract LibAssetData is
|
|||||||
|
|
||||||
(bool success, bytes memory returnData) = tokenAddress.staticcall(ownerOfCalldata);
|
(bool success, bytes memory returnData) = tokenAddress.staticcall(ownerOfCalldata);
|
||||||
|
|
||||||
owner = success ? returnData.readAddress(12) : address(0);
|
owner = (success && returnData.length == 32) ? returnData.readAddress(12) : address(0);
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -383,10 +383,14 @@ describe('LibAssetData', () => {
|
|||||||
await setERC20AllowanceAsync();
|
await setERC20AllowanceAsync();
|
||||||
await setERC721AllowanceAsync();
|
await setERC721AllowanceAsync();
|
||||||
expect(
|
expect(
|
||||||
await libAssetData.getBatchAllowances.callAsync(tokenOwnerAddress, approvedSpenderAddress, [
|
await libAssetData.getBatchAllowances.callAsync(
|
||||||
await libAssetData.encodeERC20AssetData.callAsync(erc20TokenAddress),
|
tokenOwnerAddress,
|
||||||
await libAssetData.encodeERC721AssetData.callAsync(erc721TokenAddress, firstERC721TokenId),
|
[approvedSpenderAddress, approvedSpenderAddress],
|
||||||
]),
|
[
|
||||||
|
await libAssetData.encodeERC20AssetData.callAsync(erc20TokenAddress),
|
||||||
|
await libAssetData.encodeERC721AssetData.callAsync(erc721TokenAddress, firstERC721TokenId),
|
||||||
|
],
|
||||||
|
),
|
||||||
).to.deep.equal([new BigNumber(1), new BigNumber(1)]);
|
).to.deep.equal([new BigNumber(1), new BigNumber(1)]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -418,9 +422,11 @@ describe('LibAssetData', () => {
|
|||||||
it('should query balances and allowances together, from an asset data array', async () => {
|
it('should query balances and allowances together, from an asset data array', async () => {
|
||||||
await setERC20AllowanceAsync();
|
await setERC20AllowanceAsync();
|
||||||
expect(
|
expect(
|
||||||
await libAssetData.getBatchBalancesAndAllowances.callAsync(tokenOwnerAddress, approvedSpenderAddress, [
|
await libAssetData.getBatchBalancesAndAllowances.callAsync(
|
||||||
await libAssetData.encodeERC20AssetData.callAsync(erc20TokenAddress),
|
tokenOwnerAddress,
|
||||||
]),
|
[approvedSpenderAddress, approvedSpenderAddress],
|
||||||
|
[await libAssetData.encodeERC20AssetData.callAsync(erc20TokenAddress)],
|
||||||
|
),
|
||||||
).to.deep.equal([[new BigNumber(erc20TokenTotalSupply)], [new BigNumber(1)]]);
|
).to.deep.equal([[new BigNumber(erc20TokenTotalSupply)], [new BigNumber(1)]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user