Skip to content

Commit

Permalink
Add amm transactions to the worker
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Oct 3, 2023
1 parent 272ec1b commit 4e2417d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/atlas/src/joystream-lib/extrinsics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,4 +1155,47 @@ export class JoystreamLibExtrinsics {

return { block }
}

purchaseTokenOnMarketTx = async (tokenId: string, memberId: string, amount: string) => {
const amountCast = createType('u128', new BN(amount))

return this.api.tx.projectToken.buyOnAmm(
parseInt(tokenId),
parseInt(memberId),
amountCast,
createType('Option<ITuple<[Permill, u128]>>', [createType('Permill', new BN(0.5)), amountCast]) // percent, number of joy user wants to pay --- default on 0.5%
)
}

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

sellTokenOnMarketTx = async (tokenId: string, memberId: string, amount: string) => {
const amountCast = createType('u128', new BN(amount))
return this.api.tx.projectToken.sellOnAmm(
parseInt(tokenId),
parseInt(memberId),
amountCast,
createType('Option<ITuple<[Permill, u128]>>', [createType('Permill', new BN(0.5)), amountCast]) // percent, number of joy user wants to pay --- default on 0.5%
)
}

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

0 comments on commit 4e2417d

Please sign in to comment.