Skip to content

Commit

Permalink
refcator(foundation): remove old 1155 due to conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmackz committed Jun 11, 2024
1 parent ce49898 commit b7ef504
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 160 deletions.
69 changes: 5 additions & 64 deletions packages/foundation/src/Foundation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,6 @@ describe('Given the foundation plugin', () => {
// expect(projectFee).equals(parseEther('0.0008'))
})

test('should return the correct fee for erc1155 mint', async () => {
const contractAddress: Address =
'0xddcbe62d10dbee8492610fd1b4964403a0e087aa'
const mintParams = {
contractAddress,
chainId: Chains.BASE,
tokenId: 28885,
}

// mock
const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: parseEther('0'),
actionFee: parseEther('0.0008'),
}),
}
const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getFeesSpy).toHaveBeenCalledWith(mintParams)
expect(fee.projectFee).toEqual(parseEther('0'))
expect(fee.actionFee).toEqual(parseEther('0.0008'))

// const { actionFee, projectFee } = await getFees(mintParams)
// expect(actionFee).equals(parseEther('0'))
// expect(projectFee).equals(parseEther('0.0008'))
})

test('should return the correct fee for erc1155 OE mint', async () => {
const contractAddress: Address =
'0x1d2550d198197df1a10af515cf2ea0d790889b93'
Expand Down Expand Up @@ -274,38 +247,6 @@ describe('Given the foundation plugin', () => {
data: '0x16da98640000000000000000000000006a41fcce9d075a9f6324b626af56cf632c509ec900000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890',
})
})

test('returns a TransactionRequest with correct properties for 1155 mint', async () => {
const CONTRACT_ADDRESS = '0xddcbe62d10dbee8492610fd1b4964403a0e087aa'
const RECIPIENT_ADDRESS = '0x1234567890123456789012345678901234567890'
const mint: MintIntentParams = {
chainId: 8453,
contractAddress: CONTRACT_ADDRESS,
amount: 1n,
recipient: RECIPIENT_ADDRESS,
tokenId: 28885,
}

// mock
const mockFns = {
getMintIntent: async (mint: MintIntentParams) => ({
from: mint.recipient,
to: mint.contractAddress,
data: '0x337fae59000000000000000000000000000000000000000000000000000000000000016e00000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b48',
}),
}
const getMintIntentSpy = vi.spyOn(mockFns, 'getMintIntent')
const result = await mockFns.getMintIntent(mint)
expect(getMintIntentSpy).toHaveBeenCalledWith(mint)

// const result = await getMintIntent(mint)

expect(result).toEqual({
from: '0x1234567890123456789012345678901234567890',
to: '0xddcbe62d10dbee8492610fd1b4964403a0e087aa',
data: '0x337fae59000000000000000000000000000000000000000000000000000000000000016e00000000000000000000000000000000000000000000000000000000000000010000000000000000000000001234567890123456789012345678901234567890000000000000000000000000e3bba2a4f8e0f5c32ef5097f988a4d88075c8b48',
})
})
})

