From 3c866ca93cf74d96e0535602bc7898b98b642d6f Mon Sep 17 00:00:00 2001 From: Anson Date: Sat, 3 Aug 2024 01:13:25 +0100 Subject: [PATCH] feat: use lit-contracts --- .../nodejs/package.json | 15 +- .../nodejs/src/abis/PaymentDelegation.abi | 606 -------- .../nodejs/src/abis/RateLimitNFT.abi | 1385 ----------------- .../nodejs/src/addUsers.ts | 90 +- 4 files changed, 86 insertions(+), 2010 deletions(-) delete mode 100644 payment-delegation-db-relayer/nodejs/src/abis/PaymentDelegation.abi delete mode 100644 payment-delegation-db-relayer/nodejs/src/abis/RateLimitNFT.abi diff --git a/payment-delegation-db-relayer/nodejs/package.json b/payment-delegation-db-relayer/nodejs/package.json index aa9753cd..06674638 100644 --- a/payment-delegation-db-relayer/nodejs/package.json +++ b/payment-delegation-db-relayer/nodejs/package.json @@ -24,13 +24,14 @@ }, "dependencies": { "@dotenvx/dotenvx": "^0.44.1", - "@lit-protocol/auth-helpers": "^6.3.0", - "@lit-protocol/constants": "^6.3.0", - "@lit-protocol/contracts-sdk": "^6.3.0", - "@lit-protocol/lit-auth-client": "^6.3.0", - "@lit-protocol/lit-node-client": "^6.3.0", - "@lit-protocol/types": "^6.3.0", - "@lit-protocol/wrapped-keys": "^6.3.0", + "@lit-protocol/auth-helpers": "^6.4.0", + "@lit-protocol/constants": "^6.4.0", + "@lit-protocol/contracts": "^0.0.41", + "@lit-protocol/contracts-sdk": "^6.4.0", + "@lit-protocol/lit-auth-client": "^6.4.0", + "@lit-protocol/lit-node-client": "^6.4.0", + "@lit-protocol/types": "^6.4.0", + "@lit-protocol/wrapped-keys": "^6.4.0", "ethers": "v5" } } diff --git a/payment-delegation-db-relayer/nodejs/src/abis/PaymentDelegation.abi b/payment-delegation-db-relayer/nodejs/src/abis/PaymentDelegation.abi deleted file mode 100644 index 6aa317ee..00000000 --- a/payment-delegation-db-relayer/nodejs/src/abis/PaymentDelegation.abi +++ /dev/null @@ -1,606 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotAddFunctionToDiamondThatAlreadyExists", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4[]", - "name": "_selectors", - "type": "bytes4[]" - } - ], - "name": "CannotAddSelectorsToZeroAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotRemoveFunctionThatDoesNotExist", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotRemoveImmutableFunction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceFunctionThatDoesNotExists", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4[]", - "name": "_selectors", - "type": "bytes4[]" - } - ], - "name": "CannotReplaceFunctionsFromFacetWithZeroAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceImmutableFunction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "_action", - "type": "uint8" - } - ], - "name": "IncorrectFacetCutAction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_initializationContractAddress", - "type": "address" - }, - { - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "InitializationFunctionReverted", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_contractAddress", - "type": "address" - }, - { - "internalType": "string", - "name": "_message", - "type": "string" - } - ], - "name": "NoBytecodeAtAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facetAddress", - "type": "address" - } - ], - "name": "NoSelectorsProvidedForFacetForCut", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_user", - "type": "address" - }, - { - "internalType": "address", - "name": "_contractOwner", - "type": "address" - } - ], - "name": "NotContractOwner", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facetAddress", - "type": "address" - } - ], - "name": "RemoveFacetAddressMustBeZeroAddress", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "enum IDiamond.FacetCutAction", - "name": "action", - "type": "uint8" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "indexed": false, - "internalType": "struct IDiamond.FacetCut[]", - "name": "_diamondCut", - "type": "tuple[]" - }, - { - "indexed": false, - "internalType": "address", - "name": "_init", - "type": "address" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "DiamondCut", - "type": "event" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "enum IDiamond.FacetCutAction", - "name": "action", - "type": "uint8" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "internalType": "struct IDiamond.FacetCut[]", - "name": "_diamondCut", - "type": "tuple[]" - }, - { - "internalType": "address", - "name": "_init", - "type": "address" - }, - { - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "diamondCut", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_functionSelector", - "type": "bytes4" - } - ], - "name": "facetAddress", - "outputs": [ - { - "internalType": "address", - "name": "facetAddress_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "facetAddresses", - "outputs": [ - { - "internalType": "address[]", - "name": "facetAddresses_", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facet", - "type": "address" - } - ], - "name": "facetFunctionSelectors", - "outputs": [ - { - "internalType": "bytes4[]", - "name": "_facetFunctionSelectors", - "type": "bytes4[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "facets", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "internalType": "struct IDiamondLoupe.Facet[]", - "name": "facets_", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "owner_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "payer", - "type": "address" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "requestsPerPeriod", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "periodSeconds", - "type": "uint256" - } - ], - "indexed": false, - "internalType": "struct LibPaymentDelegationStorage.Restriction", - "name": "restriction", - "type": "tuple" - } - ], - "name": "RestrictionSet", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "delegatePayments", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "users", - "type": "address[]" - } - ], - "name": "delegatePaymentsBatch", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "getPayers", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "users", - "type": "address[]" - } - ], - "name": "getPayersAndRestrictions", - "outputs": [ - { - "internalType": "address[][]", - "name": "", - "type": "address[][]" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "requestsPerPeriod", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "periodSeconds", - "type": "uint256" - } - ], - "internalType": "struct LibPaymentDelegationStorage.Restriction[][]", - "name": "", - "type": "tuple[][]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "payer", - "type": "address" - } - ], - "name": "getRestriction", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "requestsPerPeriod", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "periodSeconds", - "type": "uint256" - } - ], - "internalType": "struct LibPaymentDelegationStorage.Restriction", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "payer", - "type": "address" - } - ], - "name": "getUsers", - "outputs": [ - { - "internalType": "address[]", - "name": "", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "requestsPerPeriod", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "periodSeconds", - "type": "uint256" - } - ], - "internalType": "struct LibPaymentDelegationStorage.Restriction", - "name": "r", - "type": "tuple" - } - ], - "name": "setRestriction", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "user", - "type": "address" - } - ], - "name": "undelegatePayments", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "users", - "type": "address[]" - } - ], - "name": "undelegatePaymentsBatch", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/payment-delegation-db-relayer/nodejs/src/abis/RateLimitNFT.abi b/payment-delegation-db-relayer/nodejs/src/abis/RateLimitNFT.abi deleted file mode 100644 index 94d8d4ed..00000000 --- a/payment-delegation-db-relayer/nodejs/src/abis/RateLimitNFT.abi +++ /dev/null @@ -1,1385 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotAddFunctionToDiamondThatAlreadyExists", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4[]", - "name": "_selectors", - "type": "bytes4[]" - } - ], - "name": "CannotAddSelectorsToZeroAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotRemoveFunctionThatDoesNotExist", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotRemoveImmutableFunction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceFunctionThatDoesNotExists", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4[]", - "name": "_selectors", - "type": "bytes4[]" - } - ], - "name": "CannotReplaceFunctionsFromFacetWithZeroAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_selector", - "type": "bytes4" - } - ], - "name": "CannotReplaceImmutableFunction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "_action", - "type": "uint8" - } - ], - "name": "IncorrectFacetCutAction", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_initializationContractAddress", - "type": "address" - }, - { - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "InitializationFunctionReverted", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_contractAddress", - "type": "address" - }, - { - "internalType": "string", - "name": "_message", - "type": "string" - } - ], - "name": "NoBytecodeAtAddress", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facetAddress", - "type": "address" - } - ], - "name": "NoSelectorsProvidedForFacetForCut", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_user", - "type": "address" - }, - { - "internalType": "address", - "name": "_contractOwner", - "type": "address" - } - ], - "name": "NotContractOwner", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facetAddress", - "type": "address" - } - ], - "name": "RemoveFacetAddressMustBeZeroAddress", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "enum IDiamond.FacetCutAction", - "name": "action", - "type": "uint8" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "indexed": false, - "internalType": "struct IDiamond.FacetCut[]", - "name": "_diamondCut", - "type": "tuple[]" - }, - { - "indexed": false, - "internalType": "address", - "name": "_init", - "type": "address" - }, - { - "indexed": false, - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "DiamondCut", - "type": "event" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "enum IDiamond.FacetCutAction", - "name": "action", - "type": "uint8" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "internalType": "struct IDiamond.FacetCut[]", - "name": "_diamondCut", - "type": "tuple[]" - }, - { - "internalType": "address", - "name": "_init", - "type": "address" - }, - { - "internalType": "bytes", - "name": "_calldata", - "type": "bytes" - } - ], - "name": "diamondCut", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "_functionSelector", - "type": "bytes4" - } - ], - "name": "facetAddress", - "outputs": [ - { - "internalType": "address", - "name": "facetAddress_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "facetAddresses", - "outputs": [ - { - "internalType": "address[]", - "name": "facetAddresses_", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_facet", - "type": "address" - } - ], - "name": "facetFunctionSelectors", - "outputs": [ - { - "internalType": "bytes4[]", - "name": "_facetFunctionSelectors", - "type": "bytes4[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "facets", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "facetAddress", - "type": "address" - }, - { - "internalType": "bytes4[]", - "name": "functionSelectors", - "type": "bytes4[]" - } - ], - "internalType": "struct IDiamondLoupe.Facet[]", - "name": "facets_", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "owner_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "CallerNotOwner", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "newAdditionalRequestsPerKilosecondCost", - "type": "uint256" - } - ], - "name": "AdditionalRequestsPerKilosecondCostSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "approved", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "operator", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "approved", - "type": "bool" - } - ], - "name": "ApprovalForAll", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "newFreeMintSigner", - "type": "address" - } - ], - "name": "FreeMintSignerSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "newFreeRequestsPerRateLimitWindow", - "type": "uint256" - } - ], - "name": "FreeRequestsPerRateLimitWindowSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "newRLIHolderRateLimitWindowSeconds", - "type": "uint256" - } - ], - "name": "RLIHolderRateLimitWindowSecondsSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "newRateLimitWindowSeconds", - "type": "uint256" - } - ], - "name": "RateLimitWindowSecondsSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "Withdrew", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "burn", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "requestsPerKilosecond", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "msgHash", - "type": "bytes32" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "sVal", - "type": "bytes32" - } - ], - "name": "freeMint", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "getApproved", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "operator", - "type": "address" - } - ], - "name": "isApprovedForAll", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - } - ], - "name": "mint", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "ownerOf", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "safeTransferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "safeTransferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newAdditionalRequestsPerKilosecondCost", - "type": "uint256" - } - ], - "name": "setAdditionalRequestsPerKilosecondCost", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "operator", - "type": "address" - }, - { - "internalType": "bool", - "name": "approved", - "type": "bool" - } - ], - "name": "setApprovalForAll", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newFreeMintSigner", - "type": "address" - } - ], - "name": "setFreeMintSigner", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newFreeRequestsPerRateLimitWindow", - "type": "uint256" - } - ], - "name": "setFreeRequestsPerRateLimitWindow", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newMaxExpirationSeconds", - "type": "uint256" - } - ], - "name": "setMaxExpirationSeconds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newMaxRequestsPerKilosecond", - "type": "uint256" - } - ], - "name": "setMaxRequestsPerKilosecond", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newRLIHolderRateLimitWindowSeconds", - "type": "uint256" - } - ], - "name": "setRLIHolderRateLimitWindowSeconds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "newRateLimitWindowSeconds", - "type": "uint256" - } - ], - "name": "setRateLimitWindowSeconds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "tokenByIndex", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "uint256", - "name": "index", - "type": "uint256" - } - ], - "name": "tokenOfOwnerByIndex", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "tokenURI", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "withdraw", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "RLIHolderRateLimitWindowSeconds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "additionalRequestsPerKilosecondCost", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "requestsPerKilosecond", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - } - ], - "name": "calculateCost", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "payingAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - } - ], - "name": "calculateRequestsPerKilosecond", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "capacity", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "requestsPerKilosecond", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - } - ], - "internalType": "struct LibRateLimitNFTStorage.RateLimit", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "requestedRequestsPerKilosecond", - "type": "uint256" - } - ], - "name": "checkBelowMaxRequestsPerKilosecond", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "currentSoldRequestsPerKilosecond", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "defaultRateLimitWindowSeconds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "requestsPerKilosecond", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "msgHash", - "type": "bytes32" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "sVal", - "type": "bytes32" - } - ], - "name": "freeMintSigTest", - "outputs": [], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "freeMintSigner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "freeRequestsPerRateLimitWindow", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "isExpired", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxExpirationSeconds", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxRequestsPerKilosecond", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "hash", - "type": "bytes32" - } - ], - "name": "prefixed", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "msgHash", - "type": "bytes32" - } - ], - "name": "redeemedFreeMints", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "tokenIdCounter", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "tokenSVG", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "expiresAt", - "type": "uint256" - } - ], - "name": "totalSoldRequestsPerKilosecondByExpirationTime", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - } -] diff --git a/payment-delegation-db-relayer/nodejs/src/addUsers.ts b/payment-delegation-db-relayer/nodejs/src/addUsers.ts index 76e6e288..66c8269f 100644 --- a/payment-delegation-db-relayer/nodejs/src/addUsers.ts +++ b/payment-delegation-db-relayer/nodejs/src/addUsers.ts @@ -1,6 +1,10 @@ import { ethers } from "ethers"; import fs from "fs"; +import { datil, datilTest, datilDev } from "@lit-protocol/contracts"; +import { add } from "@lit-protocol/contracts-sdk/src/lib/hex2dec"; +import { LIT_NETWORK_VALUES } from "@lit-protocol/constants"; + const getEnv = (name: string): string => { const env = process.env[name]; if (env === undefined || env === "") @@ -16,6 +20,75 @@ const LIT_RELAYER_API_KEY = getEnv("LIT_RELAYER_API_KEY"); const ETHEREUM_PRIVATE_KEY = getEnv("ETHEREUM_PRIVATE_KEY"); const REQUESTS_PER_KILOSECOND = 1000000; +const getPaymentDelegationContext = ( + networkContext: typeof datil | typeof datilTest | typeof datilDev +) => { + const contract = networkContext.data.find( + (d) => d.name === "PaymentDelegation" + )?.contracts[0]; + + if (!contract) { + throw new Error(`Contract not found in network context`); + } + + return { + address: contract.address_hash, + abi: contract.ABI, + }; +}; + +const getRateLimitContext = ( + networkContext: typeof datil | typeof datilTest | typeof datilDev +) => { + const contract = networkContext.data.find((d) => d.name === "RateLimitNFT") + ?.contracts[0]; + + if (!contract) { + throw new Error(`Contract not found in network context`); + } + + return { + address: contract.address_hash, + abi: contract.ABI, + }; +}; + +const PAYMENT_DB_BY_NETWORK: Record< + LIT_NETWORK_VALUES, + { address: string; abi: any } +> = { + datil: { + address: getPaymentDelegationContext(datil).address, + abi: getPaymentDelegationContext(datil).abi, + }, + "datil-test": { + address: getPaymentDelegationContext(datilTest).address, + abi: getPaymentDelegationContext(datilTest).abi, + }, + "datil-dev": { + address: getPaymentDelegationContext(datilDev).address, + abi: getPaymentDelegationContext(datilDev).abi, + }, +} as const; + +const RATE_LIMIT_BY_NETWORK: Record< + LIT_NETWORK_VALUES, + { address: string; abi: any } +> = { + datil: { + address: getRateLimitContext(datil).address, + abi: getRateLimitContext(datil).abi, + }, + "datil-test": { + address: getRateLimitContext(datilTest).address, + abi: getRateLimitContext(datilTest).abi, + }, + "datil-dev": { + address: getRateLimitContext(datilDev).address, + abi: getRateLimitContext(datilDev).abi, + }, +} as const; + interface AddUserResponse { success: boolean; error?: string; @@ -49,13 +122,9 @@ export const addUsers = async (users: string[]) => { ); const wallet = new ethers.Wallet(ETHEREUM_PRIVATE_KEY, provider); - const PaymentDbAbi = fs.readFileSync( - "./src/abis/PaymentDelegation.abi", - "utf-8" - ); const paymentDbContract = new ethers.Contract( - "0xd7188e0348F1dA8c9b3d6e614844cbA22329B99E", - PaymentDbAbi, + PAYMENT_DB_BY_NETWORK[LIT_NETWORK].address, + PAYMENT_DB_BY_NETWORK[LIT_NETWORK].abi, wallet ); @@ -72,13 +141,10 @@ export const addUsers = async (users: string[]) => { console.log("✅ Added restriction"); console.log(`🔄 Minting a rate limit NFT`); - const rateLimitAbi = fs.readFileSync( - "./src/abis/RateLimitNFT.abi", - "utf-8" - ); + const rateLimitContract = new ethers.Contract( - "0xa17f11B7f828EEc97926E56D98D5AB63A0231b77", - rateLimitAbi, + RATE_LIMIT_BY_NETWORK[LIT_NETWORK].address, + RATE_LIMIT_BY_NETWORK[LIT_NETWORK].abi, wallet );