Skip to content

Commit

Permalink
fix(morpho-test): add node types
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Oct 11, 2024
1 parent 8d4d0fa commit 14400f3
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
89 changes: 89 additions & 0 deletions packages/bundler-sdk/test/populateBundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,95 @@ describe("populateBundle", () => {
).toBe(0n);
},
);

test[ChainId.EthMainnet](
"should borrow with already enough collateral",
async () => {
const id = MAINNET_MARKETS.usdc_wstEth.id;

Check failure on line 294 in packages/bundler-sdk/test/populateBundle.test.ts

View workflow job for this annotation

GitHub Actions / vitest

packages/bundler-sdk/test/populateBundle.test.ts > populateBundle > without signatures > ethereum > should borrow with already enough collateral

ReferenceError: MAINNET_MARKETS is not defined ❯ packages/bundler-sdk/test/populateBundle.test.ts:294:22
bundlerService.simulationService.metaMorphoService.addMarkets(id);

const blue = Morpho__factory.connect(morpho, signer);
const erc20 = ERC20__factory.connect(wstEth, signer);

const collateral = parseUnits("50");
const assets = parseUnits("13000", 6);
await deal(wstEth, signer.address, collateral);
await erc20.approve(morpho, MaxUint256);
await blue.supplyCollateral(
MAINNET_MARKETS.usdc_wstEth,
collateral,
signer.address,
"0x",
);
await mine();

const { operations, bundle } = await setupBundle(
bundlerService,
signer,
[
{
type: "Blue_Borrow",
sender: signer.address,
address: morpho,
args: {
id,
assets,
onBehalf: signer.address,
receiver: signer.address,
slippage: DEFAULT_SLIPPAGE_TOLERANCE,
},
},
],
);

expect(operations.length).to.equal(2);
expect(bundle.requirements.txs.length).to.equal(1);
expect(bundle.requirements.signatures.length).to.equal(0);

expect(bundle.requirements.txs[0]!.type).to.equal(
"morphoSetAuthorization",
);
expect(bundle.requirements.txs[0]!.args).to.eql([bundler, true]);

expect(operations[0]).to.eql({
type: "Blue_SetAuthorization",
sender: bundler,
address: morpho,
args: {
owner: signer.address,
isBundlerAuthorized: true,
},
});
expect(operations[1]).to.eql({
type: "Blue_Borrow",
sender: bundler,
address: morpho,
args: {
id,
assets,
onBehalf: signer.address,
receiver: signer.address,
slippage: DEFAULT_SLIPPAGE_TOLERANCE,
},
});

const market = await blue.market(id);
const position = await blue.position(id, signer.address);

expect(await erc20.balanceOf(signer.address)).to.equal(0);
expect(position.collateral).to.equal(collateral);
expect(position.supplyShares).to.equal(0);
expect(
MarketUtils.toBorrowAssets(position.borrowShares, market),
).to.equal(assets + 1n);

expect(await erc20.allowance(signer.address, permit2)).to.equal(0);
expect(await erc20.allowance(signer.address, bundler)).to.equal(0);
expect(
await erc20.allowance(signer.address, steakUsdc.address),
).to.equal(0);
},
);
});

describe("base", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/morpho-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@morpho-org/test": "workspace:^",
"@types/node": "^22.7.5",
"typescript": "^5.6.3",
"viem": "^2.21.18"
},
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,7 @@ __metadata:
"@morpho-org/blue-sdk": "workspace:^"
"@morpho-org/morpho-ts": "workspace:^"
"@morpho-org/test": "workspace:^"
"@types/node": "npm:^22.7.5"
typescript: "npm:^5.6.3"
viem: "npm:^2.21.18"
peerDependencies:
Expand Down Expand Up @@ -5087,6 +5088,15 @@ __metadata:
languageName: node
linkType: hard

"@types/node@npm:^22.7.5":
version: 22.7.5
resolution: "@types/node@npm:22.7.5"
dependencies:
undici-types: "npm:~6.19.2"
checksum: 10c0/cf11f74f1a26053ec58066616e3a8685b6bcd7259bc569738b8f752009f9f0f7f85a1b2d24908e5b0f752482d1e8b6babdf1fbb25758711ec7bb9500bfcd6e60
languageName: node
linkType: hard

"@types/normalize-package-data@npm:^2.4.1, @types/normalize-package-data@npm:^2.4.3":
version: 2.4.4
resolution: "@types/normalize-package-data@npm:2.4.4"
Expand Down

0 comments on commit 14400f3

Please sign in to comment.