describe('simulateMint function', () => {
Expand Down Expand Up @@ -420,11 +361,11 @@ describe('Given the foundation plugin', () => {
// ).rejects.toThrow()
})

test('should simulate a mint with an 1155 mint', async () => {
test('should simulate a mint with an 1155 OE mint', async () => {
const mint = {
chainId: Chains.BASE,
contractAddress: '0xddcbe62d10dbee8492610fd1b4964403a0e087aa',
tokenId: 28885,
contractAddress: '0x1d2550d198197df1a10af515cf2ea0d790889b93',
tokenId: 213,
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
}
const value = parseEther('0.0008')
Expand Down Expand Up @@ -457,8 +398,8 @@ describe('Given the foundation plugin', () => {
// )

const request = result.request
expect(request.address).toBe('0x132363a3bbf47e06cf642dd18e9173e364546c99')
expect(request.functionName).toBe('mintFromFixedPriceSale')
expect(request.address).toBe('0xfee588791cda1d01ccfc80b51efa00c0be5b129e')
expect(request.functionName).toBe('mintMultiTokensFromFreeFixedPriceSale')
expect(request.value).toBe(value)
})
})
Expand Down
60 changes: 21 additions & 39 deletions packages/foundation/src/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
CHAIN_TO_CONTRACT_ADDRESS,
DUTCH_AUCTION_FRAGMENT,
FIXED_PRICE_FRAGMENTS,
MINT_FROM_1155,
MINT_MULTI_TOKEN,
NFT_MARKET_BASE,
REFERRAL_ADDRESS,
Expand Down Expand Up @@ -49,18 +48,11 @@ export const mint = async (
// 721
const dropFactoryAddress = CHAIN_TO_CONTRACT_ADDRESS[chainId]

// 1155
const multiTokenAddress = CHAIN_TO_CONTRACT_1155[chainId]
const saleTermsId = await getSaleTermsId(mint, multiTokenAddress)

if (!dropFactoryAddress || !multiTokenAddress) {
if (!dropFactoryAddress) {
throw new Error('Invalid chainId')
}

const contracts = [
dropFactoryAddress.toLowerCase(),
multiTokenAddress.toLowerCase(),
]
const contracts = [dropFactoryAddress.toLowerCase()]

if (chainId === Chains.BASE) {
contracts.push(NFT_MARKET_BASE.toLowerCase())
Expand All @@ -80,13 +72,6 @@ export const mint = async (
nftContract: contractAddress,
nftRecipient: recipient,
},
{
// 1155
$abi: [MINT_FROM_1155],
tokenRecipient: recipient,
tokenQuantity: formatAmount(amount),
saleTermsId,
},
{
// 1155 NFTMarketRouter
$abi: [MINT_MULTI_TOKEN],
Expand Down Expand Up @@ -167,9 +152,7 @@ export const getFees = async (
saleTerms.protocolFeePerQuantity) *
quantityToMint
return { actionFee, projectFee }
} catch (err) {
console.error(err)
}
} catch {}
}
// return fallback if any errors occur
return {
Expand Down Expand Up @@ -256,12 +239,16 @@ export const getMintIntent = async (
if (salesTermId == null) {
throw new Error('Sale terms ID not found')
}

const mintArgs = [salesTermId, mintAmount, recipient, REFERRAL_ADDRESS]
const mintArgs = [
contractAddress,
[{ tokenId, quantity: 1n }],
recipient,
REFERRAL_ADDRESS,
]

const data = encodeFunctionData({
abi: [MINT_FROM_1155],
functionName: 'mintFromFixedPriceSale',
abi: [MINT_MULTI_TOKEN],
functionName: 'mintMultiTokensFromFreeFixedPriceSale',
args: mintArgs,
})

Expand Down Expand Up @@ -341,27 +328,22 @@ export const simulateMint = async (
}

if (contractType === '1155') {
if (tokenId == null) {
throw new Error('Token ID is required for 1155 Mints')
}
const multiTokenAddress = CHAIN_TO_CONTRACT_1155[chainId]
const salesTermId = await getSaleTermsId(mint, multiTokenAddress)

if (salesTermId == null) {
throw new Error('Sale terms ID not found')
}

// try NFTMarket contract first
const result = await _client.simulateContract({
address: multiTokenAddress,
address: NFT_MARKET_BASE,
value,
abi: [MINT_FROM_1155],
functionName: 'mintFromFixedPriceSale',
args: [salesTermId, mintAmount, recipient, REFERRAL_ADDRESS],
abi: [MINT_MULTI_TOKEN],
functionName: 'mintMultiTokensFromFreeFixedPriceSale',
args: [
contractAddress,
[[tokenId ?? 1, mintAmount]],
recipient,
REFERRAL_ADDRESS,
],
account: account || DEFAULT_ACCOUNT,
})
return result
}

throw new Error('Invalid contract type')
}

Expand Down
46 changes: 9 additions & 37 deletions packages/foundation/src/mockvalues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,49 +109,21 @@ export const dutchAuctionResponse = {
}

export const mint1155Response = {
result: undefined,
request: {
abi: [
{
inputs: [
{
internalType: 'uint256',
name: 'saleTermsId',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'tokenQuantity',
type: 'uint256',
},
{
internalType: 'address',
name: 'tokenRecipient',
type: 'address',
},
{
internalType: 'address payable',
name: 'referrer',
type: 'address',
},
],
name: 'mintFromFixedPriceSale',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
],
address: '0x132363a3bbf47e06cf642dd18e9173e364546c99',
address: '0xfee588791cda1d01ccfc80b51efa00c0be5b129e',
args: [
'366',
'1',
'0x1d2550d198197df1a10af515cf2ea0d790889b93',
[Array],
'0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
'0xe3bBA2A4F8E0F5C32EF5097F988a4d88075C8B48',
],
functionName: 'mintFromFixedPriceSale',
dataSuffix: undefined,
functionName: 'mintMultiTokensFromFreeFixedPriceSale',
value: 800000000000000n,
account: {
address: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
type: 'json-rpc',
},
},
type: 'json-rpc'
}
}
}
20 changes: 0 additions & 20 deletions packages/foundation/src/test-transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,6 @@ const MINT_DUTCH_AUCTION: TestParams<MintActionParams> = {
},
}

const MINT_1155: TestParams<MintActionParams> = {
transaction: {
chainId: 8453,
from: '0x0f9b1b68f848Cb65F532BC12825357201726d3d2',
hash: '0xeb0f6621f186b4bee412230ba53957a7a2c6fa03995085cbb37943b218cc00c9',
input:
'0x337fae59000000000000000000000000000000000000000000000000000000000000016e00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000f9b1b68f848cb65f532bc12825357201726d3d200000000000000000000000048ce37136c6050b39efac72725089a32cc3ad053',
to: '0x132363a3bbf47e06cf642dd18e9173e364546c99',
value: '800000000000001',
},
params: {
chainId: 8453,
contractAddress: '0xddcbe62d10dbee8492610fd1b4964403a0e087aa',
recipient: '0x0f9b1b68f848Cb65F532BC12825357201726d3d2',
tokenId: 28885,
amount: '1',
},
}

const MINT_OE_1155: TestParams<MintActionParams> = {
transaction: {
chainId: 8453,
Expand All @@ -101,7 +82,6 @@ export const passingTestCases = [
MINT_DUTCH_AUCTION,
'when when minting a drop using dutch auction',
),
createTestCase(MINT_1155, 'when when minting an 1155'),
createTestCase(MINT_OE_1155, 'when when minting an 1155 open edition'),
]

Expand Down

0 comments on commit b7ef504

Please sign in to comment.