Skip to content

Commit

Permalink
Merge pull request #172 from rabbitholegg/veganbeef/treasure-mint-plugin
Browse files Browse the repository at this point in the history
feat(treasure): add mint plugin for TreasureTags
  • Loading branch information
veganbeef authored Jan 19, 2024
2 parents 09037b1 + daea0ce commit f20097f
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-trees-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk-plugin-treasure": minor
---

add mint support for TreasureTags
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ tsconfig*.tsbuildinfo
.env.test.local
.env.production.local
.envrc
~
~

.idea
62 changes: 54 additions & 8 deletions packages/treasure/src/Treasure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,65 @@ import { apply } from '@rabbitholegg/questdk/filter'
import { describe, expect, test } from 'vitest'
import { getAddress } from 'viem'
import { Chains } from './utils'
import { swap, getSupportedTokenAddresses } from './Treasure'
import { passingTestCases, failingTestCases } from './test-transactions'
import { V2_ROUTER_ABI } from './abi'
import { mint, swap, getSupportedTokenAddresses } from './Treasure'
import {
passingSwapTestCases,
failingSwapTestCases,
MINT_TREASURE_TAG,
passingMintTestCases,
failingMintTestCases,
} from './test-transactions'
import { MINT_TREASURE_TAG_ABI, V2_ROUTER_ABI } from './abi'
import { MAGIC, ANIMA, V2_ROUTER } from './constants'

describe('Given the tresure plugin', () => {
describe('Given the treasure plugin', () => {
describe('when handling the mint action', () => {
describe('should return a valid action filter', () => {
const { params } = MINT_TREASURE_TAG
test('when minting a Treasure Tag through the proxy contract', async () => {
const filter = await mint(params)
expect(filter).to.deep.equal({
chainId: Chains.ARBITRUM_ONE,
to: params.contractAddress,
input: {
$abi: MINT_TREASURE_TAG_ABI,
_registerArgs: {
owner: params.recipient,
},
},
})
})
})

describe('should pass filter with valid transactions', () => {
passingMintTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await mint(params)
const result = apply(transaction, filter)
expect(result).to.be.true
})
})
})

describe('should not pass filter with invalid transactions', () => {
failingMintTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await mint(params)
expect(apply(transaction, filter)).to.be.false
})
})
})
})

