Skip to content

Commit

Permalink
Added custom ttl for makeCsprTransferDeploy and makeAuctionManagerDeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmyshchyshyn committed Nov 25, 2024
1 parent fe40022 commit be29c68
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/types/Deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
) {
Expand Down
36 changes: 22 additions & 14 deletions src/utils/auction-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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
)
}
: {})
})
);

Expand All @@ -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);
};
19 changes: 15 additions & 4 deletions src/utils/cspr-transfer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
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;
recipientPublicKeyHex: string;
transferAmount: string;
chainName?: CasperNetworkName;
memo?: string;
ttl?: number;
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -58,14 +68,15 @@ export const makeCsprTransferDeploy = ({
transferAmount,
recipientKey,
undefined,
memo,
memo
);

const payment = ExecutableDeployItem.standardPayment('100000000');

const deployHeader = DeployHeader.default();
deployHeader.account = senderKey;
deployHeader.chainName = chainName;
deployHeader.ttl = new Duration(ttl);

return Deploy.makeDeploy(deployHeader, payment, session);
}
};

0 comments on commit be29c68

Please sign in to comment.