Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/collateral swap 2 #369

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
dd9f1ca
feat: support non-listed nft
0x8f701 Apr 12, 2023
9fdcc53
feat: remove collateral swap approve process & add eth support & calc…
0x8f701 Apr 12, 2023
3d77ba1
fix: seperate listingPrice & supplyAmount
0x8f701 Apr 13, 2023
e68ccf1
chore: add more comments
0x8f701 Apr 13, 2023
c1a2738
feat: add missing supplyAmount check
0x8f701 Apr 13, 2023
b0f62df
fix: looksrare & blur adapter recipient
0x8f701 Apr 13, 2023
6332ca3
fix: collateral swap test cases
0x8f701 Apr 13, 2023
89f5bce
chore: use safeTransfer instead
0x8f701 Apr 13, 2023
d77d03a
feat: add missing tests
0x8f701 Apr 14, 2023
f974534
fix: lint
0x8f701 Apr 14, 2023
555f4c0
Merge branch 'main' into feat/collateral-swap-2
0x8f701 Apr 18, 2023
3d4243e
Merge remote-tracking branch 'origin/main' into feat/collateral-swap-2
0x8f701 Apr 20, 2023
7f6f5a6
Feat/collateral swap 2 - borrow any (#373)
0x8f701 Apr 21, 2023
a6e6a8d
Feat/collateral swap 2 - ptoken (#380)
0x8f701 Apr 21, 2023
3a44155
Merge branch 'main' into feat/collateral-swap-2
0x8f701 Apr 21, 2023
5feb7ba
feat: make collateralswap only works with ptoken
0x8f701 Apr 21, 2023
18dd06e
chore: add seaport v14 config
0x8f701 Apr 21, 2023
250a773
feat: consistent naming
0x8f701 Apr 21, 2023
0526092
feat: better naming
0x8f701 Apr 21, 2023
3567955
fix: ptoken tests
0x8f701 Apr 22, 2023
0fe791a
fix: ptoken tests
0x8f701 Apr 22, 2023
2d02b7b
fix: bid ptoken tests
0x8f701 Apr 23, 2023
cdcf693
fix: bid ptoken tests
0x8f701 Apr 23, 2023
7063359
feat: remove duplicated timelock code
0x8f701 Apr 23, 2023
6f6b4b7
chore: update ci to use make
0x8f701 Apr 23, 2023
3c259e1
feat: no need to check isListingPToken when supplyAmount != 0
0x8f701 Apr 23, 2023
ecd78bd
chore: fix warnings & use another error
0x8f701 Apr 23, 2023
6857436
Update ci.yml
woshihahaha Apr 23, 2023
4f476de
Update ci.yml
woshihahaha Apr 23, 2023
d2c494a
Update ci.yml
woshihahaha Apr 23, 2023
718a36e
fix: unreachable branch
0x8f701 Apr 24, 2023
7770e40
Merge branch 'feat/collateral-swap-2' of ssh://github.com/para-space/…
0x8f701 Apr 24, 2023
9b77634
fix: restrict dstToken for marketplace
0x8f701 Apr 24, 2023
075654c
fix: revert when amount out bigger than price
0x8f701 Apr 24, 2023
d9dd713
fix: leave extra swapped assets in ptoken for rescue
0x8f701 Apr 24, 2023
d349c10
fix: add missing verify
0x8f701 Apr 27, 2023
edb5841
Merge remote-tracking branch 'origin/main' into feat/collateral-swap-2
0x8f701 May 16, 2023
faf3272
feat: add support for swap with exactOutput
0x8f701 May 16, 2023
f31c459
Feat/ptoken debt swap (#388)
0x8f701 May 22, 2023
f447e71
feat: reset allowance at the end of swap tx
0x8f701 May 22, 2023
95aa30b
fix: mint debt after validateBorrow
0x8f701 May 22, 2023
0286f9d
fix: build
0x8f701 May 22, 2023
8ffb1bd
chore: revert yarn.lock
0x8f701 May 22, 2023
4ccbf08
feat: gas optimize
0x8f701 May 23, 2023
ee48439
feat: remove unnecessary decode
0x8f701 May 23, 2023
5e071a1
feat: limit debtToSwap to userTotalDebt
0x8f701 May 23, 2023
ee93c6a
Feat/private listing sell to opensea (#392)
0x8f701 Jun 8, 2023
a4da24f
chore: cleanup
0x8f701 Jun 9, 2023
39d8185
fix: remove redundant check
0x8f701 Jun 9, 2023
6632c66
fix: finding
0x8f701 Jun 12, 2023
68e6b11
refactor: logic
0x8f701 Jun 12, 2023
8e5d95a
chore: cleanup
0x8f701 Jun 14, 2023
5058014
feat: remove unused orderInfo.id in buyWithCredit
0x8f701 Jun 14, 2023
e68b743
feat: apply optimizatiom
0x8f701 Jun 14, 2023
7c52239
Merge remote-tracking branch 'origin/main' into feat/collateral-swap-2
0x8f701 Jul 6, 2023
4c2f46f
chore: format
0x8f701 Jul 6, 2023
9d14490
feat: dont verify credit if creditAmount == 0
0x8f701 Jul 6, 2023
daf1755
feat: remove extra logic branches
0x8f701 Jul 6, 2023
e399c19
chore: add more comments
0x8f701 Jul 6, 2023
7d4c681
feat: remove ethLeft from vars
0x8f701 Jul 6, 2023
7705a25
feat: remove duplicated code
0x8f701 Jul 6, 2023
d145853
feat: remove duplicated code
0x8f701 Jul 6, 2023
5a41a31
feat: remove msg.value check
0x8f701 Jul 7, 2023
635eac6
feat: remove redundant check
0x8f701 Jul 7, 2023
d4c99c1
fix: tests
0x8f701 Jul 7, 2023
86de1ec
feat: limit marketplace offer to be same collection
0x8f701 Jul 7, 2023
f3c9768
fix: typo
0x8f701 Jul 9, 2023
83db9a9
feat: remove one if else
0x8f701 Jul 9, 2023
81cf9e5
feat: batch supply
0x8f701 Jul 9, 2023
9b07cd5
fix: typo
0x8f701 Jul 10, 2023
d4c6c6c
feat: simplify
0x8f701 Jul 10, 2023
2adfe1c
feat: resolve comments
0x8f701 Jul 10, 2023
71e189b
feat: add batchAcceptOpenseaBid
0x8f701 Jul 11, 2023
d78fa85
feat: cache requiredItemType
0x8f701 Jul 11, 2023
f35ec00
feat: batch collateralize
0x8f701 Jul 11, 2023
1d3cbbe
feat: improve gas
0x8f701 Jul 11, 2023
65c800b
feat: improve gas
0x8f701 Jul 11, 2023
fe27530
fix: typo
0x8f701 Jul 11, 2023
238acdb
chore: update lockfile
0x8f701 Jul 18, 2023
c7cfb0f
fix: unused lib
0x8f701 Jul 18, 2023
92bb4d6
fix: remove redundant check
0x8f701 Jul 18, 2023
9506a4e
fix: remove transferToken
0x8f701 Jul 18, 2023
33766a0
chore: revert husky
0x8f701 Jul 18, 2023
f7adee4
fix: remove 1 mstore
0x8f701 Jul 18, 2023
153652c
fix: remove typos
0x8f701 Jul 18, 2023
add9a62
Merge branch 'main' into feat/collateral-swap-2
0x8f701 Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Merge branch 'main' into feat/collateral-swap-2
  • Loading branch information
0x8f701 committed Sep 12, 2023
commit add9a62e8acefefaaf23750a66d63cfd9fc58fe9
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ DEPLOY_END=24
# FORK=mainnet
RPC_URL=http://localhost:8545
DEPLOY_INCREMENTAL=false
STACKUP_KEY=aaaaaabbbbbbcccccddddd
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"node/no-missing-import": "off",
"no-unpublished-import": "off",
"no-case-declarations": "off",
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ coverage.json
/coverage
dist

artifacts-zk/
cache-zk/
zk-libraries.json

keystore/

# Setting for non zero-installs (https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored)
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
18.16.0
47 changes: 36 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ init: submodules

.PHONY: test
test:
npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} # --verbose

npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} --no-compile
.PHONY: local-test
local-test:
make MOCHA_JOBS=0 DB_PATH=deployed-contracts.json DEPLOY_START=21 NETWORK=localhost test

.PHONY: slow-test
slow-test:
MOCHA_JOBS=0 DB_PATH=deployed-contracts.json npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} # --verbose
MOCHA_JOBS=0 DB_PATH=deployed-contracts.json npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} --no-compile

