Skip to content

Commit

Permalink
Merge pull request #507 from rabbitholegg/matthew/boost-4415-update-z…
Browse files Browse the repository at this point in the history
…ora-sdk-getfees

feat(zora): update zora SDK and implement getFees
  • Loading branch information
Quazia authored Aug 13, 2024
2 parents 0017121 + 4a180fc commit 782c0b8
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 182 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-camels-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-zora": minor
---

update SDK and implement V2 getFees
2 changes: 1 addition & 1 deletion packages/zora/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@rabbitholegg/questdk-plugin-utils": "workspace:*"
},
"dependencies": {
"@zoralabs/protocol-sdk": "0.5.17",
"@zoralabs/protocol-sdk": "0.9.0",
"@zoralabs/universal-minter": "0.2.15",
"@rabbitholegg/questdk-plugin-utils": "workspace:*",
"@rabbitholegg/questdk": "workspace:*"
Expand Down
198 changes: 90 additions & 108 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
create,
getDynamicNameParams,
getExternalUrl,
getMintIntent,
mint,
simulateMint,
} from './Zora'
Expand All @@ -12,11 +11,7 @@ import {
passingTestCasesCreate,
passingTestCasesMint,
} from './test-setup'
import {
EXPECTED_ENCODED_DATA_721,
EXPECTED_ENCODED_DATA_1155,
MINT_V2_ZORA,
} from './test-transactions'
import { MINT_V2_ZORA } from './test-transactions'
import {
ActionType,
Chains,
Expand Down Expand Up @@ -256,49 +251,6 @@ describe('Given the zora plugin', () => {
})
})

describe('Given the getMintIntent function', () => {
// Define the constant for the contract address
const CONTRACT_ADDRESS = '0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb'
const RECIPIENT_ADDRESS = '0x1234567890123456789012345678901234567890'

test('returns a TransactionRequest with correct properties when tokenId is set', async () => {
const mint: MintIntentParams = {
chainId: 1,
tokenId: 1, // not 0
contractAddress: CONTRACT_ADDRESS,
amount: BigInt('10'),
recipient: RECIPIENT_ADDRESS,
referral: ZORA_DEPLOYER_ADDRESS,
}

const result = await getMintIntent(mint)

expect(result).toEqual({
from: mint.recipient,
to: mint.contractAddress,
data: EXPECTED_ENCODED_DATA_1155,
})
})

test('returns a TransactionRequest with correct properties when tokenId is null', async () => {
const mint: MintIntentParams = {
chainId: 1,
contractAddress: CONTRACT_ADDRESS,
amount: BigInt('10'),
recipient: RECIPIENT_ADDRESS,
referral: ZORA_DEPLOYER_ADDRESS,
}

const result = await getMintIntent(mint)

expect(result).toEqual({
from: mint.recipient,
to: mint.contractAddress,
data: EXPECTED_ENCODED_DATA_721,
})
})
})

