diff --git a/contracts/Ojo.sol b/contracts/Ojo.sol index c424af5..97c1f23 100644 --- a/contracts/Ojo.sol +++ b/contracts/Ojo.sol @@ -18,6 +18,8 @@ contract Ojo is IOjo, AxelarExecutable, Upgradable { uint256 public resolveWindow; + uint16 public assetLimit; + mapping(bytes32 => OjoTypes.PriceData) public priceData; error AlreadyInitialized(); @@ -32,7 +34,7 @@ contract Ojo is IOjo, AxelarExecutable, Upgradable { bytes4 commandSelector, bytes calldata commandParams ) external payable { - require(assetNames.length <= 5, "Cannot relay more than 5 assets at a time"); + require(assetNames.length <= assetLimit, "Number of assets requested is over limit"); bytes memory payloadWithVersion = abi.encodePacked( bytes4(uint32(0)), // version number @@ -58,8 +60,8 @@ contract Ojo is IOjo, AxelarExecutable, Upgradable { string memory symbol, uint256 amount ) external payable { - require(assetNames.length <= 5, "Cannot relay more than 5 assets at a time"); - + require(assetNames.length <= assetLimit, "Number of assets requested is over limit"); + address tokenAddress = gateway.tokenAddresses(symbol); IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount); IERC20(tokenAddress).approve(address(gateway), amount); @@ -83,16 +85,18 @@ contract Ojo is IOjo, AxelarExecutable, Upgradable { } function _setup(bytes calldata data) internal override { - (string memory ojoChain_, string memory ojoAddress_, uint256 resolveWindow_) = abi.decode( + (string memory ojoChain_, string memory ojoAddress_, uint256 resolveWindow_, uint16 assetLimit_) = abi.decode( data, - (string, string, uint256) + (string, string, uint256, uint16) ); if (bytes(ojoChain).length != 0) revert AlreadyInitialized(); if (bytes(ojoAddress).length != 0) revert AlreadyInitialized(); if (resolveWindow != 0) revert AlreadyInitialized(); + if (assetLimit != 0) revert AlreadyInitialized(); ojoChain = ojoChain_; ojoAddress = ojoAddress_; resolveWindow = resolveWindow_; + assetLimit = assetLimit_; } function _execute( @@ -203,6 +207,10 @@ contract Ojo is IOjo, AxelarExecutable, Upgradable { resolveWindow = resolveWindow_; } + function updateAssetLimit(uint8 assetLimit_) external onlyOwner { + assetLimit = assetLimit_; + } + function contractId() external pure returns (bytes32) { return keccak256('ojo-v1'); } diff --git a/test/Ojo.ts b/test/Ojo.ts index 15dd930..03b282f 100644 --- a/test/Ojo.ts +++ b/test/Ojo.ts @@ -13,7 +13,8 @@ describe("Deploy OjoContract", function() { const ojoChain = "ojoChain"; const ojoAddress = "ojoAddress"; const resolveWindow = 100; - const initParams = ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256"],[ojoChain, ojoAddress, resolveWindow]); + const assetLimit = 5; + const initParams = ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256", "uint16"],[ojoChain, ojoAddress, resolveWindow, assetLimit]); const OjoProxy = await ethers.getContractFactory("OjoProxy"); const ojoProxy = await OjoProxy.deploy(); @@ -42,7 +43,10 @@ describe("Deploy OjoContract", function() { await ojo.connect(deployer).updateResolveWindow(150); expect(await ojo.resolveWindow()).eq(150); - // other account cannot update ojoChain, ojoAddress, and resolveWindow + await ojo.connect(deployer).updateAssetLimit(10); + expect(await ojo.assetLimit()).eq(10); + + // other account cannot update ojoChain, ojoAddress, resolveWindow, and assetLimit await expect(ojo.connect(otherAccount).updateOjoChain("ojoChain3")).to.be.revertedWithCustomError(ojo, "NotOwner"); expect(await ojo.ojoChain()).eq("ojoChain2"); @@ -51,6 +55,9 @@ describe("Deploy OjoContract", function() { await expect(ojo.connect(otherAccount).updateResolveWindow(200)).to.be.revertedWithCustomError(ojo, "NotOwner"); expect(await ojo.resolveWindow()).eq(150); + + await expect(ojo.connect(otherAccount).updateAssetLimit(20)).to.be.revertedWithCustomError(ojo, "NotOwner"); + expect(await ojo.assetLimit()).eq(10); }) it("reverts when trying to relay more than 5 assets at once", async function() { @@ -65,7 +72,7 @@ describe("Deploy OjoContract", function() { '0x00000000', '0x', {value: ethers.parseEther("0")} - )).to.be.revertedWith("Cannot relay more than 5 assets at a time"); + )).to.be.revertedWith("Number of assets requested is over limit"); await expect(ojo.connect(deployer).callContractMethodWithOjoPriceDataAndToken( assetNames, @@ -75,6 +82,6 @@ describe("Deploy OjoContract", function() { '', 0, {value: ethers.parseEther("0")} - )).to.be.revertedWith("Cannot relay more than 5 assets at a time"); + )).to.be.revertedWith("Number of assets requested is over limit"); }) })