.PHONY: fast-test
fast-test:
MOCHA_JOBS=4 DB_PATH=:memory: npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} # --verbose
MOCHA_JOBS=4 DB_PATH=:memory: npx hardhat test ./test/${TEST_TARGET} --network ${NETWORK} --no-compile

.PHONY: size
size:
yarn size

.PHONY: build
build: clean
yarn build
yarn build --network ${NETWORK}
yarn typechain

.PHONY: doc
doc:
Expand All @@ -51,7 +51,7 @@ lint:

.PHONY: coverage
coverage:
yarn coverage
yarn coverage --no-compile

.PHONY: format
format:
Expand Down Expand Up @@ -301,7 +301,7 @@ test-stakefish-nft:

.PHONY: run
run:
npx hardhat run $(SCRIPT_PATH) --network $(NETWORK)
npx hardhat run $(SCRIPT_PATH) --network $(NETWORK) --no-compile

.PHONY: run-task
run-task:
Expand Down Expand Up @@ -411,6 +411,10 @@ deploy-timelock:
deploy-renounceOwnership:
make TASK_NAME=deploy:renounce-ownership run-task

.PHONY: deploy-all-libraries
deploy-all-libraries:
make TASK_NAME=deploy:all-libraries run-task

.PHONY: ad-hoc
ad-hoc:
make SCRIPT_PATH=./scripts/dev/1.ad-hoc.ts run
Expand Down Expand Up @@ -459,6 +463,14 @@ set-timelock-strategy:
acl:
make SCRIPT_PATH=./scripts/dev/13.acl.ts run

