diff --git a/packages/contracts/contracts/DirectPayments/DirectPaymentsPool.sol b/packages/contracts/contracts/DirectPayments/DirectPaymentsPool.sol index 426134ef..11546697 100644 --- a/packages/contracts/contracts/DirectPayments/DirectPaymentsPool.sol +++ b/packages/contracts/contracts/DirectPayments/DirectPaymentsPool.sol @@ -112,7 +112,7 @@ contract DirectPaymentsPool is DirectPaymentsFactory public registry; /// @custom:oz-upgrades-unsafe-allow constructor - constructor(ISuperfluid _host, ISwapRouter _swapRouter) GoodCollectiveSuperApp(_host, _swapRouter) {} + constructor(ISuperfluid _host, IV3SwapRouter _swapRouter) GoodCollectiveSuperApp(_host, _swapRouter) {} /** * @dev Authorizes an upgrade for the implementation contract. diff --git a/packages/contracts/contracts/GoodCollective/GoodCollectiveSuperApp.sol b/packages/contracts/contracts/GoodCollective/GoodCollectiveSuperApp.sol index 22d20d9b..79ed5964 100644 --- a/packages/contracts/contracts/GoodCollective/GoodCollectiveSuperApp.sol +++ b/packages/contracts/contracts/GoodCollective/GoodCollectiveSuperApp.sol @@ -9,7 +9,7 @@ import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/cont import { CFAv1Library, IConstantFlowAgreementV1 } from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol"; import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; -import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; +import "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol"; import "../DirectPayments/DirectPaymentsFactory.sol"; import "../utils/HelperLibrary.sol"; @@ -51,7 +51,7 @@ abstract contract GoodCollectiveSuperApp is SuperAppBaseFlow { // ask about "receiver" can it be different then app? /// @custom:oz-upgrades-unsafe-allow state-variable-immutable - ISwapRouter public immutable swapRouter; + IV3SwapRouter public immutable swapRouter; struct SupporterData { uint256 contribution; @@ -71,7 +71,7 @@ abstract contract GoodCollectiveSuperApp is SuperAppBaseFlow { uint256[48] private _reserved; /// @custom:oz-upgrades-unsafe-allow constructor - constructor(ISuperfluid _host, ISwapRouter _swapRouter) SuperAppBaseFlow(_host) { + constructor(ISuperfluid _host, IV3SwapRouter _swapRouter) SuperAppBaseFlow(_host) { if (address(_host) == address(0)) revert ZERO_ADDRESS(); swapRouter = _swapRouter; } diff --git a/packages/contracts/contracts/utils/HelperLibrary.sol b/packages/contracts/contracts/utils/HelperLibrary.sol index 3e4e6d57..496c2083 100644 --- a/packages/contracts/contracts/utils/HelperLibrary.sol +++ b/packages/contracts/contracts/utils/HelperLibrary.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.0; import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol"; -import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; +import "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol"; import { ISuperToken } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperfluid.sol"; import { SuperTokenV1Library } from "@superfluid-finance/ethereum-contracts/contracts/apps/SuperTokenV1Library.sol"; @@ -29,7 +29,7 @@ library HelperLibrary { } function handleSwap( - ISwapRouter swapRouter, + IV3SwapRouter swapRouter, SwapData memory _customData, address outTokenIfNoPath, address _sender @@ -42,22 +42,20 @@ library HelperLibrary { if (_customData.path.length > 0) { // If a path is provided, execute a multi-hop swap - ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({ + IV3SwapRouter.ExactInputParams memory params = IV3SwapRouter.ExactInputParams({ path: _customData.path, recipient: _sender, - deadline: _customData.deadline, amountIn: _customData.amount, amountOutMinimum: _customData.minReturn }); swapRouter.exactInput(params); } else { // If no path is provided, execute a single-hop swap - ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({ + IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter.ExactInputSingleParams({ tokenIn: _customData.swapFrom, tokenOut: outTokenIfNoPath, fee: 10000, recipient: _sender, - deadline: _customData.deadline, amountIn: _customData.amount, amountOutMinimum: _customData.minReturn, sqrtPriceLimitX96: 0 diff --git a/packages/contracts/contracts/utils/SwapRouterMock.sol b/packages/contracts/contracts/utils/SwapRouterMock.sol index 0e7c3fb4..6f53425f 100644 --- a/packages/contracts/contracts/utils/SwapRouterMock.sol +++ b/packages/contracts/contracts/utils/SwapRouterMock.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; +import "@uniswap/swap-router-contracts/contracts/interfaces/IV3SwapRouter.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; contract SwapRouterMock { @@ -14,7 +14,7 @@ contract SwapRouterMock { /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token - function exactInput(ISwapRouter.ExactInputParams calldata params) external payable returns (uint256 amountOut) { + function exactInput(IV3SwapRouter.ExactInputParams calldata params) external payable returns (uint256 amountOut) { amountOut = params.amountOutMinimum; // Transfer the output token to the recipient @@ -22,7 +22,7 @@ contract SwapRouterMock { } function exactInputSingle( - ISwapRouter.ExactInputSingleParams memory params + IV3SwapRouter.ExactInputSingleParams memory params ) external payable returns (uint256 amountOut) { amountOut = params.amountOutMinimum; diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 09d0dfbd..906315e3 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -28,6 +28,7 @@ "@types/prettier": "^2", "@types/sinon-chai": "^3.2.3", "@typescript-eslint/eslint-plugin": "^5.60.0", + "@uniswap/swap-router-contracts": "^1.3.1", "@uniswap/v3-periphery": "^1.4.3", "chai": "^4.2.0", "dotenv": "^16.3.1", diff --git a/packages/contracts/test/DirectPayments/DirectPayments.superapp.test.ts b/packages/contracts/test/DirectPayments/DirectPayments.superapp.test.ts index 18ade3a9..562bcbed 100644 --- a/packages/contracts/test/DirectPayments/DirectPayments.superapp.test.ts +++ b/packages/contracts/test/DirectPayments/DirectPayments.superapp.test.ts @@ -163,7 +163,7 @@ describe('DirectPaymentsPool Superapp', () => { await mine(2, { interval: 5 }); const supporter = await pool.supporters(signer.address); expect(supporter.contribution) - .gt(Number(baseFlowRate) * 10) + .gt(Number(baseFlowRate) * 5) .gt(before.contribution); expect(supporter.lastUpdated).gt(before.lastUpdated); expect(supporter.flowRate).equal(ethers.constants.WeiPerEther.toString()); diff --git a/packages/sdk-js/package.json b/packages/sdk-js/package.json index 3c0b162a..910c0653 100644 --- a/packages/sdk-js/package.json +++ b/packages/sdk-js/package.json @@ -31,6 +31,7 @@ "eslint-config-prettier": "^8.8.0", "ethers": "5", "prettier": "^2.8.8", + "ts-node": "^10.9.2", "typescript": "5", "vite": "^4.3.9", "vitest": "^0.32.2" diff --git a/packages/sdk-js/src/goodcollective/goodcollective.ts b/packages/sdk-js/src/goodcollective/goodcollective.ts index 4d39784f..d8323cf8 100644 --- a/packages/sdk-js/src/goodcollective/goodcollective.ts +++ b/packages/sdk-js/src/goodcollective/goodcollective.ts @@ -317,4 +317,11 @@ export class GoodCollectiveSDK { return op.exec(signer); } + + async swap(signer: ethers.Signer, poolAddress: string, swap: SwapData) { + const signerAddress = await signer.getAddress(); + + const tx = await this.pool.attach(poolAddress).connect(signer).handleSwap(swap, signerAddress, '0x'); + return tx; + } } diff --git a/yarn.lock b/yarn.lock index 81255515..fea25df9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4633,6 +4633,7 @@ __metadata: "@types/prettier": ^2 "@types/sinon-chai": ^3.2.3 "@typescript-eslint/eslint-plugin": ^5.60.0 + "@uniswap/swap-router-contracts": ^1.3.1 "@uniswap/v3-periphery": ^1.4.3 chai: ^4.2.0 dotenv: ^16.3.1 @@ -4669,6 +4670,7 @@ __metadata: graphql: ^16.7.1 nft.storage: ^7.1.1 prettier: ^2.8.8 + ts-node: ^10.9.2 typescript: 5 vite: ^4.3.9 vitest: ^0.32.2 @@ -11719,7 +11721,7 @@ __metadata: languageName: node linkType: hard -"@uniswap/swap-router-contracts@npm:^1.1.0, @uniswap/swap-router-contracts@npm:^1.2.1, @uniswap/swap-router-contracts@npm:^1.3.0": +"@uniswap/swap-router-contracts@npm:^1.1.0, @uniswap/swap-router-contracts@npm:^1.2.1, @uniswap/swap-router-contracts@npm:^1.3.0, @uniswap/swap-router-contracts@npm:^1.3.1": version: 1.3.1 resolution: "@uniswap/swap-router-contracts@npm:1.3.1" dependencies: @@ -38916,6 +38918,44 @@ __metadata: languageName: node linkType: hard +"ts-node@npm:^10.9.2": + version: 10.9.2 + resolution: "ts-node@npm:10.9.2" + dependencies: + "@cspotcode/source-map-support": ^0.8.0 + "@tsconfig/node10": ^1.0.7 + "@tsconfig/node12": ^1.0.7 + "@tsconfig/node14": ^1.0.0 + "@tsconfig/node16": ^1.0.2 + acorn: ^8.4.1 + acorn-walk: ^8.1.1 + arg: ^4.1.0 + create-require: ^1.1.0 + diff: ^4.0.1 + make-error: ^1.1.1 + v8-compile-cache-lib: ^3.0.1 + yn: 3.1.1 + peerDependencies: + "@swc/core": ">=1.2.50" + "@swc/wasm": ">=1.2.50" + "@types/node": "*" + typescript: ">=2.7" + peerDependenciesMeta: + "@swc/core": + optional: true + "@swc/wasm": + optional: true + bin: + ts-node: dist/bin.js + ts-node-cwd: dist/bin-cwd.js + ts-node-esm: dist/bin-esm.js + ts-node-script: dist/bin-script.js + ts-node-transpile-only: dist/bin-transpile.js + ts-script: dist/bin-script-deprecated.js + checksum: fde256c9073969e234526e2cfead42591b9a2aec5222bac154b0de2fa9e4ceb30efcd717ee8bc785a56f3a119bdd5aa27b333d9dbec94ed254bd26f8944c67ac + languageName: node + linkType: hard + "ts-patch@npm:^2.0.2": version: 2.1.0 resolution: "ts-patch@npm:2.1.0" @@ -39370,7 +39410,7 @@ __metadata: "typescript@patch:typescript@5#~builtin, typescript@patch:typescript@^5.1.3#~builtin": version: 5.2.2 - resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=5da071" + resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=14eedb" bin: tsc: bin/tsc tsserver: bin/tsserver