From be29c686b5b6c9a91758ae807635c64c0662a1f7 Mon Sep 17 00:00:00 2001 From: Oleksandr Myshchyshyn Date: Mon, 25 Nov 2024 17:01:08 +0200 Subject: [PATCH] Added custom ttl for makeCsprTransferDeploy and makeAuctionManagerDeploy --- src/types/Deploy.ts | 4 ++-- src/utils/auction-manager.ts | 36 ++++++++++++++++++++++-------------- src/utils/cspr-transfer.ts | 19 +++++++++++++++---- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/types/Deploy.ts b/src/types/Deploy.ts index d12a99ec8..a15da4992 100644 --- a/src/types/Deploy.ts +++ b/src/types/Deploy.ts @@ -111,7 +111,7 @@ export class DeployHeader { deserializer: json => Duration.fromJSON(json), serializer: value => value.toJSON() }) - public ttl: Duration = new Duration(30 * 60 * 1000); + public ttl: Duration = new Duration(DEFAULT_DEPLOY_TTL); /** * Constructs a `DeployHeader` instance with the specified parameters. @@ -128,7 +128,7 @@ export class DeployHeader { dependencies: Hash[] = [], gasPrice = 1, timestamp: Timestamp = new Timestamp(new Date()), - ttl: Duration = new Duration(30 * 60 * 1000), + ttl: Duration = new Duration(DEFAULT_DEPLOY_TTL), account?: PublicKey, bodyHash?: Hash ) { diff --git a/src/utils/auction-manager.ts b/src/utils/auction-manager.ts index e583301fc..942e97e08 100644 --- a/src/utils/auction-manager.ts +++ b/src/utils/auction-manager.ts @@ -3,23 +3,26 @@ import { CLValue, CLValueUInt512, ContractHash, + DEFAULT_DEPLOY_TTL, Deploy, DeployHeader, + Duration, ExecutableDeployItem, PublicKey, StoredContractByHash -} from "../types"; -import { AuctionManagerEntryPoint, CasperNetworkName } from "../@types"; -import { AuctionManagerContractHashMap } from "./constants"; +} from '../types'; +import { AuctionManagerEntryPoint, CasperNetworkName } from '../@types'; +import { AuctionManagerContractHashMap } from './constants'; export interface IMakeAuctionManagerDeployParams { - contractEntryPoint: AuctionManagerEntryPoint, - delegatorPublicKeyHex: string, - validatorPublicKeyHex: string, - newValidatorPublicKeyHex?: string, - amount: string, - paymentAmount?: string, + contractEntryPoint: AuctionManagerEntryPoint; + delegatorPublicKeyHex: string; + validatorPublicKeyHex: string; + newValidatorPublicKeyHex?: string; + amount: string; + paymentAmount?: string; chainName?: CasperNetworkName; + ttl?: number; } /** @@ -68,8 +71,8 @@ export const makeAuctionManagerDeploy = ({ paymentAmount = '2500000000', chainName = CasperNetworkName.Mainnet, newValidatorPublicKeyHex, - }: IMakeAuctionManagerDeployParams -) => { + ttl = DEFAULT_DEPLOY_TTL +}: IMakeAuctionManagerDeployParams) => { const delegatorPublicKey = PublicKey.newPublicKey(delegatorPublicKeyHex); const validatorPublicKey = PublicKey.newPublicKey(validatorPublicKeyHex); const newValidatorValidatorPublicKey = newValidatorPublicKeyHex @@ -84,9 +87,13 @@ export const makeAuctionManagerDeploy = ({ validator: CLValue.newCLPublicKey(validatorPublicKey), delegator: CLValue.newCLPublicKey(delegatorPublicKey), amount: CLValueUInt512.newCLUInt512(amount), - ...(newValidatorValidatorPublicKey ? { - new_validator: CLValue.newCLPublicKey(newValidatorValidatorPublicKey) - } : {}) + ...(newValidatorValidatorPublicKey + ? { + new_validator: CLValue.newCLPublicKey( + newValidatorValidatorPublicKey + ) + } + : {}) }) ); @@ -95,6 +102,7 @@ export const makeAuctionManagerDeploy = ({ const deployHeader = DeployHeader.default(); deployHeader.account = delegatorPublicKey; deployHeader.chainName = chainName; + deployHeader.ttl = new Duration(ttl); return Deploy.makeDeploy(deployHeader, payment, session); }; diff --git a/src/utils/cspr-transfer.ts b/src/utils/cspr-transfer.ts index f65052ebd..305313604 100644 --- a/src/utils/cspr-transfer.ts +++ b/src/utils/cspr-transfer.ts @@ -1,5 +1,13 @@ -import { Deploy, DeployHeader, ExecutableDeployItem, PublicKey, TransferDeployItem } from "../types"; -import { CasperNetworkName } from "../@types"; +import { + DEFAULT_DEPLOY_TTL, + Deploy, + DeployHeader, + Duration, + ExecutableDeployItem, + PublicKey, + TransferDeployItem +} from '../types'; +import { CasperNetworkName } from '../@types'; export interface IMakeCsprTransferDeployParams { senderPublicKeyHex: string; @@ -7,6 +15,7 @@ export interface IMakeCsprTransferDeployParams { transferAmount: string; chainName?: CasperNetworkName; memo?: string; + ttl?: number; } /** @@ -49,6 +58,7 @@ export const makeCsprTransferDeploy = ({ transferAmount, chainName = CasperNetworkName.Mainnet, memo, + ttl = DEFAULT_DEPLOY_TTL }: IMakeCsprTransferDeployParams) => { const recipientKey = PublicKey.newPublicKey(recipientPublicKeyHex); const senderKey = PublicKey.newPublicKey(senderPublicKeyHex); @@ -58,7 +68,7 @@ export const makeCsprTransferDeploy = ({ transferAmount, recipientKey, undefined, - memo, + memo ); const payment = ExecutableDeployItem.standardPayment('100000000'); @@ -66,6 +76,7 @@ export const makeCsprTransferDeploy = ({ const deployHeader = DeployHeader.default(); deployHeader.account = senderKey; deployHeader.chainName = chainName; + deployHeader.ttl = new Duration(ttl); return Deploy.makeDeploy(deployHeader, payment, session); -} +};