.PHONY: zksync-bytecode-hashes
zksync-bytecode-hashes:
make SCRIPT_PATH=./scripts/dev/14.zksync-bytecode-hashes.ts run

.PHONY: redeploy-market
redeploy-market:
make SCRIPT_PATH=./scripts/dev/15.redeploy-market.ts run

.PHONY: transfer-tokens
transfer-tokens:
make SCRIPT_PATH=./scripts/dev/2.transfer-tokens.ts run
Expand Down Expand Up @@ -627,6 +639,10 @@ upgrade-pool-marketplace:
upgrade-pool-ape-staking:
make TASK_NAME=upgrade:pool-ape-staking run-task

.PHONY: upgrade-borrow_ape_and_stake
upgrade-borrow_ape_and_stake:
make TASK_NAME=upgrade:borrow-ape-and-stake run-task

.PHONY: upgrade-pool-parameters
upgrade-pool-parameters:
make TASK_NAME=upgrade:pool-parameters run-task
Expand All @@ -651,6 +667,14 @@ upgrade-auto-compound-ape:
upgrade-timelock:
make TASK_NAME=upgrade:timelock run-task

.PHONY: upgrade-helper-contract
upgrade-helper-contract:
make TASK_NAME=upgrade:helper-contract run-task

.PHONY: upgrade-account-abstraction
upgrade-account-abstraction:
make TASK_NAME=upgrade:account-abstraction run-task

