Skip to content

Commit

Permalink
fix: celo router02 no deadline
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Feb 4, 2024
1 parent 1041cd7 commit e02401b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions packages/contracts/contracts/utils/HelperLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -29,7 +29,7 @@ library HelperLibrary {
}

function handleSwap(
ISwapRouter swapRouter,
IV3SwapRouter swapRouter,
SwapData memory _customData,
address outTokenIfNoPath,
address _sender
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/contracts/utils/SwapRouterMock.sol
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,15 +14,15 @@ 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
_token.transfer(params.recipient, amountOut);
}

function exactInputSingle(
ISwapRouter.ExactInputSingleParams memory params
IV3SwapRouter.ExactInputSingleParams memory params
) external payable returns (uint256 amountOut) {
amountOut = params.amountOutMinimum;

Expand Down
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk-js/src/goodcollective/goodcollective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
44 changes: 42 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -39370,7 +39410,7 @@ __metadata:

"typescript@patch:typescript@5#~builtin<compat/typescript>, typescript@patch:typescript@^5.1.3#~builtin<compat/typescript>":
version: 5.2.2
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=5da071"
resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin<compat/typescript>::version=5.2.2&hash=14eedb"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
Expand Down

0 comments on commit e02401b

Please sign in to comment.