@towns-labs/web3 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/BaseContractShim.d.ts +57 -0
- package/dist/BaseContractShim.d.ts.map +1 -0
- package/dist/BaseContractShim.js +224 -0
- package/dist/BaseContractShim.js.map +1 -0
- package/dist/airdrop/IDropFacetShim.d.ts +9 -0
- package/dist/airdrop/IDropFacetShim.d.ts.map +1 -0
- package/dist/airdrop/IDropFacetShim.js +9 -0
- package/dist/airdrop/IDropFacetShim.js.map +1 -0
- package/dist/airdrop/IRiverPointsShim.d.ts +9 -0
- package/dist/airdrop/IRiverPointsShim.d.ts.map +1 -0
- package/dist/airdrop/IRiverPointsShim.js +9 -0
- package/dist/airdrop/IRiverPointsShim.js.map +1 -0
- package/dist/airdrop/RiverAirdropDapp.d.ts +16 -0
- package/dist/airdrop/RiverAirdropDapp.d.ts.map +1 -0
- package/dist/airdrop/RiverAirdropDapp.js +30 -0
- package/dist/airdrop/RiverAirdropDapp.js.map +1 -0
- package/dist/app-registry/AppRegistryDapp.d.ts +68 -0
- package/dist/app-registry/AppRegistryDapp.d.ts.map +1 -0
- package/dist/app-registry/AppRegistryDapp.js +182 -0
- package/dist/app-registry/AppRegistryDapp.js.map +1 -0
- package/dist/app-registry/IAppFactoryShim.d.ts +9 -0
- package/dist/app-registry/IAppFactoryShim.d.ts.map +1 -0
- package/dist/app-registry/IAppFactoryShim.js +9 -0
- package/dist/app-registry/IAppFactoryShim.js.map +1 -0
- package/dist/app-registry/IAppInstallerShim.d.ts +9 -0
- package/dist/app-registry/IAppInstallerShim.d.ts.map +1 -0
- package/dist/app-registry/IAppInstallerShim.js +9 -0
- package/dist/app-registry/IAppInstallerShim.js.map +1 -0
- package/dist/app-registry/IAppRegistryShim.d.ts +9 -0
- package/dist/app-registry/IAppRegistryShim.d.ts.map +1 -0
- package/dist/app-registry/IAppRegistryShim.js +9 -0
- package/dist/app-registry/IAppRegistryShim.js.map +1 -0
- package/dist/app-registry/IIdentityRegistryShim.d.ts +9 -0
- package/dist/app-registry/IIdentityRegistryShim.d.ts.map +1 -0
- package/dist/app-registry/IIdentityRegistryShim.js +9 -0
- package/dist/app-registry/IIdentityRegistryShim.js.map +1 -0
- package/dist/app-registry/IReputationRegistryShim.d.ts +9 -0
- package/dist/app-registry/IReputationRegistryShim.d.ts.map +1 -0
- package/dist/app-registry/IReputationRegistryShim.js +9 -0
- package/dist/app-registry/IReputationRegistryShim.js.map +1 -0
- package/dist/app-registry/SimpleAppShim.d.ts +9 -0
- package/dist/app-registry/SimpleAppShim.d.ts.map +1 -0
- package/dist/app-registry/SimpleAppShim.js +9 -0
- package/dist/app-registry/SimpleAppShim.js.map +1 -0
- package/dist/base-registry/BaseRegistry.d.ts +32 -0
- package/dist/base-registry/BaseRegistry.d.ts.map +1 -0
- package/dist/base-registry/BaseRegistry.js +67 -0
- package/dist/base-registry/BaseRegistry.js.map +1 -0
- package/dist/base-registry/IEntitlementCheckerShim.d.ts +9 -0
- package/dist/base-registry/IEntitlementCheckerShim.d.ts.map +1 -0
- package/dist/base-registry/IEntitlementCheckerShim.js +9 -0
- package/dist/base-registry/IEntitlementCheckerShim.js.map +1 -0
- package/dist/base-registry/INodeOperatorShim.d.ts +9 -0
- package/dist/base-registry/INodeOperatorShim.d.ts.map +1 -0
- package/dist/base-registry/INodeOperatorShim.js +9 -0
- package/dist/base-registry/INodeOperatorShim.js.map +1 -0
- package/dist/base-registry/ISpaceDelegationShim.d.ts +9 -0
- package/dist/base-registry/ISpaceDelegationShim.d.ts.map +1 -0
- package/dist/base-registry/ISpaceDelegationShim.js +9 -0
- package/dist/base-registry/ISpaceDelegationShim.js.map +1 -0
- package/dist/base-registry/RewardsDistributionShim.d.ts +9 -0
- package/dist/base-registry/RewardsDistributionShim.d.ts.map +1 -0
- package/dist/base-registry/RewardsDistributionShim.js +9 -0
- package/dist/base-registry/RewardsDistributionShim.js.map +1 -0
- package/dist/cache/EntitlementCache.d.ts +25 -0
- package/dist/cache/EntitlementCache.d.ts.map +1 -0
- package/dist/cache/EntitlementCache.js +91 -0
- package/dist/cache/EntitlementCache.js.map +1 -0
- package/dist/cache/ICacheStorage.d.ts +44 -0
- package/dist/cache/ICacheStorage.d.ts.map +1 -0
- package/dist/cache/ICacheStorage.js +2 -0
- package/dist/cache/ICacheStorage.js.map +1 -0
- package/dist/cache/KVCacheStorage.d.ts +79 -0
- package/dist/cache/KVCacheStorage.d.ts.map +1 -0
- package/dist/cache/KVCacheStorage.js +227 -0
- package/dist/cache/KVCacheStorage.js.map +1 -0
- package/dist/cache/Keyable.d.ts +20 -0
- package/dist/cache/Keyable.d.ts.map +1 -0
- package/dist/cache/Keyable.js +62 -0
- package/dist/cache/Keyable.js.map +1 -0
- package/dist/cache/SimpleCache.d.ts +30 -0
- package/dist/cache/SimpleCache.d.ts.map +1 -0
- package/dist/cache/SimpleCache.js +84 -0
- package/dist/cache/SimpleCache.js.map +1 -0
- package/dist/cache/TTLCacheStorage.d.ts +19 -0
- package/dist/cache/TTLCacheStorage.d.ts.map +1 -0
- package/dist/cache/TTLCacheStorage.js +40 -0
- package/dist/cache/TTLCacheStorage.js.map +1 -0
- package/dist/chain.d.ts +89 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +48 -0
- package/dist/chain.js.map +1 -0
- package/dist/delegate-registry/DelegateRegistry.d.ts +3 -0
- package/dist/delegate-registry/DelegateRegistry.d.ts.map +1 -0
- package/dist/delegate-registry/DelegateRegistry.js +72 -0
- package/dist/delegate-registry/DelegateRegistry.js.map +1 -0
- package/dist/eip-712/EIP-712.d.ts +35 -0
- package/dist/eip-712/EIP-712.d.ts.map +1 -0
- package/dist/eip-712/EIP-712.js +57 -0
- package/dist/eip-712/EIP-712.js.map +1 -0
- package/dist/erc-721/IERC721AQueryableShim.d.ts +9 -0
- package/dist/erc-721/IERC721AQueryableShim.d.ts.map +1 -0
- package/dist/erc-721/IERC721AQueryableShim.js +9 -0
- package/dist/erc-721/IERC721AQueryableShim.js.map +1 -0
- package/dist/erc-721/IERC721AShim.d.ts +9 -0
- package/dist/erc-721/IERC721AShim.d.ts.map +1 -0
- package/dist/erc-721/IERC721AShim.js +9 -0
- package/dist/erc-721/IERC721AShim.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/platform-requirements/PlatformRequirements.d.ts +12 -0
- package/dist/platform-requirements/PlatformRequirements.d.ts.map +1 -0
- package/dist/platform-requirements/PlatformRequirements.js +18 -0
- package/dist/platform-requirements/PlatformRequirements.js.map +1 -0
- package/dist/pricing-modules/IPricingShim.d.ts +9 -0
- package/dist/pricing-modules/IPricingShim.d.ts.map +1 -0
- package/dist/pricing-modules/IPricingShim.js +9 -0
- package/dist/pricing-modules/IPricingShim.js.map +1 -0
- package/dist/pricing-modules/PricingModules.d.ts +13 -0
- package/dist/pricing-modules/PricingModules.d.ts.map +1 -0
- package/dist/pricing-modules/PricingModules.js +23 -0
- package/dist/pricing-modules/PricingModules.js.map +1 -0
- package/dist/pricing-modules/helpers.d.ts +16 -0
- package/dist/pricing-modules/helpers.d.ts.map +1 -0
- package/dist/pricing-modules/helpers.js +35 -0
- package/dist/pricing-modules/helpers.js.map +1 -0
- package/dist/readContractRetryer.d.ts +10 -0
- package/dist/readContractRetryer.d.ts.map +1 -0
- package/dist/readContractRetryer.js +68 -0
- package/dist/readContractRetryer.js.map +1 -0
- package/dist/river-registry/INodeRegistryShim.d.ts +9 -0
- package/dist/river-registry/INodeRegistryShim.d.ts.map +1 -0
- package/dist/river-registry/INodeRegistryShim.js +9 -0
- package/dist/river-registry/INodeRegistryShim.js.map +1 -0
- package/dist/river-registry/IOperatorRegistryShim.d.ts +9 -0
- package/dist/river-registry/IOperatorRegistryShim.d.ts.map +1 -0
- package/dist/river-registry/IOperatorRegistryShim.js +9 -0
- package/dist/river-registry/IOperatorRegistryShim.js.map +1 -0
- package/dist/river-registry/IStreamRegistryShim.d.ts +9 -0
- package/dist/river-registry/IStreamRegistryShim.d.ts.map +1 -0
- package/dist/river-registry/IStreamRegistryShim.js +9 -0
- package/dist/river-registry/IStreamRegistryShim.js.map +1 -0
- package/dist/river-registry/RiverRegistry.d.ts +18 -0
- package/dist/river-registry/RiverRegistry.d.ts.map +1 -0
- package/dist/river-registry/RiverRegistry.js +42 -0
- package/dist/river-registry/RiverRegistry.js.map +1 -0
- package/dist/river-registry/RiverRegistryFactory.d.ts +5 -0
- package/dist/river-registry/RiverRegistryFactory.d.ts.map +1 -0
- package/dist/river-registry/RiverRegistryFactory.js +5 -0
- package/dist/river-registry/RiverRegistryFactory.js.map +1 -0
- package/dist/space/IAppAccountShim.d.ts +9 -0
- package/dist/space/IAppAccountShim.d.ts.map +1 -0
- package/dist/space/IAppAccountShim.js +9 -0
- package/dist/space/IAppAccountShim.js.map +1 -0
- package/dist/space/IBanningShim.d.ts +9 -0
- package/dist/space/IBanningShim.d.ts.map +1 -0
- package/dist/space/IBanningShim.js +9 -0
- package/dist/space/IBanningShim.js.map +1 -0
- package/dist/space/IChannelShim.d.ts +9 -0
- package/dist/space/IChannelShim.d.ts.map +1 -0
- package/dist/space/IChannelShim.js +9 -0
- package/dist/space/IChannelShim.js.map +1 -0
- package/dist/space/IEntitlementDataQueryableShim.d.ts +11 -0
- package/dist/space/IEntitlementDataQueryableShim.d.ts.map +1 -0
- package/dist/space/IEntitlementDataQueryableShim.js +9 -0
- package/dist/space/IEntitlementDataQueryableShim.js.map +1 -0
- package/dist/space/IEntitlementsShim.d.ts +13 -0
- package/dist/space/IEntitlementsShim.d.ts.map +1 -0
- package/dist/space/IEntitlementsShim.js +19 -0
- package/dist/space/IEntitlementsShim.js.map +1 -0
- package/dist/space/IMembershipMetadataShim.d.ts +9 -0
- package/dist/space/IMembershipMetadataShim.d.ts.map +1 -0
- package/dist/space/IMembershipMetadataShim.js +9 -0
- package/dist/space/IMembershipMetadataShim.js.map +1 -0
- package/dist/space/IMembershipShim.d.ts +33 -0
- package/dist/space/IMembershipShim.d.ts.map +1 -0
- package/dist/space/IMembershipShim.js +139 -0
- package/dist/space/IMembershipShim.js.map +1 -0
- package/dist/space/IMulticallShim.d.ts +13 -0
- package/dist/space/IMulticallShim.d.ts.map +1 -0
- package/dist/space/IMulticallShim.js +15 -0
- package/dist/space/IMulticallShim.js.map +1 -0
- package/dist/space/IReviewShim.d.ts +64 -0
- package/dist/space/IReviewShim.d.ts.map +1 -0
- package/dist/space/IReviewShim.js +102 -0
- package/dist/space/IReviewShim.js.map +1 -0
- package/dist/space/IRolesShim.d.ts +10 -0
- package/dist/space/IRolesShim.d.ts.map +1 -0
- package/dist/space/IRolesShim.js +9 -0
- package/dist/space/IRolesShim.js.map +1 -0
- package/dist/space/ITippingShim.d.ts +39 -0
- package/dist/space/ITippingShim.d.ts.map +1 -0
- package/dist/space/ITippingShim.js +76 -0
- package/dist/space/ITippingShim.js.map +1 -0
- package/dist/space/ITreasuryShim.d.ts +9 -0
- package/dist/space/ITreasuryShim.d.ts.map +1 -0
- package/dist/space/ITreasuryShim.js +9 -0
- package/dist/space/ITreasuryShim.js.map +1 -0
- package/dist/space/OwnableFacetShim.d.ts +12 -0
- package/dist/space/OwnableFacetShim.d.ts.map +1 -0
- package/dist/space/OwnableFacetShim.js +19 -0
- package/dist/space/OwnableFacetShim.js.map +1 -0
- package/dist/space/Space.d.ts +107 -0
- package/dist/space/Space.d.ts.map +1 -0
- package/dist/space/Space.js +511 -0
- package/dist/space/Space.js.map +1 -0
- package/dist/space/TokenPausableFacetShim.d.ts +9 -0
- package/dist/space/TokenPausableFacetShim.d.ts.map +1 -0
- package/dist/space/TokenPausableFacetShim.js +9 -0
- package/dist/space/TokenPausableFacetShim.js.map +1 -0
- package/dist/space/entitlements/ConvertersEntitlements.d.ts +14 -0
- package/dist/space/entitlements/ConvertersEntitlements.d.ts.map +1 -0
- package/dist/space/entitlements/ConvertersEntitlements.js +193 -0
- package/dist/space/entitlements/ConvertersEntitlements.js.map +1 -0
- package/dist/space/entitlements/RuleBuilder.d.ts +83 -0
- package/dist/space/entitlements/RuleBuilder.d.ts.map +1 -0
- package/dist/space/entitlements/RuleBuilder.js +86 -0
- package/dist/space/entitlements/RuleBuilder.js.map +1 -0
- package/dist/space/entitlements/RuleEntitlementShim.d.ts +353 -0
- package/dist/space/entitlements/RuleEntitlementShim.d.ts.map +1 -0
- package/dist/space/entitlements/RuleEntitlementShim.js +40 -0
- package/dist/space/entitlements/RuleEntitlementShim.js.map +1 -0
- package/dist/space/entitlements/RuleEntitlementV2Shim.d.ts +353 -0
- package/dist/space/entitlements/RuleEntitlementV2Shim.d.ts.map +1 -0
- package/dist/space/entitlements/RuleEntitlementV2Shim.js +40 -0
- package/dist/space/entitlements/RuleEntitlementV2Shim.js.map +1 -0
- package/dist/space/entitlements/UserEntitlementShim.d.ts +13 -0
- package/dist/space/entitlements/UserEntitlementShim.d.ts.map +1 -0
- package/dist/space/entitlements/UserEntitlementShim.js +45 -0
- package/dist/space/entitlements/UserEntitlementShim.js.map +1 -0
- package/dist/space/entitlements/XChainConfig.d.ts +14 -0
- package/dist/space/entitlements/XChainConfig.d.ts.map +1 -0
- package/dist/space/entitlements/XChainConfig.js +70 -0
- package/dist/space/entitlements/XChainConfig.js.map +1 -0
- package/dist/space/entitlements/entitlement.d.ts +147 -0
- package/dist/space/entitlements/entitlement.d.ts.map +1 -0
- package/dist/space/entitlements/entitlement.js +940 -0
- package/dist/space/entitlements/entitlement.js.map +1 -0
- package/dist/space/entitlements/validateAndParseXChainConfig.d.ts +6 -0
- package/dist/space/entitlements/validateAndParseXChainConfig.d.ts.map +1 -0
- package/dist/space/entitlements/validateAndParseXChainConfig.js +34 -0
- package/dist/space/entitlements/validateAndParseXChainConfig.js.map +1 -0
- package/dist/space-dapp/SpaceDapp.d.ts +223 -0
- package/dist/space-dapp/SpaceDapp.d.ts.map +1 -0
- package/dist/space-dapp/SpaceDapp.js +1260 -0
- package/dist/space-dapp/SpaceDapp.js.map +1 -0
- package/dist/space-dapp/SpaceDappFactory.d.ts +5 -0
- package/dist/space-dapp/SpaceDappFactory.d.ts.map +1 -0
- package/dist/space-dapp/SpaceDappFactory.js +8 -0
- package/dist/space-dapp/SpaceDappFactory.js.map +1 -0
- package/dist/space-dapp/wrapTransaction.d.ts +4 -0
- package/dist/space-dapp/wrapTransaction.d.ts.map +1 -0
- package/dist/space-dapp/wrapTransaction.js +99 -0
- package/dist/space-dapp/wrapTransaction.js.map +1 -0
- package/dist/space-owner/GuardianFacetShim.d.ts +9 -0
- package/dist/space-owner/GuardianFacetShim.d.ts.map +1 -0
- package/dist/space-owner/GuardianFacetShim.js +9 -0
- package/dist/space-owner/GuardianFacetShim.js.map +1 -0
- package/dist/space-owner/SpaceOwner.d.ts +48 -0
- package/dist/space-owner/SpaceOwner.d.ts.map +1 -0
- package/dist/space-owner/SpaceOwner.js +81 -0
- package/dist/space-owner/SpaceOwner.js.map +1 -0
- package/dist/space-registrar/ICreateSpaceShim.d.ts +11 -0
- package/dist/space-registrar/ICreateSpaceShim.d.ts.map +1 -0
- package/dist/space-registrar/ICreateSpaceShim.js +9 -0
- package/dist/space-registrar/ICreateSpaceShim.js.map +1 -0
- package/dist/space-registrar/ILegacySpaceArchitectShim.d.ts +10 -0
- package/dist/space-registrar/ILegacySpaceArchitectShim.d.ts.map +1 -0
- package/dist/space-registrar/ILegacySpaceArchitectShim.js +9 -0
- package/dist/space-registrar/ILegacySpaceArchitectShim.js.map +1 -0
- package/dist/space-registrar/ISpaceArchitectShim.d.ts +10 -0
- package/dist/space-registrar/ISpaceArchitectShim.d.ts.map +1 -0
- package/dist/space-registrar/ISpaceArchitectShim.js +39 -0
- package/dist/space-registrar/ISpaceArchitectShim.js.map +1 -0
- package/dist/space-registrar/SpaceRegistrar.d.ts +27 -0
- package/dist/space-registrar/SpaceRegistrar.d.ts.map +1 -0
- package/dist/space-registrar/SpaceRegistrar.js +58 -0
- package/dist/space-registrar/SpaceRegistrar.js.map +1 -0
- package/dist/test-helpers/LocalhostWeb3Provider.d.ts +19 -0
- package/dist/test-helpers/LocalhostWeb3Provider.d.ts.map +1 -0
- package/dist/test-helpers/LocalhostWeb3Provider.js +80 -0
- package/dist/test-helpers/LocalhostWeb3Provider.js.map +1 -0
- package/dist/test-helpers/MockCrossChainEntitlement.d.ts +6 -0
- package/dist/test-helpers/MockCrossChainEntitlement.d.ts.map +1 -0
- package/dist/test-helpers/MockCrossChainEntitlement.js +104 -0
- package/dist/test-helpers/MockCrossChainEntitlement.js.map +1 -0
- package/dist/test-helpers/MockERC1155.d.ts +6 -0
- package/dist/test-helpers/MockERC1155.d.ts.map +1 -0
- package/dist/test-helpers/MockERC1155.js +518 -0
- package/dist/test-helpers/MockERC1155.js.map +1 -0
- package/dist/test-helpers/MockERC20.d.ts +6 -0
- package/dist/test-helpers/MockERC20.d.ts.map +1 -0
- package/dist/test-helpers/MockERC20.js +574 -0
- package/dist/test-helpers/MockERC20.js.map +1 -0
- package/dist/test-helpers/MockERC721A.d.ts +1563 -0
- package/dist/test-helpers/MockERC721A.d.ts.map +1 -0
- package/dist/test-helpers/MockERC721A.js +1913 -0
- package/dist/test-helpers/MockERC721A.js.map +1 -0
- package/dist/test-helpers/MockERC721AShim.d.ts +9 -0
- package/dist/test-helpers/MockERC721AShim.d.ts.map +1 -0
- package/dist/test-helpers/MockERC721AShim.js +9 -0
- package/dist/test-helpers/MockERC721AShim.js.map +1 -0
- package/dist/test-helpers/TestCrossChainEntitlement.d.ts +14 -0
- package/dist/test-helpers/TestCrossChainEntitlement.d.ts.map +1 -0
- package/dist/test-helpers/TestCrossChainEntitlement.js +99 -0
- package/dist/test-helpers/TestCrossChainEntitlement.js.map +1 -0
- package/dist/test-helpers/TestEthBalance.d.ts +72 -0
- package/dist/test-helpers/TestEthBalance.d.ts.map +1 -0
- package/dist/test-helpers/TestEthBalance.js +94 -0
- package/dist/test-helpers/TestEthBalance.js.map +1 -0
- package/dist/test-helpers/TestGatingERC1155.d.ts +17 -0
- package/dist/test-helpers/TestGatingERC1155.d.ts.map +1 -0
- package/dist/test-helpers/TestGatingERC1155.js +100 -0
- package/dist/test-helpers/TestGatingERC1155.js.map +1 -0
- package/dist/test-helpers/TestGatingERC20.d.ts +17 -0
- package/dist/test-helpers/TestGatingERC20.d.ts.map +1 -0
- package/dist/test-helpers/TestGatingERC20.js +149 -0
- package/dist/test-helpers/TestGatingERC20.js.map +1 -0
- package/dist/test-helpers/TestGatingNFT.d.ts +17 -0
- package/dist/test-helpers/TestGatingNFT.d.ts.map +1 -0
- package/dist/test-helpers/TestGatingNFT.js +137 -0
- package/dist/test-helpers/TestGatingNFT.js.map +1 -0
- package/dist/test-helpers/TestGatingUtils.d.ts +15 -0
- package/dist/test-helpers/TestGatingUtils.d.ts.map +1 -0
- package/dist/test-helpers/TestGatingUtils.js +112 -0
- package/dist/test-helpers/TestGatingUtils.js.map +1 -0
- package/dist/test-helpers/utils.d.ts +22 -0
- package/dist/test-helpers/utils.d.ts.map +1 -0
- package/dist/test-helpers/utils.js +30 -0
- package/dist/test-helpers/utils.js.map +1 -0
- package/dist/towns-token/TownsToken.d.ts +17 -0
- package/dist/towns-token/TownsToken.d.ts.map +1 -0
- package/dist/towns-token/TownsToken.js +33 -0
- package/dist/towns-token/TownsToken.js.map +1 -0
- package/dist/types/ContractTypes.d.ts +240 -0
- package/dist/types/ContractTypes.d.ts.map +1 -0
- package/dist/types/ContractTypes.js +65 -0
- package/dist/types/ContractTypes.js.map +1 -0
- package/dist/types/error-types.d.ts +7 -0
- package/dist/types/error-types.d.ts.map +1 -0
- package/dist/types/error-types.js +13 -0
- package/dist/types/error-types.js.map +1 -0
- package/dist/types/typechain.d.ts +4 -0
- package/dist/types/typechain.d.ts.map +1 -0
- package/dist/types/typechain.js +2 -0
- package/dist/types/typechain.js.map +1 -0
- package/dist/types/types.d.ts +29 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/ContractHelpers.d.ts +14 -0
- package/dist/utils/ContractHelpers.d.ts.map +1 -0
- package/dist/utils/ContractHelpers.js +54 -0
- package/dist/utils/ContractHelpers.js.map +1 -0
- package/dist/utils/Web3Constants.d.ts +6 -0
- package/dist/utils/Web3Constants.d.ts.map +1 -0
- package/dist/utils/Web3Constants.js +7 -0
- package/dist/utils/Web3Constants.js.map +1 -0
- package/dist/utils/ut.d.ts +46 -0
- package/dist/utils/ut.d.ts.map +1 -0
- package/dist/utils/ut.js +94 -0
- package/dist/utils/ut.js.map +1 -0
- package/dist/utils/web3Env.d.ts +36 -0
- package/dist/utils/web3Env.d.ts.map +1 -0
- package/dist/utils/web3Env.js +123 -0
- package/dist/utils/web3Env.js.map +1 -0
- package/dist/wallet-link/WalletLink.d.ts +58 -0
- package/dist/wallet-link/WalletLink.d.ts.map +1 -0
- package/dist/wallet-link/WalletLink.js +226 -0
- package/dist/wallet-link/WalletLink.js.map +1 -0
- package/dist/wallet-link/WalletLinkShim.d.ts +9 -0
- package/dist/wallet-link/WalletLinkShim.d.ts.map +1 -0
- package/dist/wallet-link/WalletLinkShim.js +9 -0
- package/dist/wallet-link/WalletLinkShim.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,940 @@
|
|
|
1
|
+
import { IRuleEntitlementAbi } from './RuleEntitlementShim';
|
|
2
|
+
import { IRuleEntitlementV2Abi } from './RuleEntitlementV2Shim';
|
|
3
|
+
import { dlogger } from '@towns-labs/utils';
|
|
4
|
+
import { encodeAbiParameters, decodeAbiParameters, getAbiItem, } from 'viem';
|
|
5
|
+
import { ethers } from 'ethers';
|
|
6
|
+
import { MOCK_ADDRESS } from '../../utils/ut';
|
|
7
|
+
const log = dlogger('csb:entitlement');
|
|
8
|
+
const zeroAddress = ethers.constants.AddressZero;
|
|
9
|
+
export var OperationType;
|
|
10
|
+
(function (OperationType) {
|
|
11
|
+
OperationType[OperationType["NONE"] = 0] = "NONE";
|
|
12
|
+
OperationType[OperationType["CHECK"] = 1] = "CHECK";
|
|
13
|
+
OperationType[OperationType["LOGICAL"] = 2] = "LOGICAL";
|
|
14
|
+
})(OperationType || (OperationType = {}));
|
|
15
|
+
export var CheckOperationType;
|
|
16
|
+
(function (CheckOperationType) {
|
|
17
|
+
CheckOperationType[CheckOperationType["NONE"] = 0] = "NONE";
|
|
18
|
+
CheckOperationType[CheckOperationType["MOCK"] = 1] = "MOCK";
|
|
19
|
+
CheckOperationType[CheckOperationType["ERC20"] = 2] = "ERC20";
|
|
20
|
+
CheckOperationType[CheckOperationType["ERC721"] = 3] = "ERC721";
|
|
21
|
+
CheckOperationType[CheckOperationType["ERC1155"] = 4] = "ERC1155";
|
|
22
|
+
CheckOperationType[CheckOperationType["ISENTITLED"] = 5] = "ISENTITLED";
|
|
23
|
+
CheckOperationType[CheckOperationType["ETH_BALANCE"] = 6] = "ETH_BALANCE";
|
|
24
|
+
})(CheckOperationType || (CheckOperationType = {}));
|
|
25
|
+
function checkOpString(operation) {
|
|
26
|
+
switch (operation) {
|
|
27
|
+
case CheckOperationType.NONE:
|
|
28
|
+
return 'NONE';
|
|
29
|
+
case CheckOperationType.MOCK:
|
|
30
|
+
return 'MOCK';
|
|
31
|
+
case CheckOperationType.ERC20:
|
|
32
|
+
return 'ERC20';
|
|
33
|
+
case CheckOperationType.ERC721:
|
|
34
|
+
return 'ERC721';
|
|
35
|
+
case CheckOperationType.ERC1155:
|
|
36
|
+
return 'ERC1155';
|
|
37
|
+
case CheckOperationType.ISENTITLED:
|
|
38
|
+
return 'ISENTITLED';
|
|
39
|
+
case CheckOperationType.ETH_BALANCE:
|
|
40
|
+
return 'ETH_BALANCE';
|
|
41
|
+
default:
|
|
42
|
+
return 'UNKNOWN';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Enum for Operation oneof operation_clause
|
|
46
|
+
export var LogicalOperationType;
|
|
47
|
+
(function (LogicalOperationType) {
|
|
48
|
+
LogicalOperationType[LogicalOperationType["NONE"] = 0] = "NONE";
|
|
49
|
+
LogicalOperationType[LogicalOperationType["AND"] = 1] = "AND";
|
|
50
|
+
LogicalOperationType[LogicalOperationType["OR"] = 2] = "OR";
|
|
51
|
+
})(LogicalOperationType || (LogicalOperationType = {}));
|
|
52
|
+
export function isContractLogicalOperation(operation) {
|
|
53
|
+
return operation.opType === OperationType.LOGICAL;
|
|
54
|
+
}
|
|
55
|
+
export const NoopOperation = {
|
|
56
|
+
opType: OperationType.NONE,
|
|
57
|
+
index: 0,
|
|
58
|
+
};
|
|
59
|
+
export const NoopRuleData = {
|
|
60
|
+
operations: [],
|
|
61
|
+
checkOperations: [],
|
|
62
|
+
logicalOperations: [],
|
|
63
|
+
};
|
|
64
|
+
export const EncodedNoopRuleData = encodeRuleDataV2(NoopRuleData);
|
|
65
|
+
function isCheckOperationV2(operation) {
|
|
66
|
+
return operation.opType === OperationType.CHECK;
|
|
67
|
+
}
|
|
68
|
+
function isLogicalOperation(operation) {
|
|
69
|
+
return operation.opType === OperationType.LOGICAL;
|
|
70
|
+
}
|
|
71
|
+
function isAndOperation(operation) {
|
|
72
|
+
return operation.logicalType === LogicalOperationType.AND;
|
|
73
|
+
}
|
|
74
|
+
function isOrOperation(operation) {
|
|
75
|
+
return operation.logicalType === LogicalOperationType.OR;
|
|
76
|
+
}
|
|
77
|
+
export function postOrderArrayToTree(operations) {
|
|
78
|
+
const stack = [];
|
|
79
|
+
operations.forEach((op) => {
|
|
80
|
+
if (isLogicalOperation(op)) {
|
|
81
|
+
if (stack.length < 2) {
|
|
82
|
+
throw new Error('Invalid post-order array, missing operations');
|
|
83
|
+
}
|
|
84
|
+
// Pop the two most recent operations from the stack
|
|
85
|
+
const right = stack.pop();
|
|
86
|
+
const left = stack.pop();
|
|
87
|
+
// Ensure the operations exist
|
|
88
|
+
if (!left || !right) {
|
|
89
|
+
throw new Error('Invalid post-order array, missing operations');
|
|
90
|
+
}
|
|
91
|
+
// Update the current logical operation's children
|
|
92
|
+
if (isLogicalOperation(op)) {
|
|
93
|
+
op.leftOperation = left;
|
|
94
|
+
op.rightOperation = right;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Push the current operation back into the stack
|
|
98
|
+
stack.push(op);
|
|
99
|
+
});
|
|
100
|
+
// The last item in the stack is the root of the tree
|
|
101
|
+
const root = stack.pop();
|
|
102
|
+
if (!root) {
|
|
103
|
+
throw new Error('Invalid post-order array');
|
|
104
|
+
}
|
|
105
|
+
return root;
|
|
106
|
+
}
|
|
107
|
+
const thresholdParamsAbi = {
|
|
108
|
+
components: [
|
|
109
|
+
{
|
|
110
|
+
name: 'threshold',
|
|
111
|
+
type: 'uint256',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
name: 'thresholdParams',
|
|
115
|
+
type: 'tuple',
|
|
116
|
+
};
|
|
117
|
+
export function encodeThresholdParams(params) {
|
|
118
|
+
if (params.threshold < 0n) {
|
|
119
|
+
throw new Error(`Invalid threshold ${params.threshold}: must be greater than or equal to 0`);
|
|
120
|
+
}
|
|
121
|
+
return encodeAbiParameters([thresholdParamsAbi], [params]);
|
|
122
|
+
}
|
|
123
|
+
export function decodeThresholdParams(params) {
|
|
124
|
+
return decodeAbiParameters([thresholdParamsAbi], params)[0];
|
|
125
|
+
}
|
|
126
|
+
const erc1155ParamsAbi = {
|
|
127
|
+
components: [
|
|
128
|
+
{
|
|
129
|
+
name: 'threshold',
|
|
130
|
+
type: 'uint256',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'tokenId',
|
|
134
|
+
type: 'uint256',
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
name: 'erc1155Params',
|
|
138
|
+
type: 'tuple',
|
|
139
|
+
};
|
|
140
|
+
export function encodeERC1155Params(params) {
|
|
141
|
+
if (params.threshold < 0n) {
|
|
142
|
+
throw new Error(`Invalid threshold ${params.threshold}: must be greater than or equal to 0`);
|
|
143
|
+
}
|
|
144
|
+
if (params.tokenId < 0n) {
|
|
145
|
+
throw new Error(`Invalid tokenId ${params.tokenId}: must be greater than or equal to 0`);
|
|
146
|
+
}
|
|
147
|
+
return encodeAbiParameters([erc1155ParamsAbi], [params]);
|
|
148
|
+
}
|
|
149
|
+
export function decodeERC1155Params(params) {
|
|
150
|
+
return decodeAbiParameters([erc1155ParamsAbi], params)[0];
|
|
151
|
+
}
|
|
152
|
+
export function encodeRuleData(ruleData) {
|
|
153
|
+
const encodeRuleDataAbi = getAbiItem({
|
|
154
|
+
abi: IRuleEntitlementAbi,
|
|
155
|
+
name: 'encodeRuleData',
|
|
156
|
+
});
|
|
157
|
+
if (!encodeRuleDataAbi) {
|
|
158
|
+
throw new Error('encodeRuleData ABI not found');
|
|
159
|
+
}
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
return encodeAbiParameters(encodeRuleDataAbi.inputs, [ruleData]);
|
|
162
|
+
}
|
|
163
|
+
export function decodeRuleData(entitlementData) {
|
|
164
|
+
const getRuleDataAbi = getAbiItem({
|
|
165
|
+
abi: IRuleEntitlementAbi,
|
|
166
|
+
name: 'getRuleData',
|
|
167
|
+
});
|
|
168
|
+
if (!getRuleDataAbi) {
|
|
169
|
+
throw new Error('getRuleData ABI not found');
|
|
170
|
+
}
|
|
171
|
+
const decoded = decodeAbiParameters(getRuleDataAbi.outputs, entitlementData);
|
|
172
|
+
return decoded[0];
|
|
173
|
+
}
|
|
174
|
+
export function encodeRuleDataV2(ruleData) {
|
|
175
|
+
// If we encounter a no-op rule data, just encode as empty bytes.
|
|
176
|
+
if (ruleData.operations.length === 0) {
|
|
177
|
+
return '0x';
|
|
178
|
+
}
|
|
179
|
+
const getRuleDataV2Abi = getAbiItem({
|
|
180
|
+
abi: IRuleEntitlementV2Abi,
|
|
181
|
+
name: 'getRuleDataV2',
|
|
182
|
+
});
|
|
183
|
+
if (!getRuleDataV2Abi) {
|
|
184
|
+
throw new Error('encodeRuleDataV2 ABI not found');
|
|
185
|
+
}
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
return encodeAbiParameters(getRuleDataV2Abi.outputs, [ruleData]);
|
|
188
|
+
}
|
|
189
|
+
export function decodeRuleDataV2(entitlementData) {
|
|
190
|
+
if (entitlementData === '0x') {
|
|
191
|
+
return {
|
|
192
|
+
operations: [],
|
|
193
|
+
checkOperations: [],
|
|
194
|
+
logicalOperations: [],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const getRuleDataV2Abi = getAbiItem({
|
|
198
|
+
abi: IRuleEntitlementV2Abi,
|
|
199
|
+
name: 'getRuleDataV2',
|
|
200
|
+
});
|
|
201
|
+
if (!getRuleDataV2Abi) {
|
|
202
|
+
throw new Error('encodeRuleDataV2 ABI not found');
|
|
203
|
+
}
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
const decoded = decodeAbiParameters(getRuleDataV2Abi.outputs, entitlementData);
|
|
206
|
+
return decoded[0];
|
|
207
|
+
}
|
|
208
|
+
export function ruleDataToOperations(data) {
|
|
209
|
+
const decodedOperations = [];
|
|
210
|
+
const roData = data;
|
|
211
|
+
roData.operations.forEach((operation) => {
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
213
|
+
if (operation.opType === OperationType.CHECK) {
|
|
214
|
+
const checkOperation = roData.checkOperations[operation.index];
|
|
215
|
+
decodedOperations.push({
|
|
216
|
+
opType: OperationType.CHECK,
|
|
217
|
+
checkType: checkOperation.opType,
|
|
218
|
+
chainId: checkOperation.chainId,
|
|
219
|
+
contractAddress: checkOperation.contractAddress,
|
|
220
|
+
params: checkOperation.params,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
224
|
+
else if (operation.opType === OperationType.LOGICAL) {
|
|
225
|
+
const logicalOperation = roData.logicalOperations[operation.index];
|
|
226
|
+
decodedOperations.push({
|
|
227
|
+
opType: OperationType.LOGICAL,
|
|
228
|
+
logicalType: logicalOperation.logOpType,
|
|
229
|
+
leftOperation: decodedOperations[logicalOperation.leftOperationIndex],
|
|
230
|
+
rightOperation: decodedOperations[logicalOperation.rightOperationIndex],
|
|
231
|
+
});
|
|
232
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
|
|
233
|
+
}
|
|
234
|
+
else if (operation.opType === OperationType.NONE) {
|
|
235
|
+
decodedOperations.push(NoopOperation);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
throw new Error(`Unknown logical operation type ${operation.opType}`);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
return decodedOperations;
|
|
242
|
+
}
|
|
243
|
+
export function postOrderTraversal(operation, data) {
|
|
244
|
+
if (isLogicalOperation(operation)) {
|
|
245
|
+
postOrderTraversal(operation.leftOperation, data);
|
|
246
|
+
// Capture index of the most recently added operation, which is the
|
|
247
|
+
// top of the left child's postorder tree
|
|
248
|
+
const leftChildIndex = data.operations.length - 1;
|
|
249
|
+
postOrderTraversal(operation.rightOperation, data);
|
|
250
|
+
data.logicalOperations.push({
|
|
251
|
+
logOpType: operation.logicalType,
|
|
252
|
+
leftOperationIndex: leftChildIndex,
|
|
253
|
+
rightOperationIndex: data.operations.length - 1, // Index of right child root
|
|
254
|
+
});
|
|
255
|
+
data.operations.push({
|
|
256
|
+
opType: OperationType.LOGICAL,
|
|
257
|
+
index: data.logicalOperations.length - 1,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
else if (isCheckOperationV2(operation)) {
|
|
261
|
+
data.checkOperations.push({
|
|
262
|
+
opType: operation.checkType,
|
|
263
|
+
chainId: operation.chainId,
|
|
264
|
+
contractAddress: operation.contractAddress,
|
|
265
|
+
params: operation.params,
|
|
266
|
+
});
|
|
267
|
+
data.operations.push({
|
|
268
|
+
opType: OperationType.CHECK,
|
|
269
|
+
index: data.checkOperations.length - 1,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
throw new Error('Unrecognized operation type');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
export function treeToRuleData(root) {
|
|
277
|
+
const data = {
|
|
278
|
+
operations: [],
|
|
279
|
+
checkOperations: [],
|
|
280
|
+
logicalOperations: [],
|
|
281
|
+
};
|
|
282
|
+
postOrderTraversal(root, data);
|
|
283
|
+
return data;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Evaluates an AndOperation
|
|
287
|
+
* If either of the operations are false, the entire operation is false, and the
|
|
288
|
+
* other operation is aborted. Once both operations succeed, the entire operation
|
|
289
|
+
* succeeds.
|
|
290
|
+
* @param operation
|
|
291
|
+
* @param controller
|
|
292
|
+
* @returns true once both succeed, false if either fail
|
|
293
|
+
*/
|
|
294
|
+
async function evaluateAndOperation(controller, linkedWallets, xchainConfig, operation) {
|
|
295
|
+
if (!operation?.leftOperation || !operation?.rightOperation) {
|
|
296
|
+
controller.abort();
|
|
297
|
+
return zeroAddress;
|
|
298
|
+
}
|
|
299
|
+
const newController = new AbortController();
|
|
300
|
+
controller.signal.addEventListener('abort', () => {
|
|
301
|
+
newController.abort();
|
|
302
|
+
});
|
|
303
|
+
const interuptFlag = {};
|
|
304
|
+
let tempInterupt;
|
|
305
|
+
const interupted = new Promise((resolve) => {
|
|
306
|
+
tempInterupt = resolve;
|
|
307
|
+
});
|
|
308
|
+
const interupt = () => {
|
|
309
|
+
if (tempInterupt) {
|
|
310
|
+
tempInterupt(interuptFlag);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
async function racer(operationEntry) {
|
|
314
|
+
const result = await Promise.race([
|
|
315
|
+
evaluateTree(newController, linkedWallets, xchainConfig, operationEntry),
|
|
316
|
+
interupted,
|
|
317
|
+
]);
|
|
318
|
+
if (result === interuptFlag) {
|
|
319
|
+
return zeroAddress; // interupted
|
|
320
|
+
}
|
|
321
|
+
else if (isValidAddress(result)) {
|
|
322
|
+
return result;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
controller.abort();
|
|
326
|
+
interupt();
|
|
327
|
+
return zeroAddress;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const checks = await Promise.all([
|
|
331
|
+
racer(operation.leftOperation),
|
|
332
|
+
racer(operation.rightOperation),
|
|
333
|
+
]);
|
|
334
|
+
const result = checks.every((res) => isValidAddress(res));
|
|
335
|
+
if (!result) {
|
|
336
|
+
return zeroAddress;
|
|
337
|
+
}
|
|
338
|
+
return checks[0];
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Evaluates an OrOperation
|
|
342
|
+
* If either of the operations are true, the entire operation is true
|
|
343
|
+
* and the other operation is aborted. Once both operationd fail, the
|
|
344
|
+
* entire operation fails.
|
|
345
|
+
* @param operation
|
|
346
|
+
* @param signal
|
|
347
|
+
* @returns true once one succeeds, false if both fail
|
|
348
|
+
*/
|
|
349
|
+
async function evaluateOrOperation(controller, linkedWallets, xchainConfig, operation) {
|
|
350
|
+
if (!operation?.leftOperation || !operation?.rightOperation) {
|
|
351
|
+
controller.abort();
|
|
352
|
+
return zeroAddress;
|
|
353
|
+
}
|
|
354
|
+
const newController = new AbortController();
|
|
355
|
+
controller.signal.addEventListener('abort', () => {
|
|
356
|
+
newController.abort();
|
|
357
|
+
});
|
|
358
|
+
const interuptFlag = {};
|
|
359
|
+
let tempInterupt;
|
|
360
|
+
const interupted = new Promise((resolve) => {
|
|
361
|
+
tempInterupt = resolve;
|
|
362
|
+
});
|
|
363
|
+
const interupt = () => {
|
|
364
|
+
if (tempInterupt) {
|
|
365
|
+
tempInterupt(interuptFlag);
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
async function racer(operation) {
|
|
369
|
+
const result = await Promise.race([
|
|
370
|
+
evaluateTree(newController, linkedWallets, xchainConfig, operation),
|
|
371
|
+
interupted,
|
|
372
|
+
]);
|
|
373
|
+
if (result === interuptFlag) {
|
|
374
|
+
return zeroAddress; // interupted, the other must have returned true
|
|
375
|
+
}
|
|
376
|
+
else if (isValidAddress(result)) {
|
|
377
|
+
// cancel the other operation
|
|
378
|
+
newController.abort();
|
|
379
|
+
interupt();
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
return zeroAddress;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const checks = await Promise.all([
|
|
387
|
+
racer(operation.leftOperation),
|
|
388
|
+
racer(operation.rightOperation),
|
|
389
|
+
]);
|
|
390
|
+
const result = checks.find((res) => isValidAddress(res));
|
|
391
|
+
return result ?? ethers.constants.AddressZero;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Evaluates a CheckOperation
|
|
395
|
+
* Mekes the smart contract call. Will be aborted if another branch invalidates
|
|
396
|
+
* the need to make the check.
|
|
397
|
+
* @param operation
|
|
398
|
+
* @param signal
|
|
399
|
+
* @returns
|
|
400
|
+
*/
|
|
401
|
+
async function evaluateCheckOperation(controller, linkedWallets, xchainConfig, operation) {
|
|
402
|
+
if (!operation) {
|
|
403
|
+
controller.abort();
|
|
404
|
+
return zeroAddress;
|
|
405
|
+
}
|
|
406
|
+
switch (operation.checkType) {
|
|
407
|
+
case CheckOperationType.MOCK: {
|
|
408
|
+
return evaluateMockOperation(operation, controller);
|
|
409
|
+
}
|
|
410
|
+
case CheckOperationType.NONE:
|
|
411
|
+
throw new Error('Unknown check operation type');
|
|
412
|
+
default:
|
|
413
|
+
}
|
|
414
|
+
if (operation.checkType !== CheckOperationType.ETH_BALANCE && operation.chainId < 0n) {
|
|
415
|
+
throw new Error(`Invalid chain id for check operation ${checkOpString(operation.checkType)}`);
|
|
416
|
+
}
|
|
417
|
+
if (operation.checkType !== CheckOperationType.ETH_BALANCE &&
|
|
418
|
+
operation.contractAddress === zeroAddress) {
|
|
419
|
+
throw new Error(`Invalid contract address for check operation ${checkOpString(operation.checkType)}`);
|
|
420
|
+
}
|
|
421
|
+
if ([
|
|
422
|
+
CheckOperationType.ERC20,
|
|
423
|
+
CheckOperationType.ERC721,
|
|
424
|
+
CheckOperationType.ETH_BALANCE,
|
|
425
|
+
].includes(operation.checkType)) {
|
|
426
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
427
|
+
if (threshold <= 0n) {
|
|
428
|
+
throw new Error(`Invalid threshold for check operation ${checkOpString(operation.checkType)}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (operation.checkType === CheckOperationType.ERC1155) {
|
|
432
|
+
const { tokenId, threshold } = decodeERC1155Params(operation.params);
|
|
433
|
+
if (tokenId < 0n) {
|
|
434
|
+
throw new Error(`Invalid token id for check operation ${checkOpString(operation.checkType)}`);
|
|
435
|
+
}
|
|
436
|
+
if (threshold <= 0n) {
|
|
437
|
+
throw new Error(`Invalid threshold for check operation ${checkOpString(operation.checkType)}`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
switch (operation.checkType) {
|
|
441
|
+
case CheckOperationType.ISENTITLED: {
|
|
442
|
+
const provider = await findProviderFromChainId(xchainConfig, operation.chainId);
|
|
443
|
+
if (!provider) {
|
|
444
|
+
controller.abort();
|
|
445
|
+
return zeroAddress;
|
|
446
|
+
}
|
|
447
|
+
return evaluateCrossChainEntitlementOperation(operation, controller, provider, linkedWallets);
|
|
448
|
+
}
|
|
449
|
+
case CheckOperationType.ETH_BALANCE: {
|
|
450
|
+
const etherChainProviders = await findEtherChainProviders(xchainConfig);
|
|
451
|
+
if (!etherChainProviders.length) {
|
|
452
|
+
controller.abort();
|
|
453
|
+
return zeroAddress;
|
|
454
|
+
}
|
|
455
|
+
return evaluateEthBalanceOperation(operation, controller, etherChainProviders, linkedWallets);
|
|
456
|
+
}
|
|
457
|
+
case CheckOperationType.ERC1155: {
|
|
458
|
+
const provider = await findProviderFromChainId(xchainConfig, operation.chainId);
|
|
459
|
+
if (!provider) {
|
|
460
|
+
controller.abort();
|
|
461
|
+
return zeroAddress;
|
|
462
|
+
}
|
|
463
|
+
return evaluateERC1155Operation(operation, controller, provider, linkedWallets);
|
|
464
|
+
}
|
|
465
|
+
case CheckOperationType.ERC20: {
|
|
466
|
+
const provider = await findProviderFromChainId(xchainConfig, operation.chainId);
|
|
467
|
+
if (!provider) {
|
|
468
|
+
controller.abort();
|
|
469
|
+
return zeroAddress;
|
|
470
|
+
}
|
|
471
|
+
return evaluateERC20Operation(operation, controller, provider, linkedWallets);
|
|
472
|
+
}
|
|
473
|
+
case CheckOperationType.ERC721: {
|
|
474
|
+
const provider = await findProviderFromChainId(xchainConfig, operation.chainId);
|
|
475
|
+
if (!provider) {
|
|
476
|
+
controller.abort();
|
|
477
|
+
return zeroAddress;
|
|
478
|
+
}
|
|
479
|
+
return evaluateERC721Operation(operation, controller, provider, linkedWallets);
|
|
480
|
+
}
|
|
481
|
+
default:
|
|
482
|
+
throw new Error('Unknown check operation type');
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
*
|
|
487
|
+
* @param operations
|
|
488
|
+
* @param linkedWallets
|
|
489
|
+
* @param providers
|
|
490
|
+
* @returns An entitled wallet or the zero address, indicating no entitlement
|
|
491
|
+
*/
|
|
492
|
+
export async function evaluateOperationsForEntitledWallet(operations, linkedWallets, xchainConfig) {
|
|
493
|
+
if (operations.length === 0) {
|
|
494
|
+
return zeroAddress;
|
|
495
|
+
}
|
|
496
|
+
const controller = new AbortController();
|
|
497
|
+
const root = postOrderArrayToTree(operations);
|
|
498
|
+
const result = evaluateTree(controller, linkedWallets, xchainConfig, root);
|
|
499
|
+
controller.abort();
|
|
500
|
+
return result;
|
|
501
|
+
}
|
|
502
|
+
export async function evaluateTree(controller, linkedWallets, xchainConfig, entry) {
|
|
503
|
+
if (!entry) {
|
|
504
|
+
controller.abort();
|
|
505
|
+
return zeroAddress;
|
|
506
|
+
}
|
|
507
|
+
const newController = new AbortController();
|
|
508
|
+
controller.signal.addEventListener('abort', () => {
|
|
509
|
+
newController.abort();
|
|
510
|
+
});
|
|
511
|
+
if (isLogicalOperation(entry)) {
|
|
512
|
+
if (isAndOperation(entry)) {
|
|
513
|
+
return evaluateAndOperation(newController, linkedWallets, xchainConfig, entry);
|
|
514
|
+
}
|
|
515
|
+
else if (isOrOperation(entry)) {
|
|
516
|
+
return evaluateOrOperation(newController, linkedWallets, xchainConfig, entry);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
throw new Error('Unknown operation type');
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
else if (isCheckOperationV2(entry)) {
|
|
523
|
+
return evaluateCheckOperation(newController, linkedWallets, xchainConfig, entry);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
throw new Error('Unknown operation type');
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// These two methods are used to create a rule data struct for an external token or NFT
|
|
530
|
+
// checks for testing.
|
|
531
|
+
export function createExternalTokenStruct(addresses, options) {
|
|
532
|
+
if (addresses.length === 0) {
|
|
533
|
+
return NoopRuleData;
|
|
534
|
+
}
|
|
535
|
+
const defaultChain = addresses.map((address) => ({
|
|
536
|
+
chainId: options?.checkOptions?.chainId ?? 1n,
|
|
537
|
+
address: address,
|
|
538
|
+
type: options?.checkOptions?.type ?? CheckOperationType.ERC20,
|
|
539
|
+
params: encodeThresholdParams({ threshold: options?.checkOptions?.threshold ?? BigInt(1) }),
|
|
540
|
+
}));
|
|
541
|
+
return createOperationsTree(defaultChain, options?.logicalOp ?? LogicalOperationType.OR);
|
|
542
|
+
}
|
|
543
|
+
export function createExternalNFTStruct(addresses, options) {
|
|
544
|
+
if (addresses.length === 0) {
|
|
545
|
+
return NoopRuleData;
|
|
546
|
+
}
|
|
547
|
+
const defaultChain = addresses.map((address) => ({
|
|
548
|
+
// Anvil chain id
|
|
549
|
+
chainId: options?.checkOptions?.chainId ?? 31337n,
|
|
550
|
+
address: address,
|
|
551
|
+
type: options?.checkOptions?.type ?? CheckOperationType.ERC721,
|
|
552
|
+
params: encodeThresholdParams({ threshold: options?.checkOptions?.threshold ?? BigInt(1) }),
|
|
553
|
+
}));
|
|
554
|
+
return createOperationsTree(defaultChain, options?.logicalOp ?? LogicalOperationType.OR);
|
|
555
|
+
}
|
|
556
|
+
export class DecodedCheckOperationBuilder {
|
|
557
|
+
decodedCheckOp = {};
|
|
558
|
+
setType(checkOpType) {
|
|
559
|
+
this.decodedCheckOp.type = checkOpType;
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
562
|
+
setChainId(chainId) {
|
|
563
|
+
this.decodedCheckOp.chainId = chainId;
|
|
564
|
+
return this;
|
|
565
|
+
}
|
|
566
|
+
setThreshold(threshold) {
|
|
567
|
+
this.decodedCheckOp.threshold = threshold;
|
|
568
|
+
return this;
|
|
569
|
+
}
|
|
570
|
+
setAddress(address) {
|
|
571
|
+
this.decodedCheckOp.address = address;
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
574
|
+
setTokenId(tokenId) {
|
|
575
|
+
this.decodedCheckOp.tokenId = tokenId;
|
|
576
|
+
return this;
|
|
577
|
+
}
|
|
578
|
+
setByteEncodedParams(params) {
|
|
579
|
+
this.decodedCheckOp.byteEncodedParams = params;
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
582
|
+
build() {
|
|
583
|
+
if (this.decodedCheckOp.type === undefined) {
|
|
584
|
+
throw new Error('DecodedCheckOperation requires a type');
|
|
585
|
+
}
|
|
586
|
+
const opStr = checkOpString(this.decodedCheckOp.type);
|
|
587
|
+
// For contract-related checks, assert set values for chain id and contract address
|
|
588
|
+
switch (this.decodedCheckOp.type) {
|
|
589
|
+
case CheckOperationType.ERC1155:
|
|
590
|
+
case CheckOperationType.ERC20:
|
|
591
|
+
case CheckOperationType.ERC721:
|
|
592
|
+
case CheckOperationType.ISENTITLED:
|
|
593
|
+
if (this.decodedCheckOp.chainId === undefined) {
|
|
594
|
+
throw new Error(`DecodedCheckOperation of type ${opStr} requires a chainId`);
|
|
595
|
+
}
|
|
596
|
+
if (this.decodedCheckOp.address === undefined) {
|
|
597
|
+
throw new Error(`DecodedCheckOperation of type ${opStr} requires an address`);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
// threshold check
|
|
601
|
+
switch (this.decodedCheckOp.type) {
|
|
602
|
+
case CheckOperationType.ERC1155:
|
|
603
|
+
case CheckOperationType.ETH_BALANCE:
|
|
604
|
+
case CheckOperationType.ERC20:
|
|
605
|
+
case CheckOperationType.ERC721:
|
|
606
|
+
if (this.decodedCheckOp.threshold === undefined) {
|
|
607
|
+
throw new Error(`DecodedCheckOperation of type ${opStr} requires a threshold`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
// tokenId check
|
|
611
|
+
if (this.decodedCheckOp.type === CheckOperationType.ERC1155 &&
|
|
612
|
+
this.decodedCheckOp.tokenId === undefined) {
|
|
613
|
+
throw new Error(`DecodedCheckOperation of type ${opStr} requires a tokenId`);
|
|
614
|
+
}
|
|
615
|
+
// byte-encoded params check
|
|
616
|
+
if (this.decodedCheckOp.type === CheckOperationType.ISENTITLED &&
|
|
617
|
+
this.decodedCheckOp.byteEncodedParams === undefined) {
|
|
618
|
+
throw new Error(`DecodedCheckOperation of type ${opStr} requires byteEncodedParams`);
|
|
619
|
+
}
|
|
620
|
+
switch (this.decodedCheckOp.type) {
|
|
621
|
+
case CheckOperationType.ERC20:
|
|
622
|
+
case CheckOperationType.ERC721:
|
|
623
|
+
return {
|
|
624
|
+
type: this.decodedCheckOp.type,
|
|
625
|
+
chainId: this.decodedCheckOp.chainId,
|
|
626
|
+
address: this.decodedCheckOp.address,
|
|
627
|
+
threshold: this.decodedCheckOp.threshold,
|
|
628
|
+
};
|
|
629
|
+
case CheckOperationType.ERC1155:
|
|
630
|
+
return {
|
|
631
|
+
type: CheckOperationType.ERC1155,
|
|
632
|
+
chainId: this.decodedCheckOp.chainId,
|
|
633
|
+
address: this.decodedCheckOp.address,
|
|
634
|
+
threshold: this.decodedCheckOp.threshold,
|
|
635
|
+
tokenId: this.decodedCheckOp.tokenId,
|
|
636
|
+
};
|
|
637
|
+
case CheckOperationType.ETH_BALANCE:
|
|
638
|
+
return {
|
|
639
|
+
type: CheckOperationType.ETH_BALANCE,
|
|
640
|
+
threshold: this.decodedCheckOp.threshold,
|
|
641
|
+
};
|
|
642
|
+
case CheckOperationType.ISENTITLED:
|
|
643
|
+
return {
|
|
644
|
+
type: CheckOperationType.ISENTITLED,
|
|
645
|
+
address: this.decodedCheckOp.address,
|
|
646
|
+
chainId: this.decodedCheckOp.chainId,
|
|
647
|
+
byteEncodedParams: this.decodedCheckOp.byteEncodedParams,
|
|
648
|
+
};
|
|
649
|
+
default:
|
|
650
|
+
throw new Error(`Check operation type ${opStr} unrecognized or not used in production`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
export function createOperationsTree(checkOp, logicalOp = LogicalOperationType.OR) {
|
|
655
|
+
if (checkOp.length === 0) {
|
|
656
|
+
return {
|
|
657
|
+
operations: [NoopOperation],
|
|
658
|
+
checkOperations: [],
|
|
659
|
+
logicalOperations: [],
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
let operations = checkOp.map((op) => {
|
|
663
|
+
let params;
|
|
664
|
+
switch (op.type) {
|
|
665
|
+
case CheckOperationType.ERC20:
|
|
666
|
+
case CheckOperationType.ERC721:
|
|
667
|
+
params = encodeThresholdParams({ threshold: op.threshold ?? BigInt(1) });
|
|
668
|
+
break;
|
|
669
|
+
case CheckOperationType.ETH_BALANCE:
|
|
670
|
+
params = encodeThresholdParams({ threshold: op.threshold ?? BigInt(0) });
|
|
671
|
+
break;
|
|
672
|
+
case CheckOperationType.ERC1155:
|
|
673
|
+
params = encodeERC1155Params({
|
|
674
|
+
threshold: op.threshold ?? BigInt(1),
|
|
675
|
+
tokenId: op.tokenId ?? BigInt(0),
|
|
676
|
+
});
|
|
677
|
+
break;
|
|
678
|
+
case CheckOperationType.ISENTITLED:
|
|
679
|
+
params = op.byteEncodedParams ?? `0x`;
|
|
680
|
+
break;
|
|
681
|
+
default:
|
|
682
|
+
params = '0x';
|
|
683
|
+
}
|
|
684
|
+
return {
|
|
685
|
+
opType: OperationType.CHECK,
|
|
686
|
+
checkType: op.type,
|
|
687
|
+
chainId: op.chainId ?? 1n,
|
|
688
|
+
contractAddress: op.address ?? zeroAddress,
|
|
689
|
+
params,
|
|
690
|
+
};
|
|
691
|
+
});
|
|
692
|
+
while (operations.length > 1) {
|
|
693
|
+
const newOperations = [];
|
|
694
|
+
for (let i = 0; i < operations.length; i += 2) {
|
|
695
|
+
if (i + 1 < operations.length) {
|
|
696
|
+
newOperations.push({
|
|
697
|
+
opType: OperationType.LOGICAL,
|
|
698
|
+
logicalType: logicalOp,
|
|
699
|
+
leftOperation: operations[i],
|
|
700
|
+
rightOperation: operations[i + 1],
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
newOperations.push(operations[i]); // Odd one out, just push it to the next level
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
operations = newOperations;
|
|
708
|
+
}
|
|
709
|
+
return treeToRuleData(operations[0]);
|
|
710
|
+
}
|
|
711
|
+
// Return a set of reified check operations from a rule data struct in order to easily evaluate
|
|
712
|
+
// thresholds, convert check operations into token schemas, etc.
|
|
713
|
+
export function createDecodedCheckOperationFromTree(entitlementData) {
|
|
714
|
+
const operations = ruleDataToOperations(entitlementData);
|
|
715
|
+
const checkOpSubsets = [];
|
|
716
|
+
operations.forEach((operation) => {
|
|
717
|
+
if (isCheckOperationV2(operation)) {
|
|
718
|
+
const op = {
|
|
719
|
+
address: operation.contractAddress,
|
|
720
|
+
chainId: operation.chainId,
|
|
721
|
+
type: operation.checkType,
|
|
722
|
+
};
|
|
723
|
+
if (operation.checkType === CheckOperationType.ERC1155) {
|
|
724
|
+
const { threshold, tokenId } = decodeERC1155Params(operation.params);
|
|
725
|
+
checkOpSubsets.push({
|
|
726
|
+
...op,
|
|
727
|
+
threshold,
|
|
728
|
+
tokenId,
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
else if (operation.checkType === CheckOperationType.ERC20 ||
|
|
732
|
+
operation.checkType === CheckOperationType.ERC721 ||
|
|
733
|
+
operation.checkType === CheckOperationType.ETH_BALANCE) {
|
|
734
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
735
|
+
checkOpSubsets.push({
|
|
736
|
+
...op,
|
|
737
|
+
threshold,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
else if (operation.checkType === CheckOperationType.ISENTITLED) {
|
|
741
|
+
checkOpSubsets.push({
|
|
742
|
+
...op,
|
|
743
|
+
byteEncodedParams: operation.params,
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
return checkOpSubsets;
|
|
749
|
+
}
|
|
750
|
+
async function evaluateMockOperation(operation, controller) {
|
|
751
|
+
const result = operation.chainId === 1n;
|
|
752
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
753
|
+
const delay = Number.parseInt(threshold.toString());
|
|
754
|
+
return await new Promise((resolve) => {
|
|
755
|
+
controller.signal.onabort = () => {
|
|
756
|
+
if (timeout) {
|
|
757
|
+
clearTimeout(timeout);
|
|
758
|
+
resolve(zeroAddress);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
const timeout = setTimeout(() => {
|
|
762
|
+
if (result) {
|
|
763
|
+
resolve(MOCK_ADDRESS);
|
|
764
|
+
}
|
|
765
|
+
else {
|
|
766
|
+
resolve(zeroAddress);
|
|
767
|
+
}
|
|
768
|
+
}, delay);
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
async function evaluateERC721Operation(operation, controller, provider, linkedWallets) {
|
|
772
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
773
|
+
return evaluateContractBalanceAcrossWallets(operation.contractAddress, threshold, controller, provider, linkedWallets);
|
|
774
|
+
}
|
|
775
|
+
async function evaluateERC20Operation(operation, controller, provider, linkedWallets) {
|
|
776
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
777
|
+
return evaluateContractBalanceAcrossWallets(operation.contractAddress, threshold, controller, provider, linkedWallets);
|
|
778
|
+
}
|
|
779
|
+
async function evaluateCrossChainEntitlementOperation(operation, controller, provider, linkedWallets) {
|
|
780
|
+
const contract = new ethers.Contract(operation.contractAddress, ['function isEntitled(address[], bytes) view returns (bool)'], provider);
|
|
781
|
+
return await Promise.any(linkedWallets.map(async (wallet) => {
|
|
782
|
+
const isEntitled = await contract.callStatic.isEntitled([wallet], operation.params);
|
|
783
|
+
if (isEntitled === true) {
|
|
784
|
+
return wallet;
|
|
785
|
+
}
|
|
786
|
+
throw new Error('Not entitled');
|
|
787
|
+
})).catch(() => {
|
|
788
|
+
controller.abort();
|
|
789
|
+
return zeroAddress;
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
async function evaluateERC1155Operation(operation, controller, provider, linkedWallets) {
|
|
793
|
+
const contract = new ethers.Contract(operation.contractAddress, ['function balanceOf(address, uint256) view returns (uint)'], provider);
|
|
794
|
+
const { threshold, tokenId } = decodeERC1155Params(operation.params);
|
|
795
|
+
const walletBalances = await Promise.all(linkedWallets.map(async (wallet) => {
|
|
796
|
+
try {
|
|
797
|
+
const result = (await contract.callStatic.balanceOf(wallet, tokenId));
|
|
798
|
+
const resultAsBigNumber = ethers.BigNumber.from(result);
|
|
799
|
+
return {
|
|
800
|
+
wallet,
|
|
801
|
+
balance: resultAsBigNumber,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
return {
|
|
806
|
+
wallet,
|
|
807
|
+
balance: ethers.BigNumber.from(0),
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
}));
|
|
811
|
+
const walletsWithAsset = walletBalances.filter((result) => result.balance.gt(0));
|
|
812
|
+
const accumulatedBalance = walletsWithAsset.reduce((acc, el) => acc.add(el.balance), ethers.BigNumber.from(0));
|
|
813
|
+
if (walletsWithAsset.length > 0 && accumulatedBalance.gte(threshold)) {
|
|
814
|
+
return walletsWithAsset[0].wallet;
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
controller.abort();
|
|
818
|
+
return zeroAddress;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
async function getEthBalance(provider, wallet) {
|
|
822
|
+
try {
|
|
823
|
+
const balance = await provider.getBalance(wallet);
|
|
824
|
+
return {
|
|
825
|
+
wallet,
|
|
826
|
+
balance,
|
|
827
|
+
};
|
|
828
|
+
}
|
|
829
|
+
catch (error) {
|
|
830
|
+
return {
|
|
831
|
+
wallet,
|
|
832
|
+
balance: ethers.BigNumber.from(0),
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async function evaluateEthBalanceOperation(operation, controller, providers, linkedWallets) {
|
|
837
|
+
const { threshold } = decodeThresholdParams(operation.params);
|
|
838
|
+
const balancePromises = [];
|
|
839
|
+
for (const wallet of linkedWallets) {
|
|
840
|
+
for (const provider of providers) {
|
|
841
|
+
balancePromises.push(getEthBalance(provider, wallet));
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const walletBalances = await Promise.all(balancePromises);
|
|
845
|
+
const walletsWithAsset = walletBalances.filter((balance) => balance.balance.gt(0));
|
|
846
|
+
const accumulatedBalance = walletsWithAsset.reduce((acc, el) => acc.add(el.balance), ethers.BigNumber.from(0));
|
|
847
|
+
if (walletsWithAsset.length > 0 && accumulatedBalance.gte(threshold)) {
|
|
848
|
+
return walletsWithAsset[0].wallet;
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
controller.abort();
|
|
852
|
+
return zeroAddress;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
async function evaluateContractBalanceAcrossWallets(contractAddress, threshold, controller, provider, linkedWallets) {
|
|
856
|
+
const contract = new ethers.Contract(contractAddress, ['function balanceOf(address) view returns (uint)'], provider);
|
|
857
|
+
const walletBalances = await Promise.all(linkedWallets.map(async (wallet) => {
|
|
858
|
+
try {
|
|
859
|
+
const result = await contract.callStatic.balanceOf(wallet);
|
|
860
|
+
const resultAsBigNumber = ethers.BigNumber.from(result);
|
|
861
|
+
if (!ethers.BigNumber.isBigNumber(resultAsBigNumber)) {
|
|
862
|
+
return {
|
|
863
|
+
wallet,
|
|
864
|
+
balance: ethers.BigNumber.from(0),
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
return {
|
|
868
|
+
wallet,
|
|
869
|
+
balance: resultAsBigNumber,
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
catch (error) {
|
|
873
|
+
return {
|
|
874
|
+
wallet,
|
|
875
|
+
balance: ethers.BigNumber.from(0),
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
}));
|
|
879
|
+
const walletsWithAsset = walletBalances.filter((balance) => balance.balance.gt(0));
|
|
880
|
+
const accumulatedBalance = walletsWithAsset.reduce((acc, el) => acc.add(el.balance), ethers.BigNumber.from(0));
|
|
881
|
+
if (walletsWithAsset.length > 0 && accumulatedBalance.gte(threshold)) {
|
|
882
|
+
return walletsWithAsset[0].wallet;
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
controller.abort();
|
|
886
|
+
return zeroAddress;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
async function findProviderFromChainId(xchainConfig, chainId) {
|
|
890
|
+
if (!(Number(chainId) in xchainConfig.supportedRpcUrls)) {
|
|
891
|
+
return undefined;
|
|
892
|
+
}
|
|
893
|
+
const url = xchainConfig.supportedRpcUrls[Number(chainId)];
|
|
894
|
+
const provider = new ethers.providers.StaticJsonRpcProvider({
|
|
895
|
+
url,
|
|
896
|
+
skipFetchSetup: xchainConfig.skipFetchSetup === true,
|
|
897
|
+
});
|
|
898
|
+
await provider.ready;
|
|
899
|
+
return provider;
|
|
900
|
+
}
|
|
901
|
+
async function findEtherChainProviders(xchainConfig) {
|
|
902
|
+
const etherChainProviders = [];
|
|
903
|
+
for (const chainId of xchainConfig.etherNativeNetworkIds) {
|
|
904
|
+
if (!(chainId in xchainConfig.supportedRpcUrls)) {
|
|
905
|
+
log.info(`(WARN) findEtherChainProviders: No supported RPC URL for chain id ${chainId}`);
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
const url = xchainConfig.supportedRpcUrls[chainId];
|
|
909
|
+
etherChainProviders.push(new ethers.providers.StaticJsonRpcProvider({
|
|
910
|
+
url,
|
|
911
|
+
skipFetchSetup: xchainConfig.skipFetchSetup === true,
|
|
912
|
+
}));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
await Promise.all(etherChainProviders.map((p) => p.ready));
|
|
916
|
+
return etherChainProviders;
|
|
917
|
+
}
|
|
918
|
+
export async function findEthereumProviders(xchainConfig) {
|
|
919
|
+
const ethereumProviders = [];
|
|
920
|
+
for (const chainId of xchainConfig.ethereumNetworkIds) {
|
|
921
|
+
if (!(chainId in xchainConfig.supportedRpcUrls)) {
|
|
922
|
+
log.error(`findEthereumProviders: No supported RPC URL for chain id ${chainId}`);
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
const url = xchainConfig.supportedRpcUrls[chainId];
|
|
926
|
+
ethereumProviders.push(new ethers.providers.StaticJsonRpcProvider({
|
|
927
|
+
url,
|
|
928
|
+
skipFetchSetup: xchainConfig.skipFetchSetup === true,
|
|
929
|
+
}));
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
await Promise.all(ethereumProviders.map((p) => p.ready));
|
|
933
|
+
return ethereumProviders;
|
|
934
|
+
}
|
|
935
|
+
function isValidAddress(value) {
|
|
936
|
+
return (typeof value === 'string' &&
|
|
937
|
+
ethers.utils.isAddress(value) &&
|
|
938
|
+
value !== ethers.constants.AddressZero);
|
|
939
|
+
}
|
|
940
|
+
//# sourceMappingURL=entitlement.js.map
|