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

🧑‍🏭 Bring all CRT transactions into worker #4859

Merged
merged 5 commits into from
Sep 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions packages/atlas/src/joystream-lib/extrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
RawMetadataProcessorFn,
SendExtrinsicResult,
StringifiedNumber,
TokenId,
TxMethodName,
VideoExtrinsicResult,
VideoId,
Expand Down Expand Up @@ -975,4 +976,181 @@ export class JoystreamLibExtrinsics {
const tx = await this.reactToVideoCommentTx(memberId, commentId, reactionId)
return this.sendMetaprotocolExtrinsic(tx, cb)
}

purchaseTokenOnSaleTx = async (tokenId: TokenId, memberId: MemberId, amount: StringifiedNumber) => {
return this.api.tx.projectToken.purchaseTokensOnSale(
parseInt(tokenId),
parseInt(memberId),
createType('u128', new BN(amount))
)
}

purchaseTokenOnSale: PublicExtrinsic<typeof this.purchaseTokenOnSaleTx, ExtrinsicResult> = async (
tokenId,
memberId,
amount,
cb
) => {
const tx = await this.purchaseTokenOnSaleTx(tokenId, memberId, amount)
const { block } = await this.sendExtrinsic(tx, cb)

return { block }
}

dustAccountTx = async (tokenId: TokenId, memberId: MemberId) => {
return this.api.tx.projectToken.dustAccount(parseInt(tokenId), parseInt(memberId))
}

dustAccount: PublicExtrinsic<typeof this.dustAccountTx, ExtrinsicResult> = async (tokenId, memberId, cb) => {
const tx = await this.dustAccountTx(tokenId, memberId)
const { block } = await this.sendExtrinsic(tx, cb)
return { block }
}

exitRevenueSplitTx = async (tokenId: TokenId, memberId: MemberId) => {
return this.api.tx.projectToken.exitRevenueSplit(parseInt(tokenId), parseInt(memberId))
}

exitRevenueSplit: PublicExtrinsic<typeof this.exitRevenueSplitTx, ExtrinsicResult> = async (
tokenId,
memberId,
cb
) => {
const tx = await this.exitRevenueSplitTx(tokenId, memberId)
const { block } = await this.sendExtrinsic(tx, cb)
return { block }
}

participateInSplitTx = async (tokenId: TokenId, memberId: MemberId, amount: StringifiedNumber) => {
return this.api.tx.projectToken.participateInSplit(
parseInt(tokenId),
parseInt(memberId),
createType('u128', new BN(amount))
)
}

participateInSplit: PublicExtrinsic<typeof this.participateInSplitTx, ExtrinsicResult> = async (
tokenId,
memberId,
amount,
cb
) => {
const tx = await this.participateInSplitTx(tokenId, memberId, amount)
const { block } = await this.sendExtrinsic(tx, cb)

return { block }
}

issueRevenueSplitTx = async (
memberId: MemberId,
channelId: ChannelId,
start: StringifiedNumber,
duration: number
) => {
const member = createType('PalletContentPermissionsContentActor', { Member: parseInt(memberId) })
return this.api.tx.content.issueRevenueSplit(
member,
parseInt(channelId),
createType('Option<u32>', new BN(start)),
createType('u32', duration)
)
}

issueRevenueSplit: PublicExtrinsic<typeof this.issueRevenueSplitTx, ExtrinsicResult> = async (
memberId,
channelId,
start,
duration,
cb
) => {
const tx = await this.issueRevenueSplitTx(memberId, channelId, start, duration)
const { block } = await this.sendExtrinsic(tx, cb)
return { block }
}

finalizeRevenueSplitTx = async (memberId: MemberId, channelId: ChannelId) => {
const member = createType('PalletContentPermissionsContentActor', { Member: parseInt(memberId) })
return this.api.tx.content.finalizeRevenueSplit(member, parseInt(channelId))
}

finalizeRevenueSplit: PublicExtrinsic<typeof this.finalizeRevenueSplitTx, ExtrinsicResult> = async (
memberId,
channelId,
cb
) => {
const tx = await this.finalizeRevenueSplitTx(memberId, channelId)
const { block } = await this.sendExtrinsic(tx, cb)

return { block }
}

deissueCreatorTokenTx = async (memberId: MemberId, channelId: ChannelId) => {
const member = createType('PalletContentPermissionsContentActor', { Member: parseInt(memberId) })
return this.api.tx.content.deissueCreatorToken(member, parseInt(channelId))
}

deissueCreatorToken: PublicExtrinsic<typeof this.deissueCreatorTokenTx, ExtrinsicResult> = async (
memberId,
channelId,
cb
) => {
const tx = await this.deissueCreatorTokenTx(memberId, channelId)
const { block } = await this.sendExtrinsic(tx, cb)
return { block }
}

issueCreatorTokenTx = async (
memberId: MemberId,
channelId: ChannelId,
symbol: string,
patronageRate: number,
initialCreatorAllocation: {
amount: StringifiedNumber
vestingDuration: number
blocksBeforeCliff: number
cliffAmountPercentage: number
},
revenueSplitRate: number
) => {
const member = createType('PalletContentPermissionsContentActor', { Member: parseInt(memberId) })
const params = createType('PalletProjectTokenTokenIssuanceParameters', {
initialAllocation: createType('BTreeMap<u64, PalletProjectTokenTokenAllocation>', {
[parseInt(memberId)]: createType('PalletProjectTokenTokenAllocation', {
amount: createType('u128', new BN(initialCreatorAllocation.amount)),
vestingScheduleParams: createType('Option<PalletProjectTokenVestingScheduleParams>', {
blocksBeforeCliff: createType('u32', new BN(initialCreatorAllocation.blocksBeforeCliff)),
linearVestingDuration: createType('u32', new BN(initialCreatorAllocation.vestingDuration)),
cliffAmountPercentage: initialCreatorAllocation.cliffAmountPercentage,
}),
}),
}),
symbol,
patronageRate,
revenueSplitRate,
transferPolicy: createType('PalletProjectTokenTransferPolicyParams', { Permissionless: null }),
})
return this.api.tx.content.issueCreatorToken(member, parseInt(channelId), params)
}

issueCreatorToken: PublicExtrinsic<typeof this.issueCreatorTokenTx, ExtrinsicResult> = async (
memberId,
channelId,
symbol,
patronageRate,
initialCreatorAllocation,
revenueSplitRate,
cb
) => {
const tx = await this.issueCreatorTokenTx(
memberId,
channelId,
symbol,
patronageRate,
initialCreatorAllocation,
revenueSplitRate
)
const { block } = await this.sendExtrinsic(tx, cb)

return { block }
}
}
1 change: 1 addition & 0 deletions packages/atlas/src/joystream-lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type MemberId = string
export type ChannelId = string
export type VideoId = string
export type CategoryId = string
export type TokenId = string

export type AccountBalanceInfo = {
// transferable balance account
Expand Down