diff --git a/package.json b/package.json index 82333d5..86670df 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data/dto/common.ts b/src/data/dto/common.ts index 93de871..dc9094b 100644 --- a/src/data/dto/common.ts +++ b/src/data/dto/common.ts @@ -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'; @@ -103,3 +105,20 @@ export function getMarketDataProviderUrl( return null; } } + +export function isCep18Action(entryPointName: string, contractTypeId?: Maybe): boolean { + return ( + (contractTypeId === ContractTypeId.CustomCep18 || contractTypeId === ContractTypeId.Cep18) && + CEP_18_ACTION_ENTRY_POINTS.includes(entryPointName.toLowerCase()) + ); +} + +export function isNftAction(entryPointName: string, contractTypeId?: Maybe): boolean { + return ( + (contractTypeId === ContractTypeId.CEP78Nft || + contractTypeId === ContractTypeId.CEP47Nft || + contractTypeId === ContractTypeId.CustomCEP78Nft || + contractTypeId === ContractTypeId.CustomCEP47Nft) && + NFT_ACTION_ENTRY_POINTS.includes(entryPointName.toLowerCase()) + ); +} diff --git a/src/data/dto/deploys/Cep18DeployDto.ts b/src/data/dto/deploys/Cep18DeployDto.ts index 87a2a1a..f8f1c1a 100644 --- a/src/data/dto/deploys/Cep18DeployDto.ts +++ b/src/data/dto/deploys/Cep18DeployDto.ts @@ -1,4 +1,9 @@ -import { getDeployAmount, getEntryPoint, guardedDeriveSplitDataFromArguments } from './common'; +import { + deriveSplitDataFromNamedKeyValue, + getDeployAmount, + getEntryPoint, + guardedDeriveSplitDataFromArguments, +} from './common'; import { formatTokenBalance, getAccountHashFromPublicKey, @@ -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); diff --git a/src/data/dto/deploys/common.ts b/src/data/dto/deploys/common.ts index 547ea0a..1d20ee0 100644 --- a/src/data/dto/deploys/common.ts +++ b/src/data/dto/deploys/common.ts @@ -12,7 +12,6 @@ import { AccountKeyType, AssociatedKeysContractHash, AuctionManagerContractHash, - CEP_18_ACTION_ENTRY_POINTS, CSPRMarketContractHash, CSPRStudioCep47ContractHash, DeployType, @@ -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): DeployType { const contractTypeId = @@ -41,21 +40,16 @@ export function getDeployType(network: Network, deploy?: Partial, - signingPublicKeyHex: string, + senderPublicKeyHex: string, accountInfoMap: Record = {}, contractPackage: Maybe, collectionContractPackage: Maybe, @@ -150,7 +156,7 @@ export function getTxSignatureRequestAction( tx, accountInfoMap, csprFiatRate, - signingPublicKeyHex, + senderPublicKeyHex, contractPackage, ); @@ -173,7 +179,7 @@ export function getTxSignatureRequestAction( tx, accountInfoMap, csprFiatRate, - signingPublicKeyHex, + senderPublicKeyHex, contractPackage, ); } else if ( @@ -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, @@ -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()) - ); -} diff --git a/src/data/dto/txSignatureRequest/actions/auctionAction.ts b/src/data/dto/txSignatureRequest/actions/auctionAction.ts index 8b756b2..f281b87 100644 --- a/src/data/dto/txSignatureRequest/actions/auctionAction.ts +++ b/src/data/dto/txSignatureRequest/actions/auctionAction.ts @@ -14,7 +14,7 @@ export function getTxSignatureRequestAuctionAction( tx: Transaction, accountInfoMap: Record = {}, csprFiatRate: string, - signingPublicKeyHex: string, + senderPublicKeyHex: string, contractPackage: Maybe, ): ITxSignatureRequestAuctionAction { const amount = tx.args.getByName('amount')?.toString() ?? '0'; @@ -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, @@ -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) { @@ -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; diff --git a/src/domain/constants/casperNetwork.ts b/src/domain/constants/casperNetwork.ts index f21d0b6..854547a 100644 --- a/src/domain/constants/casperNetwork.ts +++ b/src/domain/constants/casperNetwork.ts @@ -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', +]; diff --git a/src/domain/deploys/entities.ts b/src/domain/deploys/entities.ts index 4d1833a..b42c473 100644 --- a/src/domain/deploys/entities.ts +++ b/src/domain/deploys/entities.ts @@ -19,6 +19,8 @@ export type DeployType = | 'AUCTION' | 'CSPR_MARKET' | 'ASSOCIATED_KEYS' + | 'WASM' + | 'WASM_PROXY' | 'UNKNOWN'; export interface IDeploy extends IEntity { diff --git a/src/utils/deploy.ts b/src/utils/deploy.ts index a5f0d3b..9320a93 100644 --- a/src/utils/deploy.ts +++ b/src/utils/deploy.ts @@ -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; diff --git a/yarn.lock b/yarn.lock index ffc2138..21e1979 100644 --- a/yarn.lock +++ b/yarn.lock @@ -352,11 +352,11 @@ __metadata: linkType: hard "@noble/curves@npm:^1.1.0, @noble/curves@npm:~1.9.0": - version: 1.9.1 - resolution: "@noble/curves@npm:1.9.1" + version: 1.9.7 + resolution: "@noble/curves@npm:1.9.7" dependencies: "@noble/hashes": "npm:1.8.0" - checksum: 10c0/39c84dbfecdca80cfde2ecea4b06ef2ec1255a4df40158d22491d1400057a283f57b2b26c8b1331006e6e061db791f31d47764961c239437032e2f45e8888c1e + checksum: 10c0/150014751ebe8ca06a8654ca2525108452ea9ee0be23430332769f06808cddabfe84f248b6dbf836916bc869c27c2092957eec62c7506d68a1ed0a624017c2a3 languageName: node linkType: hard @@ -466,9 +466,9 @@ __metadata: linkType: hard "@scure/base@npm:~1.2.5": - version: 1.2.5 - resolution: "@scure/base@npm:1.2.5" - checksum: 10c0/078928dbcdd21a037b273b81b8b0bd93af8a325e2ffd535b7ccaadd48ee3c15bab600ec2920a209fca0910abc792cca9b01d3336b472405c407440e6c0aa8bd6 + version: 1.2.6 + resolution: "@scure/base@npm:1.2.6" + checksum: 10c0/49bd5293371c4e062cb6ba689c8fe3ea3981b7bb9c000400dc4eafa29f56814cdcdd27c04311c2fec34de26bc373c593a1d6ca6d754398a488d587943b7c128a languageName: node linkType: hard @@ -501,11 +501,11 @@ __metadata: linkType: hard "@types/node@npm:*": - version: 22.15.24 - resolution: "@types/node@npm:22.15.24" + version: 25.0.3 + resolution: "@types/node@npm:25.0.3" dependencies: - undici-types: "npm:~6.21.0" - checksum: 10c0/16c38e98168fa6c3d2f2b6e95f14f80878d969b39093bc5384385a884d73a7fe361c563b36f14bc27536b337f5baad74321f717b31d2c061b9c48074567eb8c6 + undici-types: "npm:~7.16.0" + checksum: 10c0/b7568f0d765d9469621615e2bb257c7fd1953d95e9acbdb58dffb6627a2c4150d405a4600aa1ad8a40182a94fe5f903cafd3c0a2f5132814debd0e3bfd61f835 languageName: node linkType: hard @@ -727,7 +727,7 @@ __metadata: "@react-native/typescript-config": "npm:0.74.83" "@types/uuid": "npm:^10.0.0" apisauce: "npm:^3.1.1" - casper-js-sdk: "npm:^5.0.6" + casper-js-sdk: "npm:5.0.6" date-fns: "npm:^2.30.0" decimal.js: "npm:^10.4.3" eslint: "npm:8.22.0" @@ -959,7 +959,7 @@ __metadata: languageName: node linkType: hard -"axios@npm:^1.7.7, axios@npm:^1.8.4": +"axios@npm:^1.7.7": version: 1.9.0 resolution: "axios@npm:1.9.0" dependencies: @@ -970,6 +970,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:^1.8.4": + version: 1.13.2 + resolution: "axios@npm:1.13.2" + dependencies: + follow-redirects: "npm:^1.15.6" + form-data: "npm:^4.0.4" + proxy-from-env: "npm:^1.1.0" + checksum: 10c0/e8a42e37e5568ae9c7a28c348db0e8cf3e43d06fcbef73f0048669edfe4f71219664da7b6cc991b0c0f01c28a48f037c515263cb79be1f1ae8ff034cd813867b + languageName: node + linkType: hard + "balanced-match@npm:^1.0.0": version: 1.0.2 resolution: "balanced-match@npm:1.0.2" @@ -1086,7 +1097,7 @@ __metadata: languageName: node linkType: hard -"casper-js-sdk@npm:^5.0.6": +"casper-js-sdk@npm:5.0.6": version: 5.0.6 resolution: "casper-js-sdk@npm:5.0.6" dependencies: @@ -2015,6 +2026,19 @@ __metadata: languageName: node linkType: hard +"form-data@npm:^4.0.4": + version: 4.0.5 + resolution: "form-data@npm:4.0.5" + dependencies: + asynckit: "npm:^0.4.0" + combined-stream: "npm:^1.0.8" + es-set-tostringtag: "npm:^2.1.0" + hasown: "npm:^2.0.2" + mime-types: "npm:^2.1.12" + checksum: 10c0/dd6b767ee0bbd6d84039db12a0fa5a2028160ffbfaba1800695713b46ae974a5f6e08b3356c3195137f8530dcd9dfcb5d5ae1eeff53d0db1e5aad863b619ce3b + languageName: node + linkType: hard + "fs.realpath@npm:^1.0.0": version: 1.0.0 resolution: "fs.realpath@npm:1.0.0" @@ -2289,9 +2313,9 @@ __metadata: linkType: hard "humanize-duration@npm:^3.24.0": - version: 3.32.2 - resolution: "humanize-duration@npm:3.32.2" - checksum: 10c0/c267d69e3e1206b6326a33218a8dd4c5980adccdd750f1b3e9837719c4519e2587463e86e81fadfa8d8c0e107101b4dfcaa6dd8e99265a794c58907d266c679f + version: 3.33.2 + resolution: "humanize-duration@npm:3.33.2" + checksum: 10c0/eae493c113f1c11c96e42195002e8016ab7c08bfcc3414ba5459027da4faaa2df012429bc4eae200873a65d0a86b7cc6a9656783aa45705ffe6106b5256af973 languageName: node linkType: hard @@ -3957,10 +3981,10 @@ __metadata: languageName: node linkType: hard -"undici-types@npm:~6.21.0": - version: 6.21.0 - resolution: "undici-types@npm:6.21.0" - checksum: 10c0/c01ed51829b10aa72fc3ce64b747f8e74ae9b60eafa19a7b46ef624403508a54c526ffab06a14a26b3120d055e1104d7abe7c9017e83ced038ea5cf52f8d5e04 +"undici-types@npm:~7.16.0": + version: 7.16.0 + resolution: "undici-types@npm:7.16.0" + checksum: 10c0/3033e2f2b5c9f1504bdc5934646cb54e37ecaca0f9249c983f7b1fc2e87c6d18399ebb05dc7fd5419e02b2e915f734d872a65da2e3eeed1813951c427d33cc9a languageName: node linkType: hard