Skip to content

Commit

Permalink
Merge pull request #93 from morpho-org/fix/mistakes-corrections
Browse files Browse the repository at this point in the history
Fix/mistakes corrections
  • Loading branch information
julien-devatom authored Aug 31, 2023
2 parents 3f4fc04 + 94ed6b6 commit 5c3f3c5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"rules": {
"node/no-missing-import": "off",
"node/no-unsupported-features/es-syntax": "off",
"node/shebang": "off"
"node/shebang": "off",
"no-console": "error"
}
}
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ jobs:
- name: Install dependencies
run: yarn --frozen-lockfile


- name: Load cache
uses: dawidd6/[email protected]
with:
name: hardhat-cache
path: cache
if_no_artifact_found: ignore

- name: Run e2e test suite
run: yarn test:e2e
env:
RPC_URL: ${{ secrets.RPC_URL }}

- name: Save cache
uses: actions/upload-artifact@v2
with:
name: hardhat-cache
path: cache
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const config: HardhatUserConfig = {
},
paths: {
tests: "./tests/e2e",
cache: "./cache",
},
mocha: {
timeout: 300000,
Expand Down
4 changes: 3 additions & 1 deletion src/simulation/MorphoAaveV3Simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class MorphoAaveV3Simulator extends MorphoAaveV3DataEmitter {
*
* @param parentAdapter adapter on which the simulator is based
* @param _timeout [Optional] Minimum delay between two refresh. Explicitly set to `O` to prevent it from refreshing
* @param _allowWrapping Whether or not the simulator will wrap native balances to increase user balance of wrapped tokens before a supply / repay operation.
*/
constructor(
parentAdapter: MorphoAaveV3DataEmitter,
Expand Down Expand Up @@ -412,6 +413,7 @@ export class MorphoAaveV3Simulator extends MorphoAaveV3DataEmitter {
marketConfig.supplyCap.gt(0) &&
poolLiquidity.gt(marketConfig.supplyCap)
) {
// throw as if all the supply was on pool to be more conservative and prevent the user to supply more than the cap (even if matched p2p)
return this._raiseError(index, ErrorCode.supplyCapReached, operation);
}

Expand Down Expand Up @@ -1258,7 +1260,7 @@ export class MorphoAaveV3Simulator extends MorphoAaveV3DataEmitter {
newMarketsData,
data.getMarketsList(),
data.getGlobalData(),
data.getUserData(),
newUserData,
newUserMarketsData
);
}
Expand Down
46 changes: 30 additions & 16 deletions src/txHandler/batch/BaseBatch.TxHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default abstract class BaseBatchTxHandler
}

/**
* Removes the last operation from the list of operations.
* @returns the index of the deleted operation, -1 if no operation was deleted
*/
public removeLastOperation(): number {
Expand All @@ -81,26 +82,31 @@ export default abstract class BaseBatchTxHandler
return nOperations - 1;
}

/**
* Converts a TxOperation to a Bulker.Transactions[].
* @param data The state after the operation has been applied.
* @param operation The operation to convert.
* @param index The index of the operation in the list of operations.
* @returns transactions The list of transactions to execute for the operation.
*/
protected abstract _operationToBatch(
data: MorphoAaveV3DataHolder,
operation: TxOperation,
index: number
): Bulker.Transactions[] | null;

_applyOperations({
operations,
data,
}: {
data: MorphoAaveV3DataHolder;
operations: Operation[];
}): void {
this.bulkerOperations$.setValue([]);
super._applyOperations({ operations, data });
this.#done$?.next(true);
}

/**
* Executes the batch of transactions.
*/
abstract executeBatch(options?: BulkerTransactionOptions): Promise<any>;

/**
* A hook that is called before each operation.
* @param data The state before the operation has been applied.
* @param operation The operation to apply.
* @param index The index of the operation in the list of operations.
* @returns state An intermediate state injected into the simulation of the operation.
*/
protected abstract _beforeOperation(
data: MorphoAaveV3DataHolder,
operation: TxOperation,
Expand All @@ -111,6 +117,18 @@ export default abstract class BaseBatchTxHandler
data: MorphoAaveV3DataHolder | null;
} | null;

_applyOperations({
operations,
data,
}: {
data: MorphoAaveV3DataHolder;
operations: Operation[];
}): void {
this.bulkerOperations$.setValue([]);
super._applyOperations({ operations, data });
this.#done$?.next(true);
}

protected _applySupplyOperation(
data: MorphoAaveV3DataHolder,
operation: TxOperation,
Expand Down Expand Up @@ -285,8 +303,6 @@ export default abstract class BaseBatchTxHandler
index: number,
_operations: Operation[]
): MorphoAaveV3DataHolder | null {
const underlyingAddress = getAddress(operation.underlyingAddress);

const batch: Bulker.Transactions[] = [];

const userMarketsData = data.getUserMarketsData();
Expand Down Expand Up @@ -337,8 +353,6 @@ export default abstract class BaseBatchTxHandler
index: number,
_operations: Operation[]
): MorphoAaveV3DataHolder | null {
const underlyingAddress = getAddress(operation.underlyingAddress);

const batch: Bulker.Transactions[] = [];

const userMarketsData = data.getUserMarketsData();
Expand Down
13 changes: 12 additions & 1 deletion src/txHandler/batch/Bulker.TxHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class BulkerTxHandler extends BaseBatchTxHandler {
return !!signature.signature;
}

autosign = false;
public autosign = false;

public readonly signatures$ = new BehaviorSubject<BulkerSignature[]>([]);

Expand Down Expand Up @@ -116,6 +116,7 @@ export default class BulkerTxHandler extends BaseBatchTxHandler {
const userData = this.getUserData();
const marketsConfig = this.getMarketsConfigs();
if (!userData) {
// eslint-disable-next-line no-console
console.error(`Missing user data`);
return;
}
Expand All @@ -135,6 +136,7 @@ export default class BulkerTxHandler extends BaseBatchTxHandler {
? { symbol: "stETH" }
: marketsConfig?.[toSign.underlyingAddress] ?? {};
if (!symbol) {
// eslint-disable-next-line no-console
console.error(`Missing market data`);
return;
}
Expand Down Expand Up @@ -513,6 +515,13 @@ export default class BulkerTxHandler extends BaseBatchTxHandler {
await notifier?.close?.(notificationId, success);
}

/**
* Adds Bulker specific operations (skim, manager approval, transferToBulker)
* @param data
* @param operation
* @param index
* @protected
*/
protected _beforeOperation(
data: MorphoAaveV3DataHolder,
operation: TxOperation,
Expand Down Expand Up @@ -645,8 +654,10 @@ export default class BulkerTxHandler extends BaseBatchTxHandler {
* And the non wrapped stEth balance
*
* If this is not enough, it will revert
* @param data
* @param underlyingAddress
* @param amount
* @param index
* @private
*/
#transferToBulker(
Expand Down
8 changes: 3 additions & 5 deletions src/txHandler/batch/Safe.TxHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ export default class SafeTxHandler extends BaseBatchTxHandler {
}
default: {
throw Error(`${operation.type} not implemented for a safe`);
break;
}
}
return {
to: contractAddress,
value: value,
value,
data,
};
});
Expand Down Expand Up @@ -253,9 +252,8 @@ export default class SafeTxHandler extends BaseBatchTxHandler {
let success: boolean;
try {
const batchFile = this.generateJSON(options);
console.debug(batchFile);
if ("errorCode" in batchFile) {
throw Error(batchFile.errorCode as string);
if (this.error$.value?.errorCode) {
throw Error(this.error$.value.errorCode);
}

const safeSdk = new SafeAppsSDK();
Expand Down

0 comments on commit 5c3f3c5

Please sign in to comment.