diff --git a/DaoPools/abis/PriceFeed.json b/DaoPools/abis/PriceFeed.json index 2c479f0..3da40cd 100644 --- a/DaoPools/abis/PriceFeed.json +++ b/DaoPools/abis/PriceFeed.json @@ -16,116 +16,81 @@ "anonymous": false, "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" + "indexed": false, + "internalType": "address[]", + "name": "newOwners", + "type": "address[]" } ], - "name": "OwnershipTransferred", + "name": "OwnersAdded", "type": "event" }, { - "inputs": [], - "name": "__PriceFeed_init", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { + "anonymous": false, "inputs": [ { + "indexed": false, "internalType": "address[]", - "name": "pathTokens", + "name": "removedOwners", "type": "address[]" } ], - "name": "addPathTokens", + "name": "OwnersRemoved", + "type": "event" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum IPriceFeed.PoolInterfaceType", + "name": "poolType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "internalType": "struct IPriceFeed.PoolType[]", + "name": "poolTypes", + "type": "tuple[]" + } + ], + "name": "__PriceFeed_init", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "inToken", - "type": "address" - }, - { - "internalType": "address", - "name": "outToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, { "internalType": "address[]", - "name": "optionalPath", + "name": "newOwners_", "type": "address[]" - }, - { - "internalType": "uint256", - "name": "minAmountOut", - "type": "uint256" - } - ], - "name": "exchangeFromExact", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" } ], + "name": "addOwners", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "inToken", - "type": "address" - }, - { - "internalType": "address", - "name": "outToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, { "internalType": "address[]", - "name": "optionalPath", + "name": "pathTokens", "type": "address[]" - }, - { - "internalType": "uint256", - "name": "maxAmountIn", - "type": "uint256" - } - ], - "name": "exchangeToExact", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" } ], + "name": "addPathTokens", + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, @@ -147,9 +112,21 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "optionalPath", - "type": "address[]" + "type": "tuple" } ], "name": "getExtendedPriceIn", @@ -160,12 +137,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -186,9 +175,21 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "optionalPath", - "type": "address[]" + "type": "tuple" } ], "name": "getExtendedPriceOut", @@ -199,12 +200,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -213,7 +226,7 @@ "outputs": [ { "internalType": "address", - "name": "_injector", + "name": "injector_", "type": "address" } ], @@ -238,9 +251,21 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "optionalPath", - "type": "address[]" + "type": "tuple" } ], "name": "getNormalizedExtendedPriceIn", @@ -251,12 +276,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -277,9 +314,21 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "optionalPath", - "type": "address[]" + "type": "tuple" } ], "name": "getNormalizedExtendedPriceOut", @@ -290,12 +339,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -324,12 +385,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -353,12 +426,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -382,12 +467,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -416,12 +513,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -445,12 +554,24 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { @@ -474,17 +595,29 @@ "type": "uint256" }, { - "internalType": "address[]", + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", "name": "path", - "type": "address[]" + "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "getPathTokens", + "name": "getOwners", "outputs": [ { "internalType": "address[]", @@ -496,24 +629,8 @@ "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "getSavedPaths", + "inputs": [], + "name": "getPathTokens", "outputs": [ { "internalType": "address[]", @@ -525,19 +642,43 @@ "type": "function" }, { - "inputs": [ + "inputs": [], + "name": "getPoolTypes", + "outputs": [ { - "internalType": "address", - "name": "token", - "type": "address" + "components": [ + { + "internalType": "enum IPriceFeed.PoolInterfaceType", + "name": "poolType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "internalType": "struct IPriceFeed.PoolType[]", + "name": "", + "type": "tuple[]" } ], - "name": "isSupportedPathToken", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPoolTypesLength", "outputs": [ { - "internalType": "bool", + "internalType": "uint256", "name": "", - "type": "bool" + "type": "uint256" } ], "stateMutability": "view", @@ -557,26 +698,33 @@ }, { "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "address[]", - "name": "optionalPath", - "type": "address[]" - }, - { - "internalType": "uint256", - "name": "minAmountOut", + "name": "amountOut", "type": "uint256" } ], - "name": "normalizedExchangeFromExact", + "name": "getPriceIn", "outputs": [ { "internalType": "uint256", - "name": "", + "name": "amountIn", "type": "uint256" + }, + { + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", + "name": "path", + "type": "tuple" } ], "stateMutability": "nonpayable", @@ -594,46 +742,91 @@ "name": "outToken", "type": "address" }, + { + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + } + ], + "name": "getPriceOut", + "outputs": [ { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, { - "internalType": "address[]", - "name": "optionalPath", - "type": "address[]" - }, + "components": [ + { + "internalType": "address[]", + "name": "path", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "poolTypes", + "type": "uint8[]" + } + ], + "internalType": "struct IPriceFeed.SwapPath", + "name": "path", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ { - "internalType": "uint256", - "name": "maxAmountIn", - "type": "uint256" + "internalType": "address", + "name": "address_", + "type": "address" } ], - "name": "normalizedExchangeToExact", + "name": "isOwner", "outputs": [ { - "internalType": "uint256", + "internalType": "bool", "name": "", - "type": "uint256" + "type": "bool" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { - "inputs": [], - "name": "owner", - "outputs": [ + "inputs": [ { "internalType": "address", - "name": "", + "name": "token", "type": "address" } ], + "name": "isSupportedPathToken", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "oldOwners_", + "type": "address[]" + } + ], + "name": "removeOwners", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -660,6 +853,11 @@ "internalType": "address", "name": "contractsRegistry", "type": "address" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" } ], "name": "setDependencies", @@ -671,7 +869,7 @@ "inputs": [ { "internalType": "address", - "name": "_injector", + "name": "injector_", "type": "address" } ], @@ -680,53 +878,44 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "totalPathTokens", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", + "components": [ + { + "internalType": "enum IPriceFeed.PoolInterfaceType", + "name": "poolType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "uint24", + "name": "fee", + "type": "uint24" + } + ], + "internalType": "struct IPriceFeed.PoolType[]", + "name": "poolTypes", + "type": "tuple[]" + } + ], + "name": "setPoolTypes", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], - "name": "uniswapFactory", - "outputs": [ - { - "internalType": "contract IUniswapV2Factory", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "uniswapV2Router", + "name": "totalPathTokens", "outputs": [ { - "internalType": "contract IUniswapV2Router02", + "internalType": "uint256", "name": "", - "type": "address" + "type": "uint256" } ], "stateMutability": "view", diff --git a/DaoPools/src/helpers/PriceFeedInteractions.ts b/DaoPools/src/helpers/PriceFeedInteractions.ts index 549f452..f09c133 100644 --- a/DaoPools/src/helpers/PriceFeedInteractions.ts +++ b/DaoPools/src/helpers/PriceFeedInteractions.ts @@ -22,26 +22,3 @@ export function getUSDValue(token: Bytes, amount: BigInt): BigInt { return resp.value.value0; } } - -export function getTokenValue(fromToken: Bytes, toToken: Bytes, amount: BigInt): BigInt { - let pfPrototype = PriceFeed.bind(Address.fromString(PRICE_FEED_ADDRESS)); - - let resp = pfPrototype.try_getNormalizedPriceOut(Address.fromBytes(fromToken), Address.fromBytes(toToken), amount); - if (resp.reverted) { - log.warning("try_getNormalizedPriceOut reverted. FromToken: {}, ToToken: {}, Amount:{}", [ - fromToken.toHexString(), - toToken.toHexString(), - amount.toString(), - ]); - return BigInt.zero(); - } else { - if (resp.value.value1.length == 0) { - log.warning("try_getNormalizedPriceOut returned 0 length path. FromToken: {}, ToToken: {}, Amount:{}", [ - fromToken.toHexString(), - toToken.toHexString(), - amount.toString(), - ]); - } - return resp.value.value0; - } -} diff --git a/DaoPools/tests/DaoPool.test.ts b/DaoPools/tests/DaoPool.test.ts index 48d95e2..637665e 100644 --- a/DaoPools/tests/DaoPool.test.ts +++ b/DaoPools/tests/DaoPool.test.ts @@ -369,10 +369,14 @@ const USER_KEEPER_ADDRESS = "0x96e08f7d84603AEb97cd1c89A80A9e914f181670"; describe("DaoPool", () => { beforeAll(() => { + let swapPath = new ethereum.Tuple(2); + swapPath[0] = ethereum.Value.fromAddressArray([contractSender]); + swapPath[1] = ethereum.Value.fromI32Array([1]); + createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181672")), @@ -380,13 +384,13 @@ describe("DaoPool", () => { ]) .returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(1000000000000000000)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), + ethereum.Value.fromTuple(swapPath), ]); createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181673")), @@ -394,50 +398,41 @@ describe("DaoPool", () => { ]) .returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(2000000000000000000)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), + ethereum.Value.fromTuple(swapPath), ]); createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181676")), ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(1000)), ]) - .returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(200)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), - ]); + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(200)), ethereum.Value.fromTuple(swapPath)]); createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181676")), ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(500)), ]) - .returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(100)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), - ]); + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(100)), ethereum.Value.fromTuple(swapPath)]); createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181676")), ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(3000)), ]) - .returns([ - ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(1500)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), - ]); + .returns([ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(1500)), ethereum.Value.fromTuple(swapPath)]); createMockedFunction( Address.fromString(USER_KEEPER_ADDRESS), diff --git a/DaoPools/tests/DistributionProposal.test.ts b/DaoPools/tests/DistributionProposal.test.ts index 6035a55..e1557ec 100644 --- a/DaoPools/tests/DistributionProposal.test.ts +++ b/DaoPools/tests/DistributionProposal.test.ts @@ -38,10 +38,14 @@ const proposalId = BigInt.fromI32(2); describe("DistributionProposal", () => { beforeEach(() => { + let swapPath = new ethereum.Tuple(2); + swapPath[0] = ethereum.Value.fromAddressArray([contractSender]); + swapPath[1] = ethereum.Value.fromI32Array([1]); + createMockedFunction( Address.fromString(PRICE_FEED_ADDRESS), "getNormalizedPriceOutUSD", - "getNormalizedPriceOutUSD(address,uint256):(uint256,address[])" + "getNormalizedPriceOutUSD(address,uint256):(uint256,(address[],uint8[]))" ) .withArgs([ ethereum.Value.fromAddress(Address.fromString("0x86e08f7d84603aeb97cd1c89a80a9e914f181672")), @@ -49,7 +53,7 @@ describe("DistributionProposal", () => { ]) .returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromU64(10000000000000000000)), - ethereum.Value.fromAddressArray([contractSender, contractSender]), + ethereum.Value.fromTuple(swapPath), ]); let dPContract = new DPContract(contractSender);