diff --git a/package.json b/package.json index f7caa09746..c5cd887d5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tatumio", - "version": "2.2.28", + "version": "2.2.29", "license": "MIT", "repository": "https://github.com/tatumio/tatum-js", "scripts": { diff --git a/packages/blockchain/tezos/src/lib/__tests__/tezos.e2e.blockchain.spec.ts b/packages/blockchain/tezos/src/lib/__tests__/tezos.e2e.blockchain.spec.ts index 28415d594b..493c572de6 100644 --- a/packages/blockchain/tezos/src/lib/__tests__/tezos.e2e.blockchain.spec.ts +++ b/packages/blockchain/tezos/src/lib/__tests__/tezos.e2e.blockchain.spec.ts @@ -1,7 +1,6 @@ import { TatumTezosSDK } from '../tezos.sdk' import { BurnTezosToken, - DeployTezosNft, MintTezosToken, Token, TransferTezosToken, @@ -26,14 +25,17 @@ describe.skip('TatumTezosSDK - blockchain', () => { const sdk = TatumTezosSDK() const tezosWeb = sdk.tezosWeb - const body: DeployTezosNft = { + const body = { privateKey, owner: addr1, - metadata: JSON.stringify({ name: 'contract name', symbol: 'TZ-gold' }), + metadata: JSON.stringify({ + name: 'contract name', + symbol: 'TZ-gold', + version: '1.26.0', + }), } const opHash = await sdk.nft({ tezosWeb }).deploy.tzip12(body, testnet) - console.log(opHash) }) @@ -42,24 +44,22 @@ describe.skip('TatumTezosSDK - blockchain', () => { const tezosWeb = sdk.tezosWeb const token: Token = { - id: '6', + id: '1', ipfs: 'ipfs://Qmcz7iquheYehi4rmA2v9ZWakxMJCJusC5K7Harz8WNdza', } const token2: Token = { - id: '7', + id: '2', ipfs: 'ipfs://QmS7W7vtC6f3kSPUUkapVtW5bAXQvtn2tDDBDiBH1R3g2h', } - const body: MintTezosToken = { contractAddress, - owner: addr1, + owner: addr2, nfts: [token, token2], privateKey, } const tx = await sdk.nft({ tezosWeb }).mintTzip12(body, testnet) - console.log(tx) }) @@ -70,14 +70,14 @@ describe.skip('TatumTezosSDK - blockchain', () => { const body: BurnTezosToken = { contractAddress, owner: addr1, - tokens: ['6'], - privateKey, + tokens: ['1'], + privateKey: privateKey, } const tx = await sdk.nft({ tezosWeb }).burnTzip12(body, testnet) - console.log(tx) }) + it('Should add an operator to a token on testnet', async () => { const sdk = TatumTezosSDK() const tezosWeb = sdk.tezosWeb @@ -100,16 +100,76 @@ describe.skip('TatumTezosSDK - blockchain', () => { const body: TransferTezosToken = { contractAddress, - from: addr1, + from: addr2, to: addr3, - tokenId: '7', + tokenId: '1', amount: '1', privateKey: privateKey2, } const tx = await sdk.nft({ tezosWeb }).transferTzip12(body, testnet) - console.log(tx) }) + + it('Should estimate contract origination on testnet', async () => { + const sdk = TatumTezosSDK() + const tezosWeb = sdk.tezosWeb + + const body = { + privateKey, + owner: addr1, + metadata: JSON.stringify({ + name: 'contract name', + symbol: 'TZ-gold', + version: '1.26.0', + }), + } + + const totalCost = await sdk.nft({ tezosWeb }).estimate.contractDeploy(body, testnet) + console.log(totalCost) + }) + + it('Should estimate a token mint on testnet', async () => { + const sdk = TatumTezosSDK() + const tezosWeb = sdk.tezosWeb + + const token: Token = { + id: '1', + ipfs: 'ipfs://Qmcz7iquheYehi4rmA2v9ZWakxMJCJusC5K7Harz8WNdza', + } + + const token2: Token = { + id: '2', + ipfs: 'ipfs://QmS7W7vtC6f3kSPUUkapVtW5bAXQvtn2tDDBDiBH1R3g2h', + } + + const body: MintTezosToken = { + contractAddress, + owner: addr1, + nfts: [token, token2], + privateKey, + } + + const totalCost = await sdk.nft({ tezosWeb }).estimate.tokenMint(body, testnet) + + console.log(totalCost) + }) + + it('Should estimate a token transfer on testnet', async () => { + const sdk = TatumTezosSDK() + const tezosWeb = sdk.tezosWeb + const body: TransferTezosToken = { + contractAddress, + from: addr2, + to: addr3, + tokenId: '1', + amount: '1', + privateKey: privateKey2, + } + + const totalCost = await sdk.nft({ tezosWeb }).estimate.tokenTransfer(body, testnet) + + console.log(totalCost) + }) }) }) diff --git a/packages/blockchain/tezos/src/lib/services/tezos.tzip.ts b/packages/blockchain/tezos/src/lib/services/tezos.tzip.ts index 717f6bfe92..5acbeab075 100644 --- a/packages/blockchain/tezos/src/lib/services/tezos.tzip.ts +++ b/packages/blockchain/tezos/src/lib/services/tezos.tzip.ts @@ -5,12 +5,11 @@ import { char2Bytes } from '@taquito/utils' import * as fa2 from '@oxheadalpha/fa2-interfaces' import { MichelsonMap } from '@taquito/taquito' -export type DeployTezosNft = { +export type DeployContractData = { privateKey: string owner: string metadata: string } - export type MintTezosToken = { privateKey: string contractAddress: string @@ -45,7 +44,11 @@ export type UpdateOperatorTezosToken = { operator: string } -const deployTzip12 = async (body: DeployTezosNft, tronWeb: ITezosWeb, provider?: string): Promise => { +const deployTzip12 = async ( + body: DeployContractData, + tronWeb: ITezosWeb, + provider?: string, +): Promise => { const client = tronWeb.getClient(provider) const { privateKey, owner, metadata } = body @@ -62,6 +65,7 @@ const deployTzip12 = async (body: DeployTezosNft, tronWeb: ITezosWeb, provider?: return hash } + const mintToken = async (body: MintTezosToken, tronWeb: ITezosWeb, provider?: string): Promise => { const { contractAddress, nfts, owner, privateKey } = body @@ -172,6 +176,94 @@ const updateOperator = async ( return opHash } +const estimateContractDeploy = async ( + body: DeployContractData, + tronWeb: ITezosWeb, + provider?: string, +): Promise => { + const client = tronWeb.getClient(provider) + const { privateKey, owner, metadata } = body + + const memorySigner = new InMemorySigner(privateKey) + + client.setSignerProvider(memorySigner) + + const storage = createStorage({ metadata, owner }) + + const { burnFeeMutez, suggestedFeeMutez } = await client.estimate.originate({ + code: Tezos_TZIP_12.michelson, + storage, + }) + + return burnFeeMutez + suggestedFeeMutez +} + +const estimateTokenMint = async ( + body: MintTezosToken, + tronWeb: ITezosWeb, + provider?: string, +): Promise => { + const { contractAddress, nfts, owner, privateKey } = body + + const client = tronWeb.getClient(provider) + const memorySigner = new InMemorySigner(privateKey) + + client.setSignerProvider(memorySigner) + + const contract = await client.contract.at(contractAddress) + const tokens = nfts.map(({ id, ipfs }) => { + const tokenInfoMap = new MichelsonMap() + + tokenInfoMap.set('', char2Bytes(ipfs)) + return { token_id: id, token_info: tokenInfoMap } + }) + + const mintParams = [ + { + owner, + tokens, + }, + ] + + const op = contract.methods.mint(mintParams) + + const { burnFeeMutez, suggestedFeeMutez } = await client.estimate.contractCall(op) + return burnFeeMutez + suggestedFeeMutez +} + +const estimateTransferToken = async ( + body: TransferTezosToken, + tronWeb: ITezosWeb, + provider?: string, +): Promise => { + const { contractAddress, privateKey, from, to, tokenId, amount } = body + + const client = tronWeb.getClient(provider) + const memorySigner = new InMemorySigner(privateKey) + + client.setSignerProvider(memorySigner) + + const contract = await client.contract.at(contractAddress) + + const transferParams = [ + { + from_: from, + txs: [ + { + to_: to, + token_id: tokenId, + amount: amount, + }, + ], + }, + ] + + const op = contract.methods.transfer(transferParams) + + const { burnFeeMutez, suggestedFeeMutez } = await client.estimate.contractCall(op) + return burnFeeMutez + suggestedFeeMutez +} + export const tezosTzip = (args: { tezosWeb: ITezosWeb }) => ({ deploy: { /** @@ -180,7 +272,16 @@ export const tezosTzip = (args: { tezosWeb: ITezosWeb }) => ({ * @param provider * @returns The hash (ID) of the transaction */ - tzip12: async (body: DeployTezosNft, provider?: string) => deployTzip12(body, args.tezosWeb, provider), + tzip12: async (body: DeployContractData, provider?: string) => + deployTzip12(body, args.tezosWeb, provider), + }, + estimate: { + contractDeploy: async (body: DeployContractData, provider?: string) => + estimateContractDeploy(body, args.tezosWeb, provider), + tokenMint: async (body: MintTezosToken, provider?: string) => + estimateTokenMint(body, args.tezosWeb, provider), + tokenTransfer: async (body: TransferTezosToken, provider?: string) => + estimateTransferToken(body, args.tezosWeb, provider), }, /** * Mint a new NFT collection