decentraland-dapps 23.5.0 → 23.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/time.d.ts +1 -0
- package/dist/lib/time.js +4 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/trades.d.ts +37 -0
- package/dist/lib/trades.js +129 -0
- package/dist/lib/trades.js.map +1 -0
- package/dist/modules/trades/TradeService.d.ts +10 -0
- package/dist/modules/trades/TradeService.js +34 -0
- package/dist/modules/trades/TradeService.js.map +1 -0
- package/dist/modules/trades/api.d.ts +8 -0
- package/dist/modules/trades/api.js +25 -0
- package/dist/modules/trades/api.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fromMillisecondsToSeconds(timeInMilliseconds: number): number;
|
package/dist/lib/time.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/lib/time.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,yBAAyB,CAAC,kBAA0B;IAClE,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TypedDataField, ethers } from 'ethers';
|
|
2
|
+
import { ChainId, OnChainTrade, Trade, TradeAsset, TradeAssetType, TradeCreation } from '@dcl/schemas';
|
|
3
|
+
export declare const OFFCHAIN_MARKETPLACE_TYPES: Record<string, TypedDataField[]>;
|
|
4
|
+
export declare function getOffChainMarketplaceContract(chainId: ChainId): Promise<ethers.Contract>;
|
|
5
|
+
export declare function getValueForTradeAsset(asset: TradeAsset): string;
|
|
6
|
+
export declare function generateTradeValues(trade: Omit<TradeCreation, 'signature'>): {
|
|
7
|
+
checks: {
|
|
8
|
+
uses: number;
|
|
9
|
+
expiration: number;
|
|
10
|
+
effective: number;
|
|
11
|
+
salt: string;
|
|
12
|
+
contractSignatureIndex: number;
|
|
13
|
+
signerSignatureIndex: number;
|
|
14
|
+
allowedRoot: string;
|
|
15
|
+
externalChecks: {
|
|
16
|
+
contractAddress: string;
|
|
17
|
+
selector: string;
|
|
18
|
+
value: string;
|
|
19
|
+
required: boolean;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
sent: {
|
|
23
|
+
assetType: TradeAssetType;
|
|
24
|
+
contractAddress: string;
|
|
25
|
+
value: string;
|
|
26
|
+
extra: string;
|
|
27
|
+
}[];
|
|
28
|
+
received: {
|
|
29
|
+
assetType: TradeAssetType;
|
|
30
|
+
contractAddress: string;
|
|
31
|
+
value: string;
|
|
32
|
+
extra: string;
|
|
33
|
+
beneficiary: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
export declare function getOnChainTrade(trade: Trade, sentBeneficiaryAddress: string): OnChainTrade;
|
|
37
|
+
export declare function getTradeSignature(trade: Omit<TradeCreation, 'signature'>): Promise<string>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { TradeAssetType } from '@dcl/schemas';
|
|
3
|
+
import { ContractName, getContract } from 'decentraland-transactions';
|
|
4
|
+
import { getNetworkProvider, getSigner } from './eth';
|
|
5
|
+
import { fromMillisecondsToSeconds } from './time';
|
|
6
|
+
export const OFFCHAIN_MARKETPLACE_TYPES = {
|
|
7
|
+
Trade: [
|
|
8
|
+
{ name: 'checks', type: 'Checks' },
|
|
9
|
+
{ name: 'sent', type: 'AssetWithoutBeneficiary[]' },
|
|
10
|
+
{ name: 'received', type: 'Asset[]' }
|
|
11
|
+
],
|
|
12
|
+
Asset: [
|
|
13
|
+
{ name: 'assetType', type: 'uint256' },
|
|
14
|
+
{ name: 'contractAddress', type: 'address' },
|
|
15
|
+
{ name: 'value', type: 'uint256' },
|
|
16
|
+
{ name: 'extra', type: 'bytes' },
|
|
17
|
+
{ name: 'beneficiary', type: 'address' }
|
|
18
|
+
],
|
|
19
|
+
AssetWithoutBeneficiary: [
|
|
20
|
+
{ name: 'assetType', type: 'uint256' },
|
|
21
|
+
{ name: 'contractAddress', type: 'address' },
|
|
22
|
+
{ name: 'value', type: 'uint256' },
|
|
23
|
+
{ name: 'extra', type: 'bytes' }
|
|
24
|
+
],
|
|
25
|
+
Checks: [
|
|
26
|
+
{ name: 'uses', type: 'uint256' },
|
|
27
|
+
{ name: 'expiration', type: 'uint256' },
|
|
28
|
+
{ name: 'effective', type: 'uint256' },
|
|
29
|
+
{ name: 'salt', type: 'bytes32' },
|
|
30
|
+
{ name: 'contractSignatureIndex', type: 'uint256' },
|
|
31
|
+
{ name: 'signerSignatureIndex', type: 'uint256' },
|
|
32
|
+
{ name: 'allowedRoot', type: 'bytes32' },
|
|
33
|
+
{ name: 'externalChecks', type: 'ExternalCheck[]' }
|
|
34
|
+
],
|
|
35
|
+
ExternalCheck: [
|
|
36
|
+
{ name: 'contractAddress', type: 'address' },
|
|
37
|
+
{ name: 'selector', type: 'bytes4' },
|
|
38
|
+
{ name: 'value', type: 'bytes' },
|
|
39
|
+
{ name: 'required', type: 'bool' }
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
export async function getOffChainMarketplaceContract(chainId) {
|
|
43
|
+
const provider = await getNetworkProvider(chainId);
|
|
44
|
+
if (!provider) {
|
|
45
|
+
throw new Error('Could not get connected provider');
|
|
46
|
+
}
|
|
47
|
+
const { address, abi } = getContract(ContractName.OffChainMarketplace, chainId);
|
|
48
|
+
const instance = new ethers.Contract(address, abi, new ethers.providers.Web3Provider(provider));
|
|
49
|
+
return instance;
|
|
50
|
+
}
|
|
51
|
+
export function getValueForTradeAsset(asset) {
|
|
52
|
+
switch (asset.assetType) {
|
|
53
|
+
case TradeAssetType.ERC721:
|
|
54
|
+
return asset.tokenId;
|
|
55
|
+
case TradeAssetType.COLLECTION_ITEM:
|
|
56
|
+
return asset.itemId;
|
|
57
|
+
case TradeAssetType.ERC20:
|
|
58
|
+
return asset.amount;
|
|
59
|
+
default:
|
|
60
|
+
console.error('Invalid asset type:', asset);
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function generateTradeValues(trade) {
|
|
65
|
+
return {
|
|
66
|
+
checks: {
|
|
67
|
+
uses: trade.checks.uses,
|
|
68
|
+
expiration: fromMillisecondsToSeconds(trade.checks.expiration),
|
|
69
|
+
effective: fromMillisecondsToSeconds(trade.checks.effective),
|
|
70
|
+
salt: ethers.utils.hexZeroPad(trade.checks.salt, 32),
|
|
71
|
+
contractSignatureIndex: trade.checks.contractSignatureIndex,
|
|
72
|
+
signerSignatureIndex: trade.checks.signerSignatureIndex,
|
|
73
|
+
allowedRoot: ethers.utils.hexZeroPad(trade.checks.allowedRoot, 32),
|
|
74
|
+
externalChecks: trade.checks.externalChecks?.map(externalCheck => ({
|
|
75
|
+
contractAddress: externalCheck.contractAddress,
|
|
76
|
+
selector: externalCheck.selector,
|
|
77
|
+
value: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(externalCheck.value)),
|
|
78
|
+
required: externalCheck.required
|
|
79
|
+
}))
|
|
80
|
+
},
|
|
81
|
+
sent: trade.sent.map(asset => ({
|
|
82
|
+
assetType: asset.assetType,
|
|
83
|
+
contractAddress: asset.contractAddress,
|
|
84
|
+
value: getValueForTradeAsset(asset),
|
|
85
|
+
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra))
|
|
86
|
+
})),
|
|
87
|
+
received: trade.received.map(asset => ({
|
|
88
|
+
assetType: asset.assetType,
|
|
89
|
+
contractAddress: asset.contractAddress,
|
|
90
|
+
value: getValueForTradeAsset(asset),
|
|
91
|
+
extra: ethers.utils.hexlify(ethers.utils.toUtf8Bytes(asset.extra)),
|
|
92
|
+
beneficiary: asset.beneficiary
|
|
93
|
+
}))
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export function getOnChainTrade(trade, sentBeneficiaryAddress) {
|
|
97
|
+
const tradeValues = generateTradeValues(trade);
|
|
98
|
+
return {
|
|
99
|
+
signer: trade.signer,
|
|
100
|
+
signature: trade.signature,
|
|
101
|
+
...tradeValues,
|
|
102
|
+
checks: {
|
|
103
|
+
...tradeValues.checks,
|
|
104
|
+
allowedProof: []
|
|
105
|
+
},
|
|
106
|
+
// set the beneficiary of the sent assets to the address of the logged in user
|
|
107
|
+
sent: tradeValues.sent.map(asset => ({
|
|
108
|
+
...asset,
|
|
109
|
+
beneficiary: sentBeneficiaryAddress
|
|
110
|
+
}))
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
export async function getTradeSignature(trade) {
|
|
114
|
+
const marketplaceContract = getContract(ContractName.OffChainMarketplace, trade.chainId);
|
|
115
|
+
if (!marketplaceContract) {
|
|
116
|
+
throw new Error(`The ${ContractName.OffChainMarketplace} contract doesn't exist on chain ${trade.chainId}`);
|
|
117
|
+
}
|
|
118
|
+
const signer = (await getSigner());
|
|
119
|
+
const SALT = ethers.utils.hexZeroPad(ethers.utils.hexlify(trade.chainId), 32);
|
|
120
|
+
const domain = {
|
|
121
|
+
name: marketplaceContract.name,
|
|
122
|
+
version: marketplaceContract.version,
|
|
123
|
+
salt: SALT,
|
|
124
|
+
verifyingContract: marketplaceContract.address
|
|
125
|
+
};
|
|
126
|
+
const signature = await signer._signTypedData(domain, OFFCHAIN_MARKETPLACE_TYPES, generateTradeValues(trade));
|
|
127
|
+
return signature;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=trades.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trades.js","sourceRoot":"","sources":["../../src/lib/trades.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,MAAM,EAAE,MAAM,QAAQ,CAAA;AAChE,OAAO,EAML,cAAc,EAEf,MAAM,cAAc,CAAA;AACrB,OAAO,EAEL,YAAY,EACZ,WAAW,EACZ,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,OAAO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AAK,CACb,OAAO,YAAY,CAAC,mBAAmB,oCAAoC,KAAK,CAAC,OAAO,EAAE,CAC3F,CAAA;IACH,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,SAAS,EAAE,CAAmC,CAAA;IACpE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7E,MAAM,MAAM,GAAoB;QAC9B,IAAI,EAAE,mBAAmB,CAAC,IAAI;QAC9B,OAAO,EAAE,mBAAmB,CAAC,OAAO;QACpC,IAAI,EAAE,IAAI;QACV,iBAAiB,EAAE,mBAAmB,CAAC,OAAO;KAC/C,CAAA;IAED,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,cAAc,CAC3C,MAAM,EACN,0BAA0B,EAC1B,mBAAmB,CAAC,KAAK,CAAC,CAC3B,CAAA;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Trade, TradeCreation } from '@dcl/schemas';
|
|
2
|
+
import { AuthIdentity } from 'decentraland-crypto-fetch';
|
|
3
|
+
export declare class TradeService {
|
|
4
|
+
private tradesAPI;
|
|
5
|
+
constructor(signer: string, basePath: string, getIdentity: () => AuthIdentity | undefined);
|
|
6
|
+
addTrade(trade: TradeCreation): Promise<Trade>;
|
|
7
|
+
fetchTrade(tradeId: string): Promise<Trade>;
|
|
8
|
+
accept(trade: Trade, sentBeneficiaryAddress: string): Promise<string>;
|
|
9
|
+
cancel(trade: Trade, sentBeneficiaryAddress: string): Promise<string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ContractName, getContract } from 'decentraland-transactions';
|
|
2
|
+
import { TradesAPI } from './api';
|
|
3
|
+
import { getOnChainTrade } from '../../lib/trades';
|
|
4
|
+
import { sendTransaction } from '../wallet/utils';
|
|
5
|
+
export class TradeService {
|
|
6
|
+
tradesAPI;
|
|
7
|
+
constructor(signer, basePath, getIdentity) {
|
|
8
|
+
this.tradesAPI = new TradesAPI(signer, basePath, {
|
|
9
|
+
identity: getIdentity,
|
|
10
|
+
retries: 0
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async addTrade(trade) {
|
|
14
|
+
return this.tradesAPI.addTrade(trade);
|
|
15
|
+
}
|
|
16
|
+
async fetchTrade(tradeId) {
|
|
17
|
+
return this.tradesAPI.fetchTrade(tradeId);
|
|
18
|
+
}
|
|
19
|
+
async accept(trade, sentBeneficiaryAddress) {
|
|
20
|
+
const offchainMarketplaceContract = getContract(ContractName.OffChainMarketplace, trade.chainId);
|
|
21
|
+
const tradeToAccept = getOnChainTrade(trade, sentBeneficiaryAddress);
|
|
22
|
+
return sendTransaction(offchainMarketplaceContract, 'accept', [
|
|
23
|
+
tradeToAccept
|
|
24
|
+
]);
|
|
25
|
+
}
|
|
26
|
+
async cancel(trade, sentBeneficiaryAddress) {
|
|
27
|
+
const offchainMarketplaceContract = getContract(ContractName.OffChainMarketplace, trade.chainId);
|
|
28
|
+
const tradeToCancel = getOnChainTrade(trade, sentBeneficiaryAddress);
|
|
29
|
+
return sendTransaction(offchainMarketplaceContract, 'cancelSignature', [
|
|
30
|
+
tradeToCancel
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=TradeService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradeService.js","sourceRoot":"","sources":["../../../src/modules/trades/TradeService.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,OAAO,YAAY;IACf,SAAS,CAAW;IAE5B,YACE,MAAc,EACd,QAAgB,EAChB,WAA2C;QAE3C,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE;YAC/C,QAAQ,EAAE,WAAW;YACrB,OAAO,EAAE,CAAC;SACX,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAoB;QACjC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACvC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAY,EAAE,sBAA8B;QACvD,MAAM,2BAA2B,GAAG,WAAW,CAC7C,YAAY,CAAC,mBAAmB,EAChC,KAAK,CAAC,OAAO,CACd,CAAA;QACD,MAAM,aAAa,GAAG,eAAe,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAA;QACpE,OAAO,eAAe,CAAC,2BAA2B,EAAE,QAAQ,EAAE;YAC5D,aAAa;SACd,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAY,EAAE,sBAA8B;QACvD,MAAM,2BAA2B,GAAG,WAAW,CAC7C,YAAY,CAAC,mBAAmB,EAChC,KAAK,CAAC,OAAO,CACd,CAAA;QACD,MAAM,aAAa,GAAG,eAAe,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAA;QACpE,OAAO,eAAe,CAAC,2BAA2B,EAAE,iBAAiB,EAAE;YACrE,aAAa;SACd,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Trade, TradeCreation } from '@dcl/schemas';
|
|
2
|
+
import { BaseClient, BaseClientConfig } from '../../lib';
|
|
3
|
+
export declare class TradesAPI extends BaseClient {
|
|
4
|
+
signer: string;
|
|
5
|
+
constructor(dappSigner: string, url: string, config?: BaseClientConfig);
|
|
6
|
+
addTrade: (trade: TradeCreation) => Promise<Trade>;
|
|
7
|
+
fetchTrade: (tradeId: string) => Promise<Trade>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseClient } from '../../lib';
|
|
2
|
+
export class TradesAPI extends BaseClient {
|
|
3
|
+
signer;
|
|
4
|
+
constructor(dappSigner, url, config) {
|
|
5
|
+
super(url, config);
|
|
6
|
+
this.signer = dappSigner;
|
|
7
|
+
}
|
|
8
|
+
addTrade = async (trade) => {
|
|
9
|
+
return this.fetch('/v1/trades', {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
body: JSON.stringify(trade),
|
|
12
|
+
metadata: {
|
|
13
|
+
signer: this.signer,
|
|
14
|
+
intent: 'dcl:create-trade'
|
|
15
|
+
},
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
fetchTrade = async (tradeId) => {
|
|
22
|
+
return this.fetch(`/v1/trades/${tradeId}`, { method: 'GET' });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/trades/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAA;AAExD,MAAM,OAAO,SAAU,SAAQ,UAAU;IACvC,MAAM,CAAQ;IAEd,YAAY,UAAkB,EAAE,GAAW,EAAE,MAAyB;QACpE,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,UAAU,CAAA;IAC1B,CAAC;IAED,QAAQ,GAAG,KAAK,EAAE,KAAoB,EAAE,EAAE;QACxC,OAAO,IAAI,CAAC,KAAK,CAAQ,YAAY,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAC3B,QAAQ,EAAE;gBACR,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,MAAM,EAAE,kBAAkB;aAC3B;YACD,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,UAAU,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;QACrC,OAAO,IAAI,CAAC,KAAK,CAAQ,cAAc,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;IACtE,CAAC,CAAA;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decentraland-dapps",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.6.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@0xsequence/multicall": "^0.25.1",
|
|
11
11
|
"@0xsequence/relayer": "^0.25.1",
|
|
12
12
|
"@dcl/crypto": "^3.3.1",
|
|
13
|
-
"@dcl/schemas": "^
|
|
13
|
+
"@dcl/schemas": "^14.0.0",
|
|
14
14
|
"@dcl/single-sign-on-client": "^0.1.0",
|
|
15
15
|
"@dcl/ui-env": "^1.5.0",
|
|
16
16
|
"@transak/transak-sdk": "^1.0.31",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dcl-catalyst-client": "^21.1.0",
|
|
24
24
|
"decentraland-connect": "^7.0.0",
|
|
25
25
|
"decentraland-crypto-fetch": "^2.0.1",
|
|
26
|
-
"decentraland-transactions": "^2.
|
|
26
|
+
"decentraland-transactions": "^2.15.0",
|
|
27
27
|
"decentraland-ui": "^6.9.2",
|
|
28
28
|
"ethers": "^5.6.8",
|
|
29
29
|
"events": "^3.3.0",
|