Skip to content

Commit

Permalink
feat: add tips from newbieVilla (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed May 8, 2023
1 parent d179921 commit f702779
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
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

0 comments on commit f702779

Please sign in to comment.