describe('When handling the swap action', () => {
describe('should return a valid action filter', () => {
test('when making a valid swap', async () => {
const { params } = passingTestCases[0]
const { params } = passingSwapTestCases[0]
const filter = await swap(params)
expect(filter).to.deep.equal({
chainId: 42161,
chainId: Chains.ARBITRUM_ONE,
to: V2_ROUTER,
input: {
$abi: V2_ROUTER_ABI,
Expand Down Expand Up @@ -59,7 +105,7 @@ describe('Given the tresure plugin', () => {
})

describe('should pass filter with valid transactions', () => {
passingTestCases.forEach((testCase) => {
passingSwapTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await swap(params)
Expand All @@ -69,7 +115,7 @@ describe('Given the tresure plugin', () => {
})

describe('should not pass filter with invalid transactions', () => {
failingTestCases.forEach((testCase) => {
failingSwapTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await swap(params)
Expand Down
21 changes: 20 additions & 1 deletion packages/treasure/src/Treasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@ import {
type TransactionFilter,
type SwapActionParams,
compressJson,
type MintActionParams,
} from '@rabbitholegg/questdk'
import { type Address } from 'viem'
import { MAGICSWAP_TOKENS, V2_ROUTER } from './constants'
import { V2_ROUTER_ABI } from './abi'
import { MINT_TREASURE_TAG_ABI, V2_ROUTER_ABI } from './abi'
import { Chains, buildV2PathQuery } from './utils'

export const mint = async (
mint: MintActionParams,
): Promise<TransactionFilter> => {
const { chainId, contractAddress, recipient } = mint

return compressJson({
chainId,
to: contractAddress,
input: {
$abi: MINT_TREASURE_TAG_ABI,
_registerArgs: {
owner: recipient,
},
},
})
}

export const swap = async (
swap: SwapActionParams,
): Promise<TransactionFilter> => {
Expand Down Expand Up @@ -41,6 +59,7 @@ export const swap = async (
},
})
}

export const getSupportedTokenAddresses = async (
_chainId: number,
): Promise<Address[]> => {
Expand Down
48 changes: 48 additions & 0 deletions packages/treasure/src/abi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
export const MINT_TREASURE_TAG_ABI = [
{
inputs: [
{
internalType: 'struct IMagicDomainRegistrarController.RegisterArgs',
name: '_registerArgs',
type: 'tuple',
components: [
{
internalType: 'string',
name: 'name',
type: 'string',
},
{
internalType: 'string',
name: 'discriminant',
type: 'string',
},
{
internalType: 'address',
name: 'owner',
type: 'address',
},
{
internalType: 'address',
name: 'resolver',
type: 'address',
},
{
internalType: 'uint96',
name: 'nonce',
type: 'uint96',
},
],
},
{
internalType: 'bytes',
name: '_authoritySignature',
type: 'bytes',
},
],
name: 'register',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
]

export const V2_ROUTER_ABI = [
{
inputs: [
Expand Down
3 changes: 3 additions & 0 deletions packages/treasure/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type Address } from 'viem'

// TreasureTags proxy contract
export const TREASURE_TAGS_PROXY = '0x072b65f891b1a389539e921bdb9427af41a7b1f7'

// Router Contract
export const V2_ROUTER = '0x23805449f91bb2d2054d9ba288fdc8f09b5eac79'

Expand Down
3 changes: 2 additions & 1 deletion packages/treasure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@rabbitholegg/questdk'

import {
mint,
swap,
getSupportedChainIds,
getSupportedTokenAddresses,
Expand All @@ -13,7 +14,7 @@ export const Treasure: IActionPlugin = {
pluginId: 'treasure',
getSupportedTokenAddresses,
getSupportedChainIds,
mint,
swap,
bridge: async () => new PluginActionNotImplementedError(),
mint: async () => new PluginActionNotImplementedError(),
}
40 changes: 37 additions & 3 deletions packages/treasure/src/test-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import {
type SwapActionParams,
GreaterThanOrEqual,
type MintActionParams,
} from '@rabbitholegg/questdk'
import { parseUnits } from 'viem'
import { ANIMA, GFLY, MAGIC } from './constants'
import { ANIMA, GFLY, MAGIC, TREASURE_TAGS_PROXY } from './constants'
import { type TestParams, Chains, createTestCase } from './utils'

export const MINT_TREASURE_TAG: TestParams<MintActionParams> = {
transaction: {
chainId: 42161,
from: '0x702c99051255ff9c621eddf5a752afef2f1ac14c',
hash: '0x375e98904e78bbdde0e59cf7bb0158aa2c63a4f321182f43ada05d4839837a2e',
input:
'0x95f38e770000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000702c99051255ff9c621eddf5a752afef2f1ac14c000000000000000000000000ecdff76f3d9e130f795a68e50cdde5a11ec5542c00000000000000000000000000000000000000000e8a81453c23f19faf749b06000000000000000000000000000000000000000000000000000000000000000a63616666656d6f63686100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000434323836000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041b86733784462d0b6a679d1bd498b1a62b8250e1db37af0690c031959052dee64478635e23cfd305d8c4878fe6b19e20b124dfc46c44499971a839e9bf56af7b31b00000000000000000000000000000000000000000000000000000000000000',
to: TREASURE_TAGS_PROXY,
value: '0',
},
params: {
chainId: Chains.ARBITRUM_ONE,
contractAddress: TREASURE_TAGS_PROXY,
recipient: '0x702c99051255ff9c621eddf5a752afef2f1ac14c',
},
}

export const EXACT_TOKENS_FOR_TOKENS: TestParams<SwapActionParams> = {
transaction: {
chainId: 42161,
Expand Down Expand Up @@ -46,7 +64,7 @@ export const TOKENS_FOR_EXACT_TOKENS: TestParams<SwapActionParams> = {
},
}

export const passingTestCases = [
export const passingSwapTestCases = [
createTestCase(
EXACT_TOKENS_FOR_TOKENS,
'when swapping exact tokens for tokens',
Expand All @@ -57,7 +75,11 @@ export const passingTestCases = [
),
]

export const failingTestCases = [
export const passingMintTestCases = [
createTestCase(MINT_TREASURE_TAG, 'when minting a TreasureTag'),
]

export const failingSwapTestCases = [
createTestCase(TOKENS_FOR_EXACT_TOKENS, 'when chainId is incorrect', {
chainId: 10,
}),
Expand Down Expand Up @@ -92,3 +114,15 @@ export const failingTestCases = [
recipient: '0x7a227272e5B583c2B51B04fF5cA4FDe498368b44',
}),
]

export const failingMintTestCases = [
createTestCase(MINT_TREASURE_TAG, 'when the chainId is incorrect', {
chainId: Chains.ETHEREUM,
}),
createTestCase(MINT_TREASURE_TAG, 'when the contractAddress is incorrect', {
contractAddress: MAGIC,
}),
createTestCase(MINT_TREASURE_TAG, 'when the recipient is incorrect', {
recipient: '0x0A4066534E21dF54331EDcb65A2F41151eD20912',
}),
]

0 comments on commit f20097f

Please sign in to comment.