Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@react-native/typescript-config": "0.74.83",
"@types/uuid": "^10.0.0",
"apisauce": "^3.1.1",
"casper-js-sdk": "^5.0.6",
"casper-js-sdk": "5.0.6",
"date-fns": "^2.30.0",
"decimal.js": "^10.4.3",
"lru-cache": "10.4.3",
Expand Down
19 changes: 19 additions & 0 deletions src/data/dto/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
import Decimal from 'decimal.js';
import {
AccountKeyType,
CEP_18_ACTION_ENTRY_POINTS,
CSPR_COIN,
IAccountInfo,
NFT_ACTION_ENTRY_POINTS,
SupportedMarketDataProviders,
} from '../../domain';
import { Maybe } from '../../typings';
Expand Down Expand Up @@ -103,3 +105,20 @@ export function getMarketDataProviderUrl(
return null;
}
}

export function isCep18Action(entryPointName: string, contractTypeId?: Maybe<number>): boolean {
return (
(contractTypeId === ContractTypeId.CustomCep18 || contractTypeId === ContractTypeId.Cep18) &&
CEP_18_ACTION_ENTRY_POINTS.includes(entryPointName.toLowerCase())
);
}

export function isNftAction(entryPointName: string, contractTypeId?: Maybe<number>): boolean {
return (
(contractTypeId === ContractTypeId.CEP78Nft ||
contractTypeId === ContractTypeId.CEP47Nft ||
contractTypeId === ContractTypeId.CustomCEP78Nft ||
contractTypeId === ContractTypeId.CustomCEP47Nft) &&
NFT_ACTION_ENTRY_POINTS.includes(entryPointName.toLowerCase())
);
}
17 changes: 15 additions & 2 deletions src/data/dto/deploys/Cep18DeployDto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getDeployAmount, getEntryPoint, guardedDeriveSplitDataFromArguments } from './common';
import {
deriveSplitDataFromNamedKeyValue,
getDeployAmount,
getEntryPoint,
guardedDeriveSplitDataFromArguments,
} from './common';
import {
formatTokenBalance,
getAccountHashFromPublicKey,
Expand Down Expand Up @@ -101,7 +106,15 @@ export function getCep18RecipientKeyAndType(
const owner = guardedDeriveSplitDataFromArguments(data?.args?.owner, 'Account');
const spender = guardedDeriveSplitDataFromArguments(data?.args?.spender, 'Hash');

const info = recipientAccount ?? owner ?? recipient ?? spender;
const recipientAccountHash =
typeof data?.args?.recipient?.parsed === 'string'
? {
...deriveSplitDataFromNamedKeyValue(data?.args?.recipient?.parsed),
keyType: 'accountHash' as const,
}
: null;

const info = recipientAccount ?? owner ?? recipient ?? spender ?? recipientAccountHash;

if (info?.keyType === 'accountHash' && info?.hash) {
const publicKey = derivePublicKeyFromCep18ActionResults(info.hash, data);
Expand Down
20 changes: 7 additions & 13 deletions src/data/dto/deploys/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
AccountKeyType,
AssociatedKeysContractHash,
AuctionManagerContractHash,
CEP_18_ACTION_ENTRY_POINTS,
CSPRMarketContractHash,
CSPRStudioCep47ContractHash,
DeployType,
Expand All @@ -22,7 +21,7 @@ import {

import { ExtendedCloudDeploy, ExtendedDeployArgsResult, IApiDeployArgs } from '../../repositories';
import { Maybe } from '../../../typings';
import { ContractTypeId, getHashByType } from '../common';
import { getHashByType, isCep18Action, isNftAction } from '../common';

export function getDeployType(network: Network, deploy?: Partial<ExtendedCloudDeploy>): DeployType {
const contractTypeId =
Expand All @@ -41,21 +40,16 @@ export function getDeployType(network: Network, deploy?: Partial<ExtendedCloudDe
deploy?.contract_package?.contract_package_hash === CSPRMarketContractHash[network]
) {
return 'CSPR_MARKET';
} else if (
(contractTypeId === ContractTypeId.CustomCep18 || contractTypeId === ContractTypeId.Cep18) &&
CEP_18_ACTION_ENTRY_POINTS.includes(getEntryPoint(deploy) ?? '')
) {
} else if (isCep18Action(getEntryPoint(deploy) ?? '', contractTypeId)) {
return 'CEP18';
} else if (
contractTypeId === ContractTypeId.CEP78Nft ||
contractTypeId === ContractTypeId.CEP47Nft ||
contractTypeId === ContractTypeId.CustomCEP78Nft ||
contractTypeId === ContractTypeId.CustomCEP47Nft ||
contractTypeId === ContractTypeId.CEP95NFT
) {
} else if (isNftAction(getEntryPoint(deploy) ?? '', contractTypeId)) {
return 'NFT';
} else if (deploy?.contract_package?.name === 'Mint' || deploy?.execution_type_id === 6) {
return 'CSPR_NATIVE';
} else if (deploy?.execution_type_id === 1) {
return 'WASM';
} else if (deploy?.execution_type_id === 7) {
return 'WASM_PROXY';
}

return 'UNKNOWN';
Expand Down
34 changes: 13 additions & 21 deletions src/data/dto/txSignatureRequest/TxSignatureRequestDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import {
} from '../../../domain';
import { Maybe } from '../../../typings';
import { formatTokenBalance, isKeysEqual } from '../../../utils';
import { ContractTypeId, deriveKeyType, getAccountInfoFromMap, getCsprFiatAmount } from '../common';
import {
deriveKeyType,
getAccountInfoFromMap,
getCsprFiatAmount,
isCep18Action,
isNftAction,
} from '../common';
import {
getTxSignatureRequestAssociatedKeysAction,
getTxSignatureRequestAuctionAction,
Expand Down Expand Up @@ -88,7 +94,7 @@ export class TxSignatureRequestDto implements ITxSignatureRequest {
tx,
csprFiatRate,
network,
signingPublicKeyHex,
this.senderKey,
accountInfoMap,
contractPackage,
collectionContractPackage,
Expand Down Expand Up @@ -124,7 +130,7 @@ export function getTxSignatureRequestAction(
tx: Transaction,
csprFiatRate: string,
network: Maybe<CasperNetwork>,
signingPublicKeyHex: string,
senderPublicKeyHex: string,
accountInfoMap: Record<string, IAccountInfo> = {},
contractPackage: Maybe<IContractPackage>,
collectionContractPackage: Maybe<IContractPackage>,
Expand All @@ -150,7 +156,7 @@ export function getTxSignatureRequestAction(
tx,
accountInfoMap,
csprFiatRate,
signingPublicKeyHex,
senderPublicKeyHex,
contractPackage,
);

Expand All @@ -173,7 +179,7 @@ export function getTxSignatureRequestAction(
tx,
accountInfoMap,
csprFiatRate,
signingPublicKeyHex,
senderPublicKeyHex,
contractPackage,
);
} else if (
Expand All @@ -189,14 +195,9 @@ export function getTxSignatureRequestAction(
contractPackage,
collectionContractPackage,
);
} else if (isCep18Action(tx, contractTypeId)) {
} else if (isCep18Action(tx.entryPoint.customEntryPoint ?? '', contractTypeId)) {
return getTxSignatureRequestCep18Action(tx, accountInfoMap, contractPackage);
} else if (
contractTypeId === ContractTypeId.CEP78Nft ||
contractTypeId === ContractTypeId.CEP47Nft ||
contractTypeId === ContractTypeId.CustomCEP78Nft ||
contractTypeId === ContractTypeId.CustomCEP47Nft
) {
} else if (isNftAction(tx.entryPoint.customEntryPoint ?? '', contractTypeId)) {
return getTxSignatureRequestNFTAction(
tx,
accountInfoMap,
Expand Down Expand Up @@ -261,12 +262,3 @@ function isContractSpecificContractCall(tx: Transaction, contractInfo: IContract
storedTargetId?.byPackageName?.name === contractInfo.contractPackageName
);
}

function isCep18Action(tx: Transaction, contractTypeId?: number): boolean {
const entryPoint = tx.entryPoint.customEntryPoint ?? '';

return (
(contractTypeId === ContractTypeId.CustomCep18 || contractTypeId === ContractTypeId.Cep18) &&
CEP_18_ACTION_ENTRY_POINTS.includes(entryPoint.toLowerCase())
);
}
8 changes: 4 additions & 4 deletions src/data/dto/txSignatureRequest/actions/auctionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getTxSignatureRequestAuctionAction(
tx: Transaction,
accountInfoMap: Record<string, IAccountInfo> = {},
csprFiatRate: string,
signingPublicKeyHex: string,
senderPublicKeyHex: string,
contractPackage: Maybe<IContractPackage>,
): ITxSignatureRequestAuctionAction {
const amount = tx.args.getByName('amount')?.toString() ?? '0';
Expand All @@ -28,7 +28,7 @@ export function getTxSignatureRequestAuctionAction(
fromValidatorKeyType,
);

const toValidator = getToValidator(tx, entryPoint, signingPublicKeyHex);
const toValidator = getToValidator(tx, entryPoint, senderPublicKeyHex);
const toValidatorKeyType = deriveKeyType(toValidator);
const toValidatorAccountInfo = getAccountInfoFromMap(
accountInfoMap,
Expand Down Expand Up @@ -75,7 +75,7 @@ function getFromValidator(tx: Transaction, entryPoint: string): string | null {
return null;
}

function getToValidator(tx: Transaction, entryPoint: string, signingPublicKeyHex: string) {
function getToValidator(tx: Transaction, entryPoint: string, senderPublicKeyHex: string) {
const new_validator = tx.args.getByName('new_validator');

if (new_validator) {
Expand All @@ -85,7 +85,7 @@ function getToValidator(tx: Transaction, entryPoint: string, signingPublicKeyHex

return validator?.type.getTypeID() === TypeID.PublicKey ? validator.toString() : '';
} else if (entryPoint.toLowerCase() === 'undelegate') {
return signingPublicKeyHex;
return senderPublicKeyHex;
}

return null;
Expand Down
10 changes: 10 additions & 0 deletions src/domain/constants/casperNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ export const CEP_18_ACTION_ENTRY_POINTS = [
'mint',
'burn',
];

export const NFT_ACTION_ENTRY_POINTS = [
'approve',
'burn',
'mint',
'transfer',
'transfer_from',
'update_token_meta',
'set_approval_for_all',
];
2 changes: 2 additions & 0 deletions src/domain/deploys/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type DeployType =
| 'AUCTION'
| 'CSPR_MARKET'
| 'ASSOCIATED_KEYS'
| 'WASM'
| 'WASM_PROXY'
| 'UNKNOWN';

export interface IDeploy extends IEntity {
Expand Down
8 changes: 6 additions & 2 deletions src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export const isNativeCsprDeploy = (deploy: IDeploy): deploy is INativeCsprDeploy
export const isNftDeploy = (deploy: IDeploy): deploy is INftDeploy => {
return deploy.type === 'NFT';
};
export const isWasmDeploy = (deploy: IDeploy): deploy is INftDeploy => {
return deploy.type === 'WASM';
};
export const isWasmProxyDeploy = (deploy: IDeploy): deploy is INftDeploy => {
return deploy.type === 'WASM_PROXY';
};

export const isUnknownDeploy = (deploy: IDeploy): deploy is IDeploy => {
return deploy.type === 'UNKNOWN';
};

export const isWasmDeployExecutionType = (deploy: IDeploy) =>
Number(deploy.executionTypeId) === 1 || Number(deploy.executionTypeId) === 7;
export const isContractCallExecutionType = (deploy: IDeploy) =>
Number(deploy.executionTypeId) > 1 && Number(deploy.executionTypeId) < 6;
export const isTransferExecutionType = (deploy: IDeploy) => Number(deploy.executionTypeId) === 6;
Loading