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

feat: make types compatible with deno #223

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions packages/contracts/src/escrow/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
mConStr2,
} from '@meshsdk/mesh-csl';
import blueprint from './aiken-workspace/plutus.json';
import { Asset, UTxO, mergeAssets } from '@meshsdk/core';
import { Asset, Data, UTxO, mergeAssets } from '@meshsdk/core';

export type InitiationDatum = ConStr0<[PubKeyAddress, Value]>;
export const initiateEscrowDatum = (
Expand Down Expand Up @@ -71,7 +71,8 @@ export class MeshEscrowContract extends MeshTxInitiator {
await this.mesh
.txOut(scriptAddr, escrowAmount)
.txOutInlineDatumValue(
initiateEscrowDatum(walletAddress, escrowAmount),
// TODO: remove dodgy cast
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the only genuine code change within this PR (search for "This is the only code change within the PR.") exists only to deal with a strange default export issue, the fact that we're now having to perform some explicit casts potentially indicates that types weren't always being pulled through correctly even internally?

initiateEscrowDatum(walletAddress, escrowAmount) as unknown as Data,
'JSON'
)
.changeAddress(walletAddress)
Expand Down Expand Up @@ -169,7 +170,11 @@ export class MeshEscrowContract extends MeshTxInitiator {
)
.spendingReferenceTxInInlineDatumPresent()
.txInRedeemerValue(
recipientDepositRedeemer(walletAddress, depositAmount),
// TODO: remove dodgy cast
recipientDepositRedeemer(
walletAddress,
depositAmount
) as unknown as Data,
{
mem: 7_000_000,
steps: 3_000_000_000,
Expand All @@ -178,7 +183,8 @@ export class MeshEscrowContract extends MeshTxInitiator {
)
.txInScript(this.scriptCbor)
.txOut(scriptAddr, escrowAmount)
.txOutInlineDatumValue(outputDatum, 'JSON')
// TODO: remove dodgy cast
.txOutInlineDatumValue(outputDatum as unknown as Data, 'JSON')
.changeAddress(walletAddress)
.txInCollateral(
collateral.input.txHash,
Expand Down
7 changes: 5 additions & 2 deletions packages/contracts/src/marketplace/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@meshsdk/mesh-csl';
import blueprint from './aiken-workspace/plutus.json';
import {
Data,
Quantity,
UTxO,
Unit,
Expand Down Expand Up @@ -88,7 +89,8 @@ export class MeshMarketplaceContract extends MeshTxInitiator {

await this.mesh
.txOut(scriptAddr, tokenForSale)
.txOutInlineDatumValue(outputDatum, 'JSON')
// TODO: remove dodgy cast
.txOutInlineDatumValue(outputDatum as unknown as Data, 'JSON')
.changeAddress(walletAddress)
.selectUtxosFrom(selectedUtxos)
.complete();
Expand Down Expand Up @@ -225,7 +227,8 @@ export class MeshMarketplaceContract extends MeshTxInitiator {
.spendingReferenceTxInRedeemerValue(mConStr1([]))
.txInScript(this.scriptCbor)
.txOut(scriptAddr, tokenForSale)
.txOutInlineDatumValue(outputDatum, 'JSON')
// TODO: remove dodgy cast
.txOutInlineDatumValue(outputDatum as unknown as Data, 'JSON')
.changeAddress(walletAddress)
.requiredSignerHash(serializeBech32Address(walletAddress).pubKeyHash)
.txInCollateral(
Expand Down
10 changes: 7 additions & 3 deletions packages/contracts/src/payment-splitter/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
resolvePlutusScriptAddress,
resolvePaymentKeyHash,
Transaction,
PlutusScript,
Action,
} from '@meshsdk/core';
import {
serializeBech32Address,
Expand Down Expand Up @@ -49,7 +51,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {

const { walletAddress } = await this.getWalletInfoForTx();

const script = {
const script: PlutusScript = {
code: this.scriptCbor(),
version: 'V2',
};
Expand Down Expand Up @@ -83,7 +85,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {

const { walletAddress, collateral } = await this.getWalletInfoForTx();

const script = {
const script: PlutusScript = {
code: this.scriptCbor(),
version: 'V2',
};
Expand All @@ -96,7 +98,9 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator {
};

const redeemerData = 'Hello, World!';
const redeemer = { data: { alternative: 0, fields: [redeemerData] } };
const redeemer: Action = {
data: { alternative: 0, fields: [redeemerData] },
} as Action; // NOTE: cast needed as we're missing `index`, `budget` and `tag`

let tx = new Transaction({ initiator: this.wallet });
let split = 0;
Expand Down
52 changes: 33 additions & 19 deletions packages/module/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { csl } from '@mesh/core';
import type { Costmdls } from '@mesh/core';
import type { Budget, Era, Network, Protocol } from './types';
import { csl } from '../core/index.js';
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably could have achieved a basic level of Deno support (via CDNs which fix-up some ESM issues) just by no longer using the @mesh/* alias. The need for the .js suffixes is a result of setting moduleResolution to Node16, which additionally guarantees compatibility with Deno's built-in npm support, but which also ensures that support will continue to work in the future too.

import type { Costmdls } from '../core/index.js';
import type { Budget, Era, Network, Protocol } from './types/index.js';

export const DEFAULT_REDEEMER_BUDGET: Budget = {
mem: 7_000_000,
Expand Down Expand Up @@ -46,12 +46,10 @@ export const REDEEMER_TAGS = {
SPEND: csl.RedeemerTag.new_spend(),
};

export const SUPPORTED_CLOCKS: Record<Network, [
epoch: string,
slot: string,
systemStart: string,
epochLength: string,
]> = {
export const SUPPORTED_CLOCKS: Record<
Network,
[epoch: string, slot: string, systemStart: string, epochLength: string]
> = {
testnet: ['74', '1598400', '1595967616', '432000'],
preview: ['183', '15811222', '1682467200', '86400'],
preprod: ['65', '26438400', '1682121600', '432000'],
Expand Down Expand Up @@ -230,7 +228,7 @@ export const SUPPORTED_COST_MODELS: Record<Era, Costmdls> = {
'unMapData-memory-arguments': 32,
'verifyEd25519Signature-cpu-arguments-intercept': 57996947,
'verifyEd25519Signature-cpu-arguments-slope': 18975,
'verifyEd25519Signature-memory-arguments': 10
'verifyEd25519Signature-memory-arguments': 10,
}).forEach((cost, operation) =>
v1CostModel.set(operation, csl.Int.new_i32(cost))
);
Expand Down Expand Up @@ -411,7 +409,7 @@ export const SUPPORTED_COST_MODELS: Record<Era, Costmdls> = {
'verifyEd25519Signature-memory-arguments': 10,
'verifySchnorrSecp256k1Signature-cpu-arguments-intercept': 38887044,
'verifySchnorrSecp256k1Signature-cpu-arguments-slope': 32947,
'verifySchnorrSecp256k1Signature-memory-arguments': 10
'verifySchnorrSecp256k1Signature-memory-arguments': 10,
}).forEach((cost, operation) =>
v2CostModel.set(operation, csl.Int.new_i32(cost))
);
Expand All @@ -424,7 +422,8 @@ export const SUPPORTED_COST_MODELS: Record<Era, Costmdls> = {
};

export const SUPPORTED_LANGUAGE_VIEWS: Record<
Era, Partial<Record<keyof typeof LANGUAGE_VERSIONS, string>>
Era,
Partial<Record<keyof typeof LANGUAGE_VERSIONS, string>>
> = {
ALONZO: {
V1: 'a141005901d59f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f704001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff',
Expand All @@ -436,8 +435,10 @@ export const SUPPORTED_LANGUAGE_VIEWS: Record<
};

export const SUPPORTED_HANDLES: Record<number, string> = {
[csl.NetworkInfo.testnet().network_id()]: '8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3',
[csl.NetworkInfo.mainnet().network_id()]: 'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a',
[csl.NetworkInfo.testnet().network_id()]:
'8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3',
[csl.NetworkInfo.mainnet().network_id()]:
'f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a',
};

export const SUPPORTED_OGMIOS_LINKS: Record<Network, string> = {
Expand Down Expand Up @@ -467,17 +468,30 @@ export const SUPPORTED_TOKENS = {
HOSKY: 'a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235484f534b59',
YUMMI: '078eafce5cd7edafdf63900edef2c1ea759e77f30ca81d6bbdeec92479756d6d69',
C3: '8e51398904a5d3fc129fbf4f1589701de23c7824d5c90fdb9490e15a434841524c4933',
GIMBAL: '2b0a04a7b60132b1805b296c7fcb3b217ff14413991bf76f72663c3067696d62616c',
SUNDAE: '9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145',
GREENS: '4623ab311b7d982d8d26fcbe1a9439ca56661aafcdcd8d8a0ef31fd6475245454e53',
GIMBAL:
'2b0a04a7b60132b1805b296c7fcb3b217ff14413991bf76f72663c3067696d62616c',
SUNDAE:
'9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145',
GREENS:
'4623ab311b7d982d8d26fcbe1a9439ca56661aafcdcd8d8a0ef31fd6475245454e53',
GENS: 'dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb0014df1047454e53',
SOCIETY: '25f0fc240e91bd95dcdaebd2ba7713fc5168ac77234a3d79449fc20c534f4349455459',
SOCIETY:
'25f0fc240e91bd95dcdaebd2ba7713fc5168ac77234a3d79449fc20c534f4349455459',
DJED: '8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344',
SHEN: '8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd615368656e4d6963726f555344',
WMT: '1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e776f726c646d6f62696c65746f6b656e',
COPI: 'b6a7467ea1deb012808ef4e87b5ff371e85f7142d7b356a40d9b42a0436f726e75636f70696173205b76696120436861696e506f72742e696f5d',
};

export const SUPPORTED_WALLETS = [
'begin', 'eternl', 'flint', 'lace', 'nami', 'nufi', 'gerowallet', 'typhoncip30', 'vespr', 'yoroi'
'begin',
'eternl',
'flint',
'lace',
'nami',
'nufi',
'gerowallet',
'typhoncip30',
'vespr',
'yoroi',
];
2 changes: 1 addition & 1 deletion packages/module/src/common/contracts/evaluator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action } from '@mesh/common/types';
import { Action } from '../../common/types/index.js';

export interface IEvaluator {
evaluateTx(tx: string): Promise<Omit<Action, 'data'>[]>;
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/common/contracts/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Protocol,
TransactionInfo,
UTxO,
} from '@mesh/common/types';
} from '../../common/types/index.js';

/**
* Fetcher interface defines end points to query blockchain data.
Expand Down
14 changes: 7 additions & 7 deletions packages/module/src/common/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './evaluator';
export * from './fetcher';
export * from './initiator';
export * from './listener';
export * from './signer';
export * from './submitter';
export * from './uploader';
export * from './evaluator.js';
export * from './fetcher.js';
export * from './initiator.js';
export * from './listener.js';
export * from './signer.js';
export * from './submitter.js';
export * from './uploader.js';
2 changes: 1 addition & 1 deletion packages/module/src/common/contracts/initiator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Address, TransactionUnspentOutput } from '@mesh/core';
import type { Address, TransactionUnspentOutput } from '../../core/index.js';

export interface IInitiator {
getUsedAddress(): SometimesPromise<Address>;
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/common/contracts/signer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DataSignature } from '@mesh/common/types';
import { DataSignature } from '../../common/types/index.js';

export interface ISigner {
signData(address: string, payload: string): SometimesPromise<DataSignature>;
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/common/helpers/generateNonce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { customAlphabet } from 'nanoid';
import { fromUTF8 } from '@mesh/common/utils';
import { fromUTF8 } from '../../common/utils/index.js';

export const generateNonce = (label = '', length = 32) => {
if (length <= 0 || length > 2048) {
Expand Down
8 changes: 4 additions & 4 deletions packages/module/src/common/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './generateNonce';
export * from './mergeSignatures';
export * from './readPlutusData';
export * from './readTransaction';
export * from './generateNonce.js';
export * from './mergeSignatures.js';
export * from './readPlutusData.js';
export * from './readTransaction.js';
10 changes: 6 additions & 4 deletions packages/module/src/common/helpers/mergeSignatures.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { csl } from '@mesh/core';
import { csl } from '../../core/index.js';
import type {
TransactionWitnessSet, Vkeywitnesses,
} from '@mesh/core';
TransactionWitnessSet,
Vkeywitnesses,
} from '../..//core/index.js';

export const mergeSignatures = (
txWitnessSet: TransactionWitnessSet, newSignatures: Vkeywitnesses,
txWitnessSet: TransactionWitnessSet,
newSignatures: Vkeywitnesses
) => {
const txSignatures = txWitnessSet.vkeys();

Expand Down
7 changes: 4 additions & 3 deletions packages/module/src/common/helpers/readPlutusData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
deserializePlutusData, fromPlutusData,
} from '@mesh/common/utils';
import type { Data } from '@mesh/common/types';
deserializePlutusData,
fromPlutusData,
} from '../../common/utils/index.js';
import type { Data } from '../../common/types/index.js';

export const readPlutusData = (plutusData: string): Data => {
return fromPlutusData(deserializePlutusData(plutusData));
Expand Down
4 changes: 2 additions & 2 deletions packages/module/src/common/helpers/readTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { csl } from '@mesh/core';
import { deserializeTx } from '@mesh/common/utils';
import { csl } from '../../core/index.js';
import { deserializeTx } from '../../common/utils/index.js';

export const readTransaction = (tx: string): csl.TransactionJSON => {
return deserializeTx(tx).to_js_value();
Expand Down
4 changes: 2 additions & 2 deletions packages/module/src/common/types/Action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { REDEEMER_TAGS } from '@mesh/common/constants';
import { Data } from './Data';
import { REDEEMER_TAGS } from '../../common/constants.js';
import { Data } from './Data.js';

export type Action = {
data: Data;
Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/common/types/AssetExtended.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Quantity, Unit } from './Asset';
import { Quantity, Unit } from './Asset.js';

export type AssetExtended = {
unit: Unit;
Expand Down
27 changes: 17 additions & 10 deletions packages/module/src/common/types/AssetMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { MetadataStandard, Files, RoyaltiesStandard } from '@mesh/core';
import type {
MetadataStandard,
Files,
RoyaltiesStandard,
} from '../../core/index.js';

export type AssetMetadata =
| FungibleAssetMetadata
Expand All @@ -19,16 +23,19 @@ export type NonFungibleAssetMetadata =

type AudioAssetMetadata = MetadataStandard & Files;

export type ImageAssetMetadata = MetadataStandard & Files & {
artists?: [{
name: string;
twitter?: `https://twitter.com/${string}`;
}];
attributes?: {
[key: string]: string;
export type ImageAssetMetadata = MetadataStandard &
Files & {
artists?: [
{
name: string;
twitter?: `https://twitter.com/${string}`;
}
];
attributes?: {
[key: string]: string;
};
traits?: string[];
};
traits?: string[];
};

type SmartAssetMetadata = MetadataStandard & Files;

Expand Down
6 changes: 3 additions & 3 deletions packages/module/src/common/types/Mint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Quantity } from './Asset';
import { AssetMetadata } from './AssetMetadata';
import { Recipient } from './Recipient';
import { Quantity } from './Asset.js';
import { AssetMetadata } from './AssetMetadata.js';
import { Recipient } from './Recipient.js';

export type Mint = {
assetName: string;
Expand Down
5 changes: 2 additions & 3 deletions packages/module/src/common/types/PlutusScript.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { LANGUAGE_VERSIONS } from '../constants';
import { LANGUAGE_VERSIONS } from '../constants.js';

export type PlutusScript = {
version: LanguageVersion;
code: string;
};

export type LanguageVersion =
keyof typeof LANGUAGE_VERSIONS;
export type LanguageVersion = keyof typeof LANGUAGE_VERSIONS;
2 changes: 1 addition & 1 deletion packages/module/src/common/types/PoolParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Relay } from './Relay';
import { Relay } from './Relay.js';

export type PoolParams = {
VRFKeyHash: string;
Expand Down
Loading