From b7bd213753224cf538a5720481af5b23ec2c5fcc Mon Sep 17 00:00:00 2001 From: WRadoslaw <92513933+WRadoslaw@users.noreply.github.com> Date: Thu, 14 Sep 2023 13:05:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=8F=AD=20Bring=20all?= =?UTF-8?q?=20CRT=20transactions=20into=20worker=20(#4859)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Purchase token on sale * Initial transactions * Add further tx * Add issue token transaction and correct few type casts * Remove lodash parseInt --- .../atlas/src/joystream-lib/extrinsics.ts | 178 ++++++++++++++++++ packages/atlas/src/joystream-lib/types.ts | 1 + 2 files changed, 179 insertions(+) diff --git a/packages/atlas/src/joystream-lib/extrinsics.ts b/packages/atlas/src/joystream-lib/extrinsics.ts index 4801574d18..5a1f08450b 100644 --- a/packages/atlas/src/joystream-lib/extrinsics.ts +++ b/packages/atlas/src/joystream-lib/extrinsics.ts @@ -55,6 +55,7 @@ import { RawMetadataProcessorFn, SendExtrinsicResult, StringifiedNumber, + TokenId, TxMethodName, VideoExtrinsicResult, VideoId, @@ -981,4 +982,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 = 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 = 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 = 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 = 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', new BN(start)), + createType('u32', duration) + ) + } + + issueRevenueSplit: PublicExtrinsic = 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 = 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 = 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', { + [parseInt(memberId)]: createType('PalletProjectTokenTokenAllocation', { + amount: createType('u128', new BN(initialCreatorAllocation.amount)), + vestingScheduleParams: createType('Option', { + 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 = 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 } + } } diff --git a/packages/atlas/src/joystream-lib/types.ts b/packages/atlas/src/joystream-lib/types.ts index 71bbfb48ae..95be3b2513 100644 --- a/packages/atlas/src/joystream-lib/types.ts +++ b/packages/atlas/src/joystream-lib/types.ts @@ -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