describe('Given the getProjectFee function', () => {
test('should return the correct fee for a 721 mint', async () => {
const contractAddress: Address =
Expand Down Expand Up @@ -340,47 +292,97 @@ describe('Given the getProjectFee function', () => {
})

describe('Given the getFee function', () => {
test('should return the correct project + action fee for a 721 mint', async () => {
test('should return the correct project + action fee for an V2 1155 mint', async () => {
const contractAddress: Address =
'0x4f86113fc3e9783cf3ec9a552cbb566716a57628'
const mintParams = { contractAddress, chainId: Chains.ZORA }
'0xd900147e2d9dd35089cd80fb77fd3de0a08d3288'
const tokenId = 2
const mintParams = {
contractAddress,
tokenId,
chainId: Chains.ZORA,
amount: 1,
}

const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: BigInt('777000000000000'),
actionFee: BigInt('0'),
projectFee: parseEther('0.000111'),
actionFee: parseEther('0'),
}),
}

const getProjectsFeeSpy = vi.spyOn(mockFns, 'getFees')
const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getProjectsFeeSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(BigInt('777000000000000'))
expect(fee.actionFee).equals(BigInt('0'))
expect(getFeesSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(parseEther('0.000111'))
expect(fee.actionFee).equals(parseEther('0'))
})

test('should return the correct project + action fee for an 1155 mint', async () => {
test('should return the correct project + action fee for an V1 1155 mint', async () => {
const contractAddress: Address =
'0x393c46fe7887697124a73f6028f39751aa1961a3'
const tokenId = 1
'0x2cf3b6dc0588b313fdc0605b4282ef26a247d173'
const tokenId = 87
const mintParams = {
contractAddress,
tokenId,
chainId: Chains.ZORA,
amount: 2,
amount: 1,
}

const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: parseEther('0.000777'),
actionFee: parseEther('0'),
}),
}

const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getFeesSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(parseEther('0.000777'))
expect(fee.actionFee).equals(parseEther('0'))
})

test('should return the correct project + action fee for (non-free) V1 1155 mint', async () => {
const contractAddress: Address =
'0x34ce43d58d0d4ecf2581f4eb6238178c77fb32d9'
const tokenId = 1
const mintParams = {
contractAddress,
tokenId,
chainId: Chains.OPTIMISM,
amount: 1,
}

const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: parseEther('0.000777'),
actionFee: parseEther('0.29'),
}),
}

const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getFeesSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(parseEther('0.000777'))
expect(fee.actionFee).equals(parseEther('0.29'))
})

test('should return the correct project + action fee for a 721 mint', async () => {
const contractAddress: Address =
'0x4f86113fc3e9783cf3ec9a552cbb566716a57628'
const mintParams = { contractAddress, chainId: Chains.ZORA }

const mockFns = {
getFees: async (_mint: MintActionParams) => ({
projectFee: BigInt('1554000000000000'),
projectFee: BigInt('777000000000000'),
actionFee: BigInt('0'),
}),
}

const getProjectsFeeSpy = vi.spyOn(mockFns, 'getFees')
const getFeesSpy = vi.spyOn(mockFns, 'getFees')
const fee = await mockFns.getFees(mintParams)
expect(getProjectsFeeSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(BigInt('1554000000000000'))
expect(getFeesSpy.mock.calls.length).toBe(1)
expect(fee.projectFee).equals(BigInt('777000000000000'))
expect(fee.actionFee).equals(BigInt('0'))
})
})
Expand Down Expand Up @@ -422,53 +424,46 @@ describe('simulateMint function', () => {
expect(request.value).toBe(value)
})

test('should simulate a 1155 mint on blast', async () => {
test('should return an error object if address is not a contract', async () => {
const mint: MintIntentParams = {
chainId: Chains.ARBITRUM_ONE,
contractAddress: '0x0fc434acc936c79ac1f8f44ed07c7da92ade8f94',
tokenId: 1,
amount: BigInt(1),
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
referral: ZORA_DEPLOYER_ADDRESS,
}
const value = parseEther('0.000777')
const account = '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF'
await expect(simulateMint(mint, value, account)).rejects.toThrow(
'None of the specified function selectors are present in the contract bytecode.',
)
})

test('should simulate a 1155 mint when tokenId using timed sale strategy', async () => {
const mockFn = {
simulateMint: async (
_mint: MintIntentParams,
_value: bigint,
_account: Address,
) => ({
request: {
address: '0x553f0a63858a9000212cdbd0c40cf7861b692dc0',
value: parseEther('0.000777'),
address: ZORA_TIMED_SALE_STRATEGY,
value: parseEther('0.000111'),
},
}),
}
vi.spyOn(mockFn, 'simulateMint')

const mint: MintIntentParams = {
chainId: Chains.BLAST,
contractAddress: '0x553f0a63858a9000212cdbd0c40cf7861b692dc0',
tokenId: 1,
amount: BigInt(1),
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
referral: ZORA_DEPLOYER_ADDRESS,
}
const value = parseEther('0.000777')
const mint = MINT_V2_ZORA.params as MintIntentParams
const value = parseEther('0.000111')
const account = '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF'

const result = await mockFn.simulateMint(mint, value, account)
const request = result.request
expect(request.address).toBe(mint.contractAddress)
expect(request.address).toBe(ZORA_TIMED_SALE_STRATEGY)
expect(request.value).toBe(value)
})

test('should return an error object if address is not a contract', async () => {
const mint: MintIntentParams = {
chainId: Chains.ARBITRUM_ONE,
contractAddress: '0x0fc434acc936c79ac1f8f44ed07c7da92ade8f94',
tokenId: 1,
amount: BigInt(1),
recipient: '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF',
referral: ZORA_DEPLOYER_ADDRESS,
}
const value = parseEther('0.000777')
const account = '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF'
await expect(simulateMint(mint, value, account)).rejects.toThrow(
'None of the specified function selectors are present in the contract bytecode.',
)
})
})

describe('getDynamicNameParams function', () => {
Expand Down Expand Up @@ -583,16 +578,3 @@ describe('getExternalUrl function', () => {
expect(result).toBe('https://zora.co/create')
})
})

describe('simulateMint function', () => {
test('should simulate a 1155 mint when tokenId is not 0', async () => {
const mint = MINT_V2_ZORA.params as MintIntentParams
const value = parseEther('0.000111')
const account = '0xf70da97812CB96acDF810712Aa562db8dfA3dbEF'

const result = await simulateMint(mint, value, account)
const request = result.request
expect(request.address).toBe(ZORA_TIMED_SALE_STRATEGY)
expect(request.value).toBe(value)
})
})
Loading

0 comments on commit 782c0b8

Please sign in to comment.