.PHONY: upgrade-p2p-pair-staking
upgrade-p2p-pair-staking:
make TASK_NAME=upgrade:p2p-pair-staking run-task
Expand Down Expand Up @@ -686,15 +710,16 @@ hardhat:
.PHONY: anvil
anvil:
anvil \
$(if $(FORK),--fork-url https://eth-$(FORK).alchemyapi.io/v2/$(ALCHEMY_KEY) --no-rate-limit,) \
$(if $(FORK),--chain-id 522,--chain-id 31337) \
--tracing \
$(if $(FORK),--fork-url https://eth-$(FORK).alchemyapi.io/v2/$(ALCHEMY_KEY) --chain-id 522 --no-rate-limit,--chain-id 31337) \
$(if $(FORK_BLOCK_NUMBER),--fork-block-number $(FORK_BLOCK_NUMBER),) \
$(if $(DEPLOYER_MNEMONIC),--mnemonic "${DEPLOYER_MNEMONIC}",--mnemonic "test test test test test test test test test test test junk") \
--host 0.0.0.0 \
--state-interval 60 \
--dump-state state.json \
$(if $(wildcard state.json),--load-state state.json,) \
--disable-block-gas-limit \
--code-size-limit 100000 \
--timeout 9000000

.PHONY: image
image:
Expand All @@ -716,7 +741,7 @@ shutdown:
docker-compose \
down \
--remove-orphans > /dev/null 2>&1 || true
docker volume prune -f
docker volume prune -f || true
sudo rm -fr redis-data || true
sudo rm -fr logs || true
sudo rm -fr state.json || true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![CI](https://github.com/para-space/paraspace-core/workflows/CI/badge.svg)](https://github.com/para-space/paraspace-core/actions)
[![License](https://img.shields.io/github/license/para-space/paraspace-core?color=green)](https://github.com/para-space/paraspace-core/blob/main/LICENSE)

[![Twitter URL](https://img.shields.io/twitter/follow/Paraspace_Official?style=social)](https://twitter.com/paraspace_CM)
[![Twitter URL](https://img.shields.io/twitter/follow/ParaSpace_NFT?style=social)](https://twitter.com/ParaSpace_NFT)
[![Telegram](https://img.shields.io/badge/Telegram-gray?logo=telegram)](https://t.me/parallelfi_community)
[![Medium](https://img.shields.io/badge/Medium-gray?logo=medium)](https://medium.com/@paraspace)
[![Discourse](https://img.shields.io/badge/Forum-gray?logo=discourse)](https://discourse.para.space)
Expand Down
Binary file added audits/SECURE3-V2.pdf
Binary file not shown.
192 changes: 192 additions & 0 deletions contracts/account-abstraction/Account.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {SignatureChecker} from "../dependencies/openzeppelin/contracts/SignatureChecker.sol";
import "./base-account-abstraction/core/BaseAccount.sol";
import "./callback/TokenCallbackHandler.sol";

/**
* Address Owned Account.
* this is sample minimal account.
* has execute, eth handling methods
* has a single signer that can send requests through the entryPoint.
*/
contract Account is BaseAccount, TokenCallbackHandler, IERC1271, Initializable {
using ECDSA for bytes32;

address public owner;

IEntryPoint private immutable _entryPoint;

event AccountInitialized(
IEntryPoint indexed entryPoint,
address indexed owner
);

modifier onlyOwner() {
_onlyOwner();
_;
}

/// @inheritdoc BaseAccount
function entryPoint() public view virtual override returns (IEntryPoint) {
return _entryPoint;
}

// solhint-disable-next-line no-empty-blocks
receive() external payable {}

constructor(IEntryPoint anEntryPoint) {
_entryPoint = anEntryPoint;
_disableInitializers();
}

function _onlyOwner() internal view {
//directly from EOA owner, or through the account itself (which gets redirected through execute())
require(
msg.sender == owner || msg.sender == address(this),
"only owner"
);
}

/**
* execute a transaction (called directly from owner, or by entryPoint)
*/
function execute(
address dest,
uint256 value,
bytes calldata func
) external {
_requireFromEntryPointOrOwner();

_call(dest, value, func);
}

/**
* execute a sequence of transactions
*/
function executeBatch(
address[] calldata dest,
uint256[] calldata value,
bytes[] calldata func
) external {
_requireFromEntryPointOrOwner();

require(
dest.length == func.length &&
(value.length == 0 || value.length == func.length),
"wrong array lengths"
);
if (value.length == 0) {
for (uint256 i = 0; i < dest.length; i++) {
_call(dest[i], 0, func[i]);
}
} else {
for (uint256 i = 0; i < dest.length; i++) {
_call(dest[i], value[i], func[i]);
}
}
}

/**
* @dev The _entryPoint member is immutable, to reduce gas consumption. To upgrade EntryPoint,
* a new implementation of SimpleAccount must be deployed with the new EntryPoint address, then upgrading
* the implementation by calling `upgradeTo()`
*/
function initialize(address anOwner) public virtual initializer {
_initialize(anOwner);
}

function _initialize(address anOwner) internal virtual {
owner = anOwner;
emit AccountInitialized(_entryPoint, owner);
}

// Require the function call went through EntryPoint or owner
function _requireFromEntryPointOrOwner() internal view {
require(
msg.sender == address(entryPoint()) || msg.sender == owner,
"account: not Owner or EntryPoint"
);
}

/// implement template method of BaseAccount
function _validateSignature(
UserOperation calldata userOp,
bytes32 userOpHash
) internal virtual override returns (uint256 validationData) {
bytes32 hash = userOpHash;

address curOwner = owner;
if (curOwner.code.length == 0) {
hash = userOpHash.toEthSignedMessageHash();
}

bool isValid = SignatureChecker.isValidSignatureNow(
curOwner,
hash,
userOp.signature
);

if (isValid) {
return 0;
}

return SIG_VALIDATION_FAILED;
}

function isValidSignature(
bytes32 hash,
bytes memory signature
) external view returns (bytes4) {
bool isValid = SignatureChecker.isValidSignatureNow(
owner,
hash,
signature
);

if (isValid) {
return IERC1271.isValidSignature.selector;
}

return "";
}

function _call(address target, uint256 value, bytes memory data) internal {
(bool success, bytes memory result) = target.call{value: value}(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}

/**
* check current account deposit in the entryPoint
*/
function getDeposit() public view returns (uint256) {
return entryPoint().balanceOf(address(this));
}

/**
* deposit more funds for this account in the entryPoint
*/
function addDeposit() public payable {
entryPoint().depositTo{value: msg.value}(address(this));
}

/**
* withdraw value from the account's deposit
* @param withdrawAddress target to send to
* @param amount to withdraw
*/
function withdrawDepositTo(
address payable withdrawAddress,
uint256 amount
) public onlyOwner {
entryPoint().withdrawTo(withdrawAddress, amount);
}
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.