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/add bulker tests e2e #68

Merged
merged 34 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5d439db
feat(bulker): simplify signature retrieval
julien-devatom Jul 24, 2023
c2f7d43
feat(bulker): throw errors instead of silent fail
julien-devatom Jul 24, 2023
c54de4a
test(bulker-e2e): supply collateral
julien-devatom Jul 24, 2023
60bc1b0
test(bulker-e2e): Test supply only weth
ghivert Jul 24, 2023
0df1f79
test(bulker-e2e): Supply collateral + borrow
ghivert Jul 25, 2023
d59fd31
test(bulker-e2e): Supply WETH without ETH to wrap
ghivert Jul 25, 2023
2418388
test(bulker-e2e): Supply stETH without wstETH
ghivert Jul 25, 2023
3e0016d
test(bulker-e2e): supply wstETH with some stETH and wstETH
ghivert Jul 25, 2023
261bee5
test(bulker-e2e): Improve test naming
ghivert Jul 25, 2023
a436fd9
test(bulker-e2e): Supply stETH with wstETH and supply WETH full wrap
ghivert Jul 25, 2023
696dd04
test(bulker-e2e): Borrow WETH with previous collateral position
ghivert Jul 25, 2023
4639a18
test(bulker-e2e): Borrow ETH with previous collateral and unwrap
ghivert Jul 25, 2023
877e9b8
test(bulker-e2e): Move describe to have a more natural test suite
ghivert Jul 25, 2023
d24c46f
test(bulker-e2e): Withdraw ETH
ghivert Jul 25, 2023
ef99267
test(bulker-e2e): Withdraw WETH with unwrap
ghivert Jul 25, 2023
6153f9d
test(bulker-e2e): Repay ETH with approval and Permit2
ghivert Jul 25, 2023
ec2e5ac
test(bulker-e2e): Repay WETH with ETH
ghivert Jul 25, 2023
2a0b746
test(bulker-e2e): Supply collateral twice
ghivert Jul 25, 2023
66d3a02
test(bulker-e2e): Repay and withdraw collateral
ghivert Jul 25, 2023
1ebeeba
test(bulker-e2e): Fix repay values in Bulker tests
ghivert Jul 25, 2023
551f1c6
test(bulker-e2e): Fix supplies, withdraw and repay
ghivert Jul 25, 2023
101ab99
fix(bulker): Increase gasLimit on bulker execute tx
ghivert Jul 26, 2023
ecf82b6
refactor(bn): use constant for approx equal threshold
ghivert Jul 27, 2023
558488d
refactor(signer): remove signer in favor of Bulker.sign
ghivert Jul 27, 2023
c0a20bc
refactor(Bulker): remove getMessage
ghivert Jul 27, 2023
895ac69
refactor(bulker-e2e): rename approve and simplify mechanism
ghivert Jul 27, 2023
dc470ea
fix(bulker-e2e): fix morphoAdapter refreshAll with delay
ghivert Jul 27, 2023
4c178da
refactor(bulker-e2e): improve error messages in expect
ghivert Jul 27, 2023
b7f33fd
refactor(bulker-e2e): add some delay after refreshing all data in ada…
ghivert Jul 27, 2023
ce0b3d6
test(bulker-e2e): properly test repay
ghivert Jul 27, 2023
e79b064
refactor(bulker-e2e): improve test suite names
ghivert Jul 27, 2023
49ffea4
refactor(bulker-e2e): rebase on main
ghivert Jul 27, 2023
10bedc2
fix(TxHandler): fix forget of default type interface
ghivert Aug 8, 2023
9016a89
fix(BN): refactor parameters name
ghivert Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config: HardhatUserConfig = {
chainId: 1,
forking: {
url: rpcUrl,
blockNumber: 17413610,
blockNumber: 17514213,
enabled: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@gnosis.pm/safe-apps-sdk": "^7.8.0",
"@morpho-labs/ethers-utils": "^1.2.0",
"@morpho-labs/gnosis-tx-builder": "^1.3.1",
"@morpho-labs/morpho-ethers-contract": "^1.19.0",
"@morpho-labs/morpho-ethers-contract": "^1.20.0",
"ethers": "^5.7.2",
"ethers-multicall-provider": "^3.0.3",
"rxjs": "^7.8.1"
Expand Down
1 change: 1 addition & 0 deletions src/mocks/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const Underlying = {
dai: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
wbtc: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
wsteth: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0",
steth: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
uni: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
usdt: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
Expand Down
43 changes: 28 additions & 15 deletions src/txHandler/Bulker.TxHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import {
} from "ethers/lib/utils";
import { BehaviorSubject, Subject } from "rxjs";

import { WadRayMath } from "@morpho-labs/ethers-utils/lib/maths";
import { PercentMath, WadRayMath } from "@morpho-labs/ethers-utils/lib/maths";
import { maxBN } from "@morpho-labs/ethers-utils/lib/utils";
import { MorphoBulkerGateway__factory } from "@morpho-labs/morpho-ethers-contract";

import sdk from "..";
import { MorphoAaveV3Adapter } from "../MorphoAaveV3Adapter";
import { MorphoAaveV3DataHolder } from "../MorphoAaveV3DataHolder";
import { MAX_UINT_160 } from "../constants";
import addresses from "../contracts/addresses";
import { safeSignTypedData } from "../helpers/signatures";
import { Underlying } from "../mocks/markets";
Expand Down Expand Up @@ -52,22 +53,23 @@ type FullfillableSignature<Fullfilled extends boolean = boolean> =
? { deadline: BigNumber; signature: Signature }
: undefined;

export interface BulkerTransferSignature<Fullfilled extends boolean = boolean> {
interface BaseBulkerSignature<Fullfilled extends boolean = boolean> {
signature: FullfillableSignature<Fullfilled>;
transactionIndex: number;
nonce: BigNumber;
}
export interface BulkerTransferSignature<Fullfilled extends boolean = boolean>
extends BaseBulkerSignature<Fullfilled> {
type: BulkerSignatureType.transfer;
underlyingAddress: Address;
amount: BigNumber;
to: Address;
nonce: BigNumber;
signature: FullfillableSignature<Fullfilled>;
transactionIndex: number;
}

export interface BulkerApprovalSignature<Fullfilled extends boolean = boolean> {
export interface BulkerApprovalSignature<Fullfilled extends boolean = boolean>
extends BaseBulkerSignature<Fullfilled> {
type: BulkerSignatureType.managerApproval;
manager: Address;
nonce: BigNumber;
signature: FullfillableSignature<Fullfilled>;
transactionIndex: number;
}

export type BulkerSignature<Fullfilled extends boolean = boolean> =
Expand Down Expand Up @@ -315,12 +317,16 @@ export default class BulkerTxHandler

async executeBatch(options?: BulkerTransactionOptions): Promise<any> {
const signer = this._signer;
if (!signer) return;
if (!signer) throw Error(`No signer provided`);

const bulkerTransactions = this.bulkerOperations$.getValue();
const operations = this.simulatorOperations$.getValue();

if (bulkerTransactions.length === 0) return;
if (bulkerTransactions.length === 0)
throw Error(`No transactions to execute`);

if (this.error$.getValue())
throw Error(`Error in the batch, cannot execute`);

if (operations.length === 1) {
if (
Expand Down Expand Up @@ -574,10 +580,8 @@ export default class BulkerTxHandler
});
});

if (missingSignatures.length > 0) {
console.error(`Missing signatures: ${JSON.stringify(missingSignatures)}`);
return;
}
if (missingSignatures.length > 0)
throw new Error(`missing ${missingSignatures.length} signatures`);

let success: boolean;
let receipt: ContractReceipt | undefined;
Expand All @@ -588,8 +592,17 @@ export default class BulkerTxHandler
signer
);

const gasLimit = await bulker.estimateGas.execute(actions, data, {
...options?.overrides,
value,
});

const resp = await bulker.execute(actions, data, {
...options?.overrides,
gasLimit: PercentMath.percentMul(
gasLimit,
sdk.configuration.gasLimitPercent
),
value,
});

Expand Down
Loading