Skip to content

feat(foundation): add support for ERC1155 mints #445

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

Merged
merged 12 commits into from
Jun 11, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/fresh-lies-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-foundation": minor
---

add support for ERC1155 mints
86 changes: 82 additions & 4 deletions packages/foundation/src/Foundation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { mint } from './Foundation'
// import { getFees, getMintIntent, simulateMint } from './Foundation'
import { dutchAuctionResponse, fixedPriceResponse } from './mockvalues'
import {
dutchAuctionResponse,
fixedPriceResponse,
mint1155Response,
} from './mockvalues'
import { failingTestCases, passingTestCases } from './test-transactions'
import { apply } from '@rabbitholegg/questdk'
import {
Expand Down Expand Up @@ -44,7 +48,6 @@ describe('Given the foundation plugin', () => {
Object.hasOwnProperty.call(filter.input, prop),
),
).to.be.true
expect(filter.input).toHaveProperty('nftContract', contractAddress)
})
})

Expand All @@ -62,8 +65,14 @@ describe('Given the foundation plugin', () => {
failingTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await mint(params)
expect(apply(transaction, filter)).to.be.false
try {
const filter = await mint(params)
const result = apply(transaction, filter)
expect(result).toBe(false)
} catch (error) {
expect(error).toBeDefined()
expect(error).toBeInstanceOf(Error)
}
})
})
})
Expand Down Expand Up @@ -147,6 +156,33 @@ describe('Given the foundation plugin', () => {
// 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'
const mintParams = {
contractAddress,
chainId: Chains.BASE,
tokenId: 213,
}

// 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'))
})
})

describe('Given the getMintIntent function', () => {
Expand Down Expand Up @@ -324,5 +360,47 @@ describe('Given the foundation plugin', () => {
// simulateMint(mint as MintIntentParams, value, address),
// ).rejects.toThrow()
})

test('should simulate a mint with an 1155 OE mint', async () => {
const mint = {
chainId: Chains.BASE,
contractAddress: '0x1d2550d198197df1a10af515cf2ea0d790889b93',
tokenId: 213,
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
}
const value = parseEther('0.0008')
const address = mint.recipient as Address

// mock
const mockFns = {
simulateMint: async (
_mint: MintIntentParams,
_value: bigint,
_address: Address,
) => mint1155Response,
}
const simulateMintSpy = vi.spyOn(mockFns, 'simulateMint')
const result = await mockFns.simulateMint(
mint as MintIntentParams,
value,
address,
)
expect(simulateMintSpy).toHaveBeenCalledWith(
mint as MintIntentParams,
value,
address,
)

// const result = await simulateMint(
// mint as MintIntentParams,
// value,
// address,
// )

const request = result.request
expect(request.address).toBe('0xfee588791cda1d01ccfc80b51efa00c0be5b129e')
expect(request.functionName).toBe('mintMultiTokensFromFreeFixedPriceSale')
expect(request.value).toBe(value)
})
})
})
Loading
Loading