forked from Uniswap/universal-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start * continue * continue * update snapshots * prettier * update snapshot * update narwhal-sdk to 1.0.0-beta.10 Co-authored-by: Alice Henshaw <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,769 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { RouterPlanner, FoundationCommand } from '@uniswap/narwhal-sdk' | ||
import FOUNDATION_ABI from './shared/abis/Foundation.json' | ||
import { Router, ERC721 } from '../../typechain' | ||
import { resetFork } from './shared/mainnetForkHelpers' | ||
import { | ||
ALICE_ADDRESS, | ||
DEADLINE, | ||
V2_FACTORY_MAINNET, | ||
V3_FACTORY_MAINNET, | ||
V2_INIT_CODE_HASH_MAINNET, | ||
V3_INIT_CODE_HASH_MAINNET, | ||
} from './shared/constants' | ||
import snapshotGasCost from '@uniswap/snapshot-gas-cost' | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' | ||
import hre from 'hardhat' | ||
import { BigNumber } from 'ethers' | ||
import { abi as ERC721_ABI } from '../../artifacts/solmate/src/tokens/ERC721.sol/ERC721.json' | ||
import { expect } from 'chai' | ||
const { ethers } = hre | ||
|
||
const FOUNDATION_INTERFACE = new ethers.utils.Interface(FOUNDATION_ABI) | ||
const MENTAL_WORLDS_ADDRESS = '0xEf96021Af16BD04918b0d87cE045d7984ad6c38c' | ||
const REFERRER = '0x459e213D8B5E79d706aB22b945e3aF983d51BC4C' | ||
|
||
describe('Foundation', () => { | ||
let alice: SignerWithAddress | ||
let router: Router | ||
let planner: RouterPlanner | ||
|
||
beforeEach(async () => { | ||
planner = new RouterPlanner() | ||
alice = await ethers.getSigner(ALICE_ADDRESS) | ||
}) | ||
|
||
// In this test we will buy token id 32 of mental worlds NFT (0xEf96021Af16BD04918b0d87cE045d7984ad6c38c), | ||
// which costs 0.01 ETH | ||
describe('Buy a mental worlds NFT from Foundation', () => { | ||
let mentalWorlds: ERC721 | ||
|
||
beforeEach(async () => { | ||
await resetFork(15725945) | ||
await hre.network.provider.request({ | ||
method: 'hardhat_impersonateAccount', | ||
params: [ALICE_ADDRESS], | ||
}) | ||
const routerFactory = await ethers.getContractFactory('Router') | ||
router = ( | ||
await routerFactory.deploy( | ||
ethers.constants.AddressZero, | ||
V2_FACTORY_MAINNET, | ||
V3_FACTORY_MAINNET, | ||
V2_INIT_CODE_HASH_MAINNET, | ||
V3_INIT_CODE_HASH_MAINNET | ||
) | ||
).connect(alice) as Router | ||
|
||
mentalWorlds = new ethers.Contract(MENTAL_WORLDS_ADDRESS, ERC721_ABI) as ERC721 | ||
}) | ||
|
||
it('purchases token id 32 of mental worlds', async () => { | ||
const value = BigNumber.from('10000000000000000') | ||
const calldata = FOUNDATION_INTERFACE.encodeFunctionData('buyV2', [MENTAL_WORLDS_ADDRESS, 32, value, REFERRER]) | ||
planner.add(FoundationCommand(value, calldata, ALICE_ADDRESS, MENTAL_WORLDS_ADDRESS, 32)) | ||
const { commands, state } = planner.plan() | ||
|
||
const aliceBalance = await ethers.provider.getBalance(alice.address) | ||
const referrerBalance = await ethers.provider.getBalance(REFERRER) | ||
const receipt = await (await router.execute(DEADLINE, commands, state, { value: value })).wait() | ||
|
||
// Expect that alice has the NFT | ||
await expect((await mentalWorlds.connect(alice).ownerOf(32)).toLowerCase()).to.eq(ALICE_ADDRESS) | ||
// Expect that alice's account has 0.01 (plus gas) less ETH in it | ||
await expect(aliceBalance.sub(await ethers.provider.getBalance(alice.address))).to.eq( | ||
value.add(receipt.gasUsed.mul(receipt.effectiveGasPrice)) | ||
) | ||
// Expect that referrer's account has 0.0001 more ETH in it (referrers receive 1% of NFT value) | ||
await expect((await ethers.provider.getBalance(REFERRER)).sub(referrerBalance)).to.eq(value.div(100)) | ||
}) | ||
|
||
it('gas token id 32 of mental worlds', async () => { | ||
const value = BigNumber.from('10000000000000000') | ||
const calldata = FOUNDATION_INTERFACE.encodeFunctionData('buyV2', [MENTAL_WORLDS_ADDRESS, 32, value, REFERRER]) | ||
planner.add(FoundationCommand(value, calldata, ALICE_ADDRESS, MENTAL_WORLDS_ADDRESS, 32)) | ||
const { commands, state } = planner.plan() | ||
await snapshotGasCost(router.execute(DEADLINE, commands, state, { value: value })) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Foundation Buy a mental worlds NFT from Foundation gas token id 32 of mental worlds 1`] = ` | ||
Object { | ||
"calldataByteLength": 836, | ||
"gasUsed": 187936, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Router bytecode size 1`] = `10058`; | ||
exports[`Router bytecode size 1`] = `10164`; |
Oops, something went wrong.