Skip to content
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

feat: add tips from newbieVilla #35

Merged
merged 1 commit into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/contract/abi/newbie-villa.ts
Expand Up @@ -133,6 +133,7 @@ export const newbieVilla = [
{ name: 'xsyncOperator_', type: 'address' },
{ name: 'token_', type: 'address' },
{ name: 'admin_', type: 'address' },
{ name: 'tips_', type: 'address' },
],
name: 'initialize',
outputs: [],
Expand Down Expand Up @@ -178,6 +179,29 @@ export const newbieVilla = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ name: 'fromCharacterId', type: 'uint256' },
{ name: 'toCharacterId', type: 'uint256' },
{ name: 'amount', type: 'uint256' },
],
name: 'tipCharacter',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ name: 'fromCharacterId', type: 'uint256' },
{ name: 'toCharacterId', type: 'uint256' },
{ name: 'toNoteId', type: 'uint256' },
{ name: 'amount', type: 'uint256' },
],
name: 'tipCharacterForNote',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{ name: '', type: 'address' },
Expand Down
52 changes: 51 additions & 1 deletion src/contract/subcontracts/tips.ts
@@ -1,6 +1,6 @@
import { type Address, encodeAbiParameters, isAddressEqual } from 'viem'
import { autoSwitchMainnet } from '../decorators'
import { type Entry, type Mira, type Tips } from '../abi'
import { type Entry, type Mira, type NewbieVilla, type Tips } from '../abi'
import {
type Numberish,
type ReadOverrides,
Expand Down Expand Up @@ -48,6 +48,56 @@ export class TipsContract {
}
}

@autoSwitchMainnet()
async tipCharacterFromNewbieVilla(
fromCharacterId: Numberish,
toCharacterId: Numberish,
amount: Numberish,
overrides: WriteOverrides<NewbieVilla, 'tipCharacter'> = {},
) {
const hash = await this.base.newbieVillaContract.write.tipCharacter(
[BigInt(fromCharacterId), BigInt(toCharacterId), BigInt(amount)],
overrides,
)

const receipt = await this.base.publicClient.waitForTransactionReceipt({
hash,
})

return {
data: undefined,
transactionHash: receipt.transactionHash,
}
}

@autoSwitchMainnet()
async tipCharacterForNoteFromNewbieVilla(
fromCharacterId: Numberish,
toCharacterId: Numberish,
toNoteId: Numberish,
amount: Numberish,
overrides: WriteOverrides<NewbieVilla, 'tipCharacterForNote'> = {},
) {
const hash = await this.base.newbieVillaContract.write.tipCharacterForNote(
[
BigInt(fromCharacterId),
BigInt(toCharacterId),
BigInt(toNoteId),
BigInt(amount),
],
overrides,
)

const receipt = await this.base.publicClient.waitForTransactionReceipt({
hash,
})

return {
data: undefined,
transactionHash: receipt.transactionHash,
}
}

/**
* This tips a character for a note with $MIRA token.
*
Expand Down