├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── nodejs.yml │ └── publish.yml ├── .gitignore ├── .husky ├── .gitignore └── pre-commit ├── .prettierignore ├── .prettierrc.json ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── examples ├── README.md ├── get-property-info.js ├── get-stats.js └── get-stoken-info.js ├── lib ├── addresses.ts ├── agent │ ├── common │ │ ├── agentAddresses.ts │ │ ├── approveIfNeeded.ts │ │ ├── clients │ │ │ ├── clientsDev.ts │ │ │ ├── clientsLockup.ts │ │ │ ├── clientsMarketFactory.ts │ │ │ ├── clientsMetricsFactory.ts │ │ │ ├── clientsMetricsGroup.ts │ │ │ ├── clientsPolicy.ts │ │ │ ├── clientsProperty.ts │ │ │ ├── clientsPropertyFactory.ts │ │ │ ├── clientsRegistry.ts │ │ │ ├── clientsSTokens.ts │ │ │ ├── clientsUtilsSwapForStake.ts │ │ │ └── clientsUtilsSwapTokensForStake.ts │ │ └── const.ts │ ├── estimationsAPY.ts │ ├── fixtures │ │ ├── swap-arbitrary-tokens │ │ │ ├── abi.ts │ │ │ ├── getEstimatedDevForTokens.spec.ts │ │ │ ├── getEstimatedDevForTokens.ts │ │ │ ├── getEstimatedTokensForDev.spec.ts │ │ │ ├── getEstimatedTokensForDev.ts │ │ │ ├── index.spec.ts │ │ │ ├── index.ts │ │ │ ├── path-of.ts │ │ │ ├── swapTokensAndStakeDev.spec.ts │ │ │ └── swapTokensAndStakeDev.ts │ │ └── swap │ │ │ ├── abi-v2.ts │ │ │ ├── abi-v3-polygon.ts │ │ │ ├── abi-v3.ts │ │ │ ├── getEstimatedDevForEth.spec.ts │ │ │ ├── getEstimatedDevForEth.ts │ │ │ ├── getEstimatedEthForDev.spec.ts │ │ │ ├── getEstimatedEthForDev.ts │ │ │ ├── index.spec.ts │ │ │ ├── index.ts │ │ │ ├── swapEthAndStakeDev.spec.ts │ │ │ ├── swapEthAndStakeDev.ts │ │ │ ├── swapEthAndStakeDevPolygon.spec.ts │ │ │ └── swapEthAndStakeDevPolygon.ts │ ├── index.ts │ ├── positionsClaim.ts │ ├── positionsCreate.spec.ts │ ├── positionsCreate.ts │ ├── positionsCreateWithAnyTokens.ts │ ├── positionsCreateWithEth.ts │ ├── positionsCreateWithEthForPolygon.ts │ ├── positionsGet.ts │ ├── positionsList.ts │ ├── positionsUpdate.ts │ ├── propertiesAssets.ts │ ├── propertiesAuthenticate.ts │ ├── propertiesCreate.ts │ ├── propertiesCreateToAuthenticate.ts │ ├── propertiesDeauthenticate.ts │ └── propertiesList.ts ├── common │ ├── erc20 │ │ ├── abi.ts │ │ ├── allowance.spec.ts │ │ ├── allowance.ts │ │ ├── approve.spec.ts │ │ ├── approve.ts │ │ ├── balanceOf.spec.ts │ │ ├── balanceOf.ts │ │ ├── decimals.spec.ts │ │ ├── decimals.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── name.spec.ts │ │ ├── name.ts │ │ ├── symbol.spec.ts │ │ ├── symbol.ts │ │ ├── totalSupply.spec.ts │ │ ├── totalSupply.ts │ │ ├── transfer.spec.ts │ │ ├── transfer.ts │ │ ├── transferFrom.spec.ts │ │ └── transferFrom.ts │ ├── option.ts │ └── utils │ │ ├── arrayify.spec.ts │ │ ├── arrayify.ts │ │ ├── const.ts │ │ ├── execute.spec.ts │ │ ├── execute.ts │ │ ├── for-test.ts │ │ ├── index.spec.ts │ │ └── index.ts ├── ethereum │ ├── allocator │ │ ├── abi.ts │ │ ├── calculateMaxRewardsPerBlock.spec.ts │ │ ├── calculateMaxRewardsPerBlock.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── client │ │ ├── createDetectSTokens.spec.ts │ │ ├── createDetectSTokens.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── contract.spec.ts │ ├── contract.ts │ ├── dev │ │ ├── abi.ts │ │ ├── deposit.spec.ts │ │ ├── deposit.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── lockup │ │ ├── abi.ts │ │ ├── calculateCumulativeHoldersRewardAmount.spec.ts │ │ ├── calculateCumulativeHoldersRewardAmount.ts │ │ ├── calculateCumulativeRewardPrices.spec.ts │ │ ├── calculateCumulativeRewardPrices.ts │ │ ├── calculateRewardAmount.spec.ts │ │ ├── calculateRewardAmount.ts │ │ ├── calculateWithdrawableInterestAmount.spec.ts │ │ ├── calculateWithdrawableInterestAmount.ts │ │ ├── calculateWithdrawableInterestAmountByPosition.spec.ts │ │ ├── calculateWithdrawableInterestAmountByPosition.ts │ │ ├── cap.spec.ts │ │ ├── cap.ts │ │ ├── depositToPosition.spec.ts │ │ ├── depositToPosition.ts │ │ ├── depositToProperty.spec.ts │ │ ├── depositToProperty.ts │ │ ├── getAllValue.spec.ts │ │ ├── getAllValue.ts │ │ ├── getPropertyValue.spec.ts │ │ ├── getPropertyValue.ts │ │ ├── getStorageWithdrawalStatus.spec.ts │ │ ├── getStorageWithdrawalStatus.ts │ │ ├── getValue.spec.ts │ │ ├── getValue.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── migrateToSTokens.spec.ts │ │ ├── migrateToSTokens.ts │ │ ├── withdraw.spec.ts │ │ ├── withdraw.ts │ │ ├── withdrawByPosition.spec.ts │ │ └── withdrawByPosition.ts │ ├── market-behavior │ │ ├── abi.ts │ │ ├── getId.spec.ts │ │ ├── getId.ts │ │ ├── getMetrics.spec.ts │ │ ├── getMetrics.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── market-factory │ │ ├── abi.ts │ │ ├── create.spec.ts │ │ ├── create.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── market │ │ ├── abi.ts │ │ ├── authenticate.ts │ │ ├── behavior.spec.ts │ │ ├── behavior.ts │ │ ├── index.ts │ │ ├── schema.spec.ts │ │ ├── schema.ts │ │ ├── vote.spec.ts │ │ └── vote.ts │ ├── metrics-factory │ │ └── abi.ts │ ├── metrics-group │ │ ├── abi.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── totalAuthenticatedProperties.spec.ts │ │ ├── totalAuthenticatedProperties.ts │ │ ├── totalIssuedMetrics.spec.ts │ │ └── totalIssuedMetrics.ts │ ├── metrics │ │ ├── abi.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── market.spec.ts │ │ ├── market.ts │ │ ├── property.spec.ts │ │ └── property.ts │ ├── policy-factory │ │ ├── abi.ts │ │ ├── create.spec.ts │ │ ├── create.ts │ │ ├── forceAttach.spec.ts │ │ ├── forceAttach.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── policy-group │ │ ├── abi.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── isDuringVotingPeriod.spec.ts │ │ ├── isDuringVotingPeriod.ts │ │ ├── isGroup.spec.ts │ │ └── isGroup.ts │ ├── policy │ │ ├── abi.ts │ │ ├── authenticationFee.spec.ts │ │ ├── authenticationFee.ts │ │ ├── capSetter.spec.ts │ │ ├── capSetter.ts │ │ ├── holdersShare.spec.ts │ │ ├── holdersShare.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── marketVotingBlocks.spec.ts │ │ ├── marketVotingBlocks.ts │ │ ├── policyVotingBlocks.spec.ts │ │ ├── policyVotingBlocks.ts │ │ ├── rewards.spec.ts │ │ ├── rewards.ts │ │ ├── shareOfTreasury.spec.ts │ │ ├── shareOfTreasury.ts │ │ ├── treasury.spec.ts │ │ └── treasury.ts │ ├── property-factory │ │ ├── abi.ts │ │ ├── create.ts │ │ ├── createAndAuthenticate.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── property │ │ ├── abi.ts │ │ ├── author.spec.ts │ │ ├── author.ts │ │ ├── changeAuthor.spec.ts │ │ ├── changeAuthor.ts │ │ ├── changeName.spec.ts │ │ ├── changeName.ts │ │ ├── changeSymbol.spec.ts │ │ ├── changeSymbol.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── registry │ │ ├── abi.ts │ │ ├── allocator.spec.ts │ │ ├── allocator.ts │ │ ├── allocatorStorage.spec.ts │ │ ├── allocatorStorage.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── lockup.spec.ts │ │ ├── lockup.ts │ │ ├── lockupStorage.spec.ts │ │ ├── lockupStorage.ts │ │ ├── marketFactory.spec.ts │ │ ├── marketFactory.ts │ │ ├── marketGroup.spec.ts │ │ ├── marketGroup.ts │ │ ├── metricsFactory.spec.ts │ │ ├── metricsFactory.ts │ │ ├── metricsGroup.spec.ts │ │ ├── metricsGroup.ts │ │ ├── policy.spec.ts │ │ ├── policy.ts │ │ ├── policyFactory.spec.ts │ │ ├── policyFactory.ts │ │ ├── policyGroup.spec.ts │ │ ├── policyGroup.ts │ │ ├── policySet.spec.ts │ │ ├── policySet.ts │ │ ├── propertyFactory.spec.ts │ │ ├── propertyFactory.ts │ │ ├── propertyGroup.spec.ts │ │ ├── propertyGroup.ts │ │ ├── token.spec.ts │ │ ├── token.ts │ │ ├── withdraw.spec.ts │ │ ├── withdraw.ts │ │ ├── withdrawStorage.spec.ts │ │ └── withdrawStorage.ts │ ├── s-tokens │ │ ├── abi.ts │ │ ├── descriptorOf.spec.ts │ │ ├── descriptorOf.ts │ │ ├── descriptorOfPropertyByPayload.spec.ts │ │ ├── descriptorOfPropertyByPayload.ts │ │ ├── freezeTokenURI.spec.ts │ │ ├── freezeTokenURI.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── isFreezed.spec.ts │ │ ├── isFreezed.ts │ │ ├── ownerOf.spec.ts │ │ ├── ownerOf.ts │ │ ├── payloadOf.spec.ts │ │ ├── payloadOf.ts │ │ ├── positions.spec.ts │ │ ├── positions.ts │ │ ├── positionsOfOwner.spec.ts │ │ ├── positionsOfOwner.ts │ │ ├── positionsOfProperty.spec.ts │ │ ├── positionsOfProperty.ts │ │ ├── rewards.spec.ts │ │ ├── rewards.ts │ │ ├── royaltyOf.spec.ts │ │ ├── royaltyOf.ts │ │ ├── setSTokenRoyaltyForProperty.spec.ts │ │ ├── setSTokenRoyaltyForProperty.ts │ │ ├── setTokenURIDescriptor.spec.ts │ │ ├── setTokenURIDescriptor.ts │ │ ├── setTokenURIImage.spec.ts │ │ ├── setTokenURIImage.ts │ │ ├── tokenURI.spec.ts │ │ ├── tokenURI.ts │ │ ├── tokenURISim.spec.ts │ │ └── tokenURISim.ts │ ├── simpleCollection │ │ ├── abi.ts │ │ ├── description.spec.ts │ │ ├── image.spec.ts │ │ ├── index.ts │ │ ├── name.spec.ts │ │ ├── queryCaller.ts │ │ ├── removeImage.spec.ts │ │ ├── removeImage.ts │ │ ├── setImages.spec.ts │ │ ├── setImages.ts │ │ └── types.ts │ └── withdraw │ │ ├── abi.ts │ │ ├── bulkWithdraw.spec.ts │ │ ├── bulkWithdraw.ts │ │ ├── calculateRewardAmount.spec.ts │ │ ├── calculateRewardAmount.ts │ │ ├── calculateWithdrawableAmount.spec.ts │ │ ├── calculateWithdrawableAmount.ts │ │ ├── getRewardsAmount.spec.ts │ │ ├── getRewardsAmount.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── withdraw.spec.ts │ │ └── withdraw.ts ├── index.ts ├── l2 │ ├── client │ │ └── index.ts │ ├── contract.spec.ts │ ├── contract.ts │ ├── dev │ │ ├── abi.ts │ │ └── index.ts │ ├── erc20 │ │ ├── abi.ts │ │ └── index.ts │ ├── index.ts │ ├── lockup │ │ ├── abi.ts │ │ ├── getLockedupProperties.spec.ts │ │ ├── getLockedupProperties.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── totalLocked.spec.ts │ │ ├── totalLocked.ts │ │ ├── totalLockedForProperty.spec.ts │ │ └── totalLockedForProperty.ts │ ├── market-behavior │ │ ├── abi.ts │ │ └── index.ts │ ├── market-factory │ │ ├── abi.ts │ │ ├── getEnabledMarkets.spec.ts │ │ ├── getEnabledMarkets.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── market │ │ ├── abi.ts │ │ ├── authenticate.ts │ │ ├── getAuthenticatedProperties.spec.ts │ │ ├── getAuthenticatedProperties.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── name.spec.ts │ │ └── name.ts │ ├── metrics-factory │ │ ├── abi.ts │ │ ├── authenticatedPropertiesCount.spec.ts │ │ ├── authenticatedPropertiesCount.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── metricsCount.spec.ts │ │ ├── metricsCount.ts │ │ ├── metricsOfProperty.spec.ts │ │ └── metricsOfProperty.ts │ ├── metrics │ │ ├── abi.ts │ │ └── index.ts │ ├── policy-factory │ │ ├── abi.ts │ │ └── index.ts │ ├── policy │ │ ├── abi.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── marketVotingSeconds.spec.ts │ │ ├── marketVotingSeconds.ts │ │ ├── policyVotingSeconds.spec.ts │ │ └── policyVotingSeconds.ts │ ├── property-factory │ │ ├── abi.ts │ │ ├── createAndAuthenticate.ts │ │ ├── getPropertiesOfAuthor.spec.ts │ │ ├── getPropertiesOfAuthor.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── property │ │ ├── abi.ts │ │ ├── getBalances.spec.ts │ │ ├── getBalances.ts │ │ ├── index.spec.ts │ │ └── index.ts │ ├── registry │ │ ├── abi.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── registries.spec.ts │ │ └── registries.ts │ ├── s-tokens │ │ ├── abi.ts │ │ └── index.ts │ └── withdraw │ │ ├── abi.ts │ │ ├── calculateRewardAmount.spec.ts │ │ ├── calculateRewardAmount.ts │ │ ├── index.spec.ts │ │ ├── index.ts │ │ ├── transferHistory.spec.ts │ │ ├── transferHistory.ts │ │ ├── transferHistoryLength.spec.ts │ │ ├── transferHistoryLength.ts │ │ ├── transferHistoryLengthOfRecipient.spec.ts │ │ ├── transferHistoryLengthOfRecipient.ts │ │ ├── transferHistoryLengthOfSender.spec.ts │ │ ├── transferHistoryLengthOfSender.ts │ │ ├── transferHistoryOfRecipientByIndex.spec.ts │ │ ├── transferHistoryOfRecipientByIndex.ts │ │ ├── transferHistoryOfSenderByIndex.spec.ts │ │ └── transferHistoryOfSenderByIndex.ts └── marketAddresses.ts ├── package.json ├── renovate.json ├── rollup.config.d.js ├── rollup.config.js ├── tsconfig.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | agent/* 4 | l2/* 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Expected Behavior 2 | 3 | ## Actual Behavior 4 | 5 | ## Steps to Reproduce the Problem 6 | 7 | 1. 1. 1. 8 | 9 | ## Specifications 10 | 11 | - Version: 12 | - Platform: 13 | - Subsystem: 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | ## Proposed Changes 4 | 5 | - 6 | -------------------------------------------------------------------------------- /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | name: Node 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | strategy: 10 | matrix: 11 | node-version: [18.x] 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Use Node.js ${{ matrix.node-version }} 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - name: yarn install, lint, build, and test 20 | run: | 21 | yarn install 22 | yarn lint 23 | yarn build 24 | yarn test --maxWorkers=50% --silent 25 | env: 26 | CI: true 27 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | workflow_run: 5 | workflows: ['Node'] 6 | branches: [main] 7 | types: 8 | - completed 9 | 10 | jobs: 11 | publish: 12 | runs-on: ubuntu-latest 13 | if: ${{ github.event.workflow_run.conclusion == 'success' }} 14 | 15 | strategy: 16 | matrix: 17 | node-version: [18.x] 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | - name: Use Node.js ${{ matrix.node-version }} 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: ${{ matrix.node-version }} 25 | - name: yarn install, and build 26 | run: | 27 | yarn install 28 | yarn run build 29 | - uses: JS-DevTools/npm-publish@v3 30 | with: 31 | token: ${{ secrets.NPM_TOKEN }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | 63 | # build 64 | dist 65 | *.js 66 | !examples/*.js 67 | *.mjs 68 | *.d.ts 69 | *.ts.map 70 | !rollup.config.* 71 | .eslintcache 72 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint-staged 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | agent/* 4 | l2/* 5 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "useTabs": true 5 | } 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.codeActionsOnSave": { 3 | "source.fixAll.eslint": "explicit" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # dev-kit-js examples 2 | 3 | ## Usage 4 | 5 | `package.json` 6 | 7 | ``` 8 | { 9 | "name": "devkit-examples-sandbox", 10 | "version": "0.0.1", 11 | "type": "module", 12 | "license": "MIT", 13 | "scripts": { 14 | "start": "node index.js" 15 | }, 16 | "dependencies": { 17 | "@devprotocol/dev-kit": "^5.8.1", 18 | "ethers": "^5.5.2" 19 | } 20 | } 21 | ``` 22 | 23 | copy the script file you want to run into index.js. 24 | Then `yarn install` to prepare for execution. 25 | 26 | ``` 27 | $ cp xxx.js index.js 28 | $ yarn install 29 | $ tree -L 1 30 | . 31 | ├── index.js 32 | ├── node_modules 33 | ├── package.json 34 | └── yarn.lock 35 | ``` 36 | 37 | run example script (with local ethereum node. like this `http://localhost:8545`): 38 | 39 | ``` 40 | $ yarn start 41 | ``` 42 | 43 | run example script (with infura) 44 | 45 | ``` 46 | $ WEB3_PROVIDER_URL=https://mainnet.infura.io/v3/xxxx yarn start 47 | ``` 48 | -------------------------------------------------------------------------------- /examples/get-property-info.js: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { contractFactory, addresses } from '@devprotocol/dev-kit' 3 | 4 | // use main net 5 | const registryContractAddress = addresses.eth.main.registry 6 | const provider = new ethers.providers.JsonRpcProvider( 7 | process.env.WEB3_PROVIDER_URL, 8 | ) 9 | const contract = contractFactory(provider) 10 | const propertyAddress = '0xac1AC9d00314aE7B4a7d6DbEE4860bECedF92309' 11 | const lockupContractAddress = await contract 12 | .registry(registryContractAddress) 13 | .lockup() 14 | 15 | const propertyStakingAmount = await contract 16 | .lockup(lockupContractAddress) 17 | .getPropertyValue(propertyAddress) 18 | const stakingAmount = ethers.BigNumber.from(propertyStakingAmount).div( 19 | new ethers.BigNumber.from(10).pow(18), 20 | ) 21 | console.log( 22 | `${propertyAddress}'s staking amount is ${stakingAmount.toBigInt()} DEV`, 23 | ) 24 | 25 | const propertyRewards = await contract 26 | .lockup(lockupContractAddress) 27 | .calculateRewardAmount(propertyAddress) 28 | const reward = ethers.BigNumber.from(propertyRewards[0]).div( 29 | new ethers.BigNumber.from(10).pow(36), 30 | ) 31 | console.log(`${propertyAddress}'s rewards is ${reward.toBigInt()} DEV`) 32 | -------------------------------------------------------------------------------- /examples/get-stats.js: -------------------------------------------------------------------------------- 1 | import { getStats } from '@devprotocol/dev-kit' 2 | 3 | const stats = await getStats() 4 | console.log(stats) 5 | -------------------------------------------------------------------------------- /examples/get-stoken-info.js: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { contractFactory, addresses } from '@devprotocol/dev-kit' 3 | 4 | // use main net 5 | const contractAddress = addresses.eth.main.sTokens 6 | const provider = new ethers.providers.JsonRpcProvider( 7 | process.env.WEB3_PROVIDER_URL, 8 | ) 9 | const contract = contractFactory(provider) 10 | const propertyAddress = '0xac1AC9d00314aE7B4a7d6DbEE4860bECedF92309' 11 | 12 | const getSTokenIdsByPropertyAddress = async (contract, propertyAddress) => { 13 | const res = await contract 14 | .sTokens(contractAddress) 15 | .positionsOfProperty(propertyAddress) 16 | return res 17 | } 18 | 19 | const getSTokenPositions = async (contract, sTokenId) => { 20 | const res = await contract.sTokens(contractAddress).positions(sTokenId) 21 | return res 22 | } 23 | 24 | const getSTokenRewards = (contract, sTokenId) => { 25 | return contract.sTokens(contractAddress).rewards(sTokenId) 26 | } 27 | 28 | // get stoken ids 29 | const sTokenIds = await getSTokenIdsByPropertyAddress(contract, propertyAddress) 30 | 31 | // get postions data by stoken id 32 | const res = await Promise.all( 33 | sTokenIds.map(async (sTokenId) => { 34 | const positions = await getSTokenPositions(contract, sTokenId) 35 | const rewards = await getSTokenRewards(contract, sTokenId) 36 | return { sTokenId, positions, rewards } 37 | }), 38 | ) 39 | console.log(res) 40 | -------------------------------------------------------------------------------- /lib/agent/common/agentAddresses.ts: -------------------------------------------------------------------------------- 1 | export const agentAddresses = { 2 | eth: { 3 | main: { 4 | swap: { 5 | v2: '0x6400264F991de614048838a7d4B536733BCE3069', 6 | v3: undefined, 7 | }, 8 | }, 9 | }, 10 | arbitrum: { 11 | one: { 12 | swap: { 13 | v2: undefined, 14 | v3: '0x60Ca7E3960e5F143DdB42B19B64F65c27cAD561d', 15 | }, 16 | }, 17 | rinkeby: { 18 | swap: { v2: undefined, v3: '0x4cd6B431B7A242D51B4D96aE5839a8b8f060F7A9' }, 19 | }, 20 | }, 21 | polygon: { 22 | mainnet: { 23 | swap: { 24 | v2: undefined, 25 | v3: '0x9265Cf9e6Dc5B163bDB75d51661Ca8EA3b6150c4', 26 | }, 27 | swapArbitraryTokens: { 28 | swap: '0xad7CaC908DfF8Dcd1D0d8d0FE3edD25bf339EB57', 29 | }, 30 | usdc: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', 31 | weth: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', 32 | }, 33 | mumbai: { 34 | swap: { 35 | v2: undefined, 36 | v3: '0x60650E5a95864b989C8b7B0357a2d4979a34c6AF', 37 | }, 38 | swapArbitraryTokens: { 39 | swap: '0x927B51D9Edd43BFDE3586E99BfaCBE08135374AA', 40 | }, 41 | usdc: '0xFEca406dA9727A25E71e732F9961F680059eF1F9', 42 | weth: '0x3c8d6A6420C922c88577352983aFFdf7b0F977cA', 43 | }, 44 | }, 45 | } as const 46 | -------------------------------------------------------------------------------- /lib/agent/common/clients/clientsMetricsFactory.ts: -------------------------------------------------------------------------------- 1 | import { l2AvailableNetworks } from '../const' 2 | import type { UndefinedOr } from '@devprotocol/util-ts' 3 | import { 4 | createMetricsFactoryContract as createMetricsFactoryContractL2, 5 | MetricsFactoryContract as MetricsFactoryContractL2, 6 | } from '../../../l2/metrics-factory' 7 | import { ContractRunner } from 'ethers' 8 | 9 | type Results = readonly [undefined, UndefinedOr] 10 | 11 | const cache: WeakMap = new WeakMap() 12 | 13 | export const clientsMetricsFactory = async ( 14 | provider: ContractRunner, 15 | ): Promise => { 16 | const res = 17 | cache.get(provider) ?? 18 | (await (async () => { 19 | const net = await provider.provider?.getNetwork() 20 | const l1 = undefined 21 | const l2 = ((data) => 22 | data 23 | ? createMetricsFactoryContractL2(provider)(data.map.metricsFactory) 24 | : undefined)( 25 | l2AvailableNetworks.find( 26 | ({ chainId }) => chainId === Number(net?.chainId), 27 | ), 28 | ) 29 | const results: Results = [l1, l2] 30 | // eslint-disable-next-line functional/no-expression-statement 31 | cache.set(provider, results) 32 | return results 33 | })()) 34 | return res 35 | } 36 | -------------------------------------------------------------------------------- /lib/agent/common/clients/clientsMetricsGroup.ts: -------------------------------------------------------------------------------- 1 | import type { UndefinedOr } from '@devprotocol/util-ts' 2 | import { 3 | createMetricsGroupContract, 4 | CreateMetricsGroupContract, 5 | } from '../../../ethereum/metrics-group' 6 | import { clientsRegistry } from './clientsRegistry' 7 | import { ContractRunner } from 'ethers' 8 | 9 | type Results = readonly [UndefinedOr, undefined] 10 | 11 | const cache: WeakMap = new WeakMap() 12 | 13 | export const clientsMetricsGroup = async ( 14 | provider: ContractRunner, 15 | ): Promise => { 16 | const res = 17 | cache.get(provider) ?? 18 | (await (async () => { 19 | const [registry] = await clientsRegistry(provider) 20 | const l1 = registry 21 | ? createMetricsGroupContract(provider)(await registry.metricsGroup()) 22 | : undefined 23 | const l2 = undefined 24 | const results: Results = [l1, l2] 25 | // eslint-disable-next-line functional/no-expression-statement 26 | cache.set(provider, results) 27 | return results 28 | })()) 29 | return res 30 | } 31 | -------------------------------------------------------------------------------- /lib/agent/common/clients/clientsUtilsSwapTokensForStake.ts: -------------------------------------------------------------------------------- 1 | import { AgentAvailableNetworks } from '../const' 2 | import type { UndefinedOr } from '@devprotocol/util-ts' 3 | import { 4 | createSwapArbitraryTokensContract, 5 | SwapArbitraryTokensContract, 6 | } from '../../fixtures/swap-arbitrary-tokens' 7 | import type { ContractRunner } from 'ethers' 8 | 9 | type Results = readonly [undefined, UndefinedOr] 10 | 11 | const cache: WeakMap = new WeakMap() 12 | 13 | export const clientsUtilsSwapTokensForStake = async ( 14 | provider: ContractRunner, 15 | ): Promise => { 16 | const res = 17 | cache.get(provider) ?? 18 | (await (async () => { 19 | const net = await provider.provider?.getNetwork() 20 | const detectedNetwork = AgentAvailableNetworks.find( 21 | ({ chainId }) => chainId === Number(net?.chainId), 22 | ) 23 | const cont = detectedNetwork 24 | ? createSwapArbitraryTokensContract(provider)( 25 | detectedNetwork.map.swapArbitraryTokens?.swap || '', 26 | ) 27 | : undefined 28 | const results: Results = [undefined, cont] 29 | // eslint-disable-next-line functional/no-expression-statement 30 | cache.set(provider, results) 31 | return results 32 | })()) 33 | return res 34 | } 35 | -------------------------------------------------------------------------------- /lib/agent/fixtures/swap-arbitrary-tokens/getEstimatedDevForTokens.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers, solidityPacked } from 'ethers' 3 | import { execute, QueryOption } from '../../../common/utils/execute' 4 | import { pathOf } from './path-of' 5 | 6 | export type CreateGetEstimatedDevForTokensCaller = ( 7 | contract: ethers.Contract, 8 | ) => ( 9 | path: readonly (string | bigint)[], 10 | tokenAmount: string, 11 | ) => Promise 12 | 13 | export const createGetEstimatedDevForTokensCaller: CreateGetEstimatedDevForTokensCaller = 14 | 15 | (contract: ethers.Contract) => 16 | async (path: readonly (string | bigint)[], tokenAmount: string) => { 17 | const res = await execute({ 18 | contract, 19 | method: 'getEstimatedDevForTokens', 20 | args: [pathOf(path), tokenAmount], 21 | mutation: false, 22 | static: true, 23 | }) 24 | 25 | return res 26 | } 27 | -------------------------------------------------------------------------------- /lib/agent/fixtures/swap-arbitrary-tokens/getEstimatedTokensForDev.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers, solidityPacked } from 'ethers' 3 | import { execute, QueryOption } from '../../../common/utils/execute' 4 | import { pathOf } from './path-of' 5 | 6 | export type CreateGetEstimatedTokensForDevCaller = ( 7 | contract: ethers.Contract, 8 | ) => (path: readonly (string | bigint)[], devAmount: string) => Promise 9 | 10 | export const createGetEstimatedTokensForDevCaller: CreateGetEstimatedTokensForDevCaller = 11 | 12 | (contract: ethers.Contract) => 13 | async (path: readonly (string | bigint)[], devAmount: string) => { 14 | const res = await execute({ 15 | contract, 16 | method: 'getEstimatedTokensForDev', 17 | args: [pathOf(path), devAmount], 18 | mutation: false, 19 | static: true, 20 | }) 21 | 22 | return res 23 | } 24 | -------------------------------------------------------------------------------- /lib/agent/fixtures/swap-arbitrary-tokens/path-of.ts: -------------------------------------------------------------------------------- 1 | import { solidityPacked } from 'ethers' 2 | 3 | export const pathOf = (_path: readonly (string | bigint)[]): string => { 4 | const abi = _path.map((value) => 5 | typeof value === 'string' 6 | ? 'address' 7 | : typeof value === 'bigint' 8 | ? 'uint24' 9 | : (undefined as never), 10 | ) 11 | const path = solidityPacked(abi, _path) 12 | 13 | return path 14 | } 15 | -------------------------------------------------------------------------------- /lib/agent/fixtures/swap/getEstimatedDevForEth.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../../common/utils/execute' 4 | 5 | export type CreateGetEstimatedDevForEthCaller = ( 6 | contract: ethers.Contract, 7 | ) => (ethAmount: string) => Promise 8 | 9 | export const createGetEstimatedDevForEthCaller: CreateGetEstimatedDevForEthCaller = 10 | (contract: ethers.Contract) => async (ethAmount: string) => { 11 | const res = await execute({ 12 | contract, 13 | method: 'getEstimatedDevForEth', 14 | args: [ethAmount], 15 | mutation: false, 16 | static: true, 17 | }) 18 | 19 | return Array.isArray(res) ? res[1] : res 20 | } 21 | -------------------------------------------------------------------------------- /lib/agent/fixtures/swap/getEstimatedEthForDev.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../../common/utils/execute' 4 | 5 | export type CreateGetEstimatedEthForDevCaller = ( 6 | contract: ethers.Contract, 7 | ) => (devAmount: string) => Promise 8 | 9 | export const createGetEstimatedEthForDevCaller: CreateGetEstimatedEthForDevCaller = 10 | (contract: ethers.Contract) => async (devAmount: string) => { 11 | const res = await execute({ 12 | contract, 13 | method: 'getEstimatedEthForDev', 14 | args: [devAmount], 15 | mutation: false, 16 | static: true, 17 | }) 18 | return Array.isArray(res) ? res[0] : res 19 | } 20 | -------------------------------------------------------------------------------- /lib/agent/positionsClaim.ts: -------------------------------------------------------------------------------- 1 | import type { TransactionResponse } from 'ethers' 2 | import { FallbackableOverrides } from '../common/utils/execute' 3 | import type { ContractRunner } from 'ethers' 4 | import { UndefinedOr } from '@devprotocol/util-ts' 5 | 6 | type PositionsClaim = (options: { 7 | readonly provider: ContractRunner 8 | readonly positionId: number 9 | readonly withdrawalAmount: string 10 | readonly overrides?: FallbackableOverrides 11 | }) => Promise> 12 | -------------------------------------------------------------------------------- /lib/agent/positionsCreate.spec.ts: -------------------------------------------------------------------------------- 1 | import { positionsCreate } from './positionsCreate' 2 | 3 | describe('positionsCreate.ts', () => { 4 | it.todo('TODO: Testing it') 5 | }) 6 | -------------------------------------------------------------------------------- /lib/agent/positionsGet.ts: -------------------------------------------------------------------------------- 1 | import type { ContractRunner } from 'ethers' 2 | import { UndefinedOr } from '@devprotocol/util-ts' 3 | import { Positions } from '../ethereum/s-tokens/positions' 4 | 5 | type PositionsGet = (options: { 6 | readonly provider: ContractRunner 7 | readonly positionId: number 8 | }) => Promise> 9 | -------------------------------------------------------------------------------- /lib/agent/positionsList.ts: -------------------------------------------------------------------------------- 1 | import type { ContractRunner } from 'ethers' 2 | import { UndefinedOr } from '@devprotocol/util-ts' 3 | import { Positions } from '../ethereum/s-tokens/positions' 4 | 5 | type PositionsList = (options: { 6 | readonly provider: ContractRunner 7 | readonly destination?: string 8 | readonly user?: string 9 | }) => Promise> 10 | -------------------------------------------------------------------------------- /lib/agent/positionsUpdate.ts: -------------------------------------------------------------------------------- 1 | import { FallbackableOverrides } from '../common/utils/execute' 2 | import type { ContractRunner } from 'ethers' 3 | import { UndefinedOr } from '@devprotocol/util-ts' 4 | import { ApproveIfNeededResult } from './common/approveIfNeeded' 5 | 6 | type PositionsUpdate = (options: { 7 | readonly provider: ContractRunner 8 | readonly positionId: number 9 | readonly additionalAmount: string 10 | readonly overrides?: FallbackableOverrides 11 | }) => Promise> 12 | -------------------------------------------------------------------------------- /lib/agent/propertiesAuthenticate.ts: -------------------------------------------------------------------------------- 1 | import { FallbackableOverrides } from '../common/utils/execute' 2 | import type { ContractRunner } from 'ethers' 3 | import type { TransactionResponse } from 'ethers' 4 | import { UndefinedOr } from '@devprotocol/util-ts' 5 | 6 | type PropertiesAuthenticate = (options: { 7 | readonly provider: ContractRunner 8 | readonly destination: string 9 | readonly authentication: { 10 | readonly market: string 11 | readonly options: readonly string[] 12 | } 13 | readonly overrides?: FallbackableOverrides 14 | }) => Promise< 15 | UndefinedOr< 16 | TransactionResponse & { 17 | readonly wait: () => Promise 18 | } 19 | > 20 | > 21 | -------------------------------------------------------------------------------- /lib/agent/propertiesCreate.ts: -------------------------------------------------------------------------------- 1 | import type { TransactionResponse } from 'ethers' 2 | import { FallbackableOverrides } from '../common/utils/execute' 3 | import type { ContractRunner } from 'ethers' 4 | import { UndefinedOr } from '@devprotocol/util-ts' 5 | 6 | type PropertiesCreate = (options: { 7 | readonly provider: ContractRunner 8 | readonly name: string 9 | readonly symbol: string 10 | readonly author: string 11 | readonly overrides?: FallbackableOverrides 12 | }) => Promise> 13 | -------------------------------------------------------------------------------- /lib/agent/propertiesCreateToAuthenticate.ts: -------------------------------------------------------------------------------- 1 | import { FallbackableOverrides } from '../common/utils/execute' 2 | import type { ContractRunner } from 'ethers' 3 | import type { TransactionResponse } from 'ethers' 4 | import { UndefinedOr } from '@devprotocol/util-ts' 5 | 6 | type PropertiesCreateToAuthenticate = (options: { 7 | readonly provider: ContractRunner 8 | readonly name: string 9 | readonly symbol: string 10 | readonly author: string 11 | readonly authentication: { 12 | readonly market: string 13 | readonly options: readonly string[] 14 | readonly overrides?: FallbackableOverrides 15 | } 16 | readonly overrides?: FallbackableOverrides 17 | }) => Promise< 18 | UndefinedOr< 19 | TransactionResponse & { 20 | readonly wait: () => Promise 21 | } 22 | > 23 | > 24 | -------------------------------------------------------------------------------- /lib/agent/propertiesDeauthenticate.ts: -------------------------------------------------------------------------------- 1 | import { FallbackableOverrides } from '../common/utils/execute' 2 | import type { ContractRunner } from 'ethers' 3 | import type { TransactionResponse } from 'ethers' 4 | import { UndefinedOr } from '@devprotocol/util-ts' 5 | 6 | type PropertiesDeauthenticate = (options: { 7 | readonly provider: ContractRunner 8 | readonly destination: string 9 | readonly authentication: { 10 | readonly market: string 11 | readonly id: string 12 | } 13 | readonly overrides?: FallbackableOverrides 14 | }) => Promise> 15 | -------------------------------------------------------------------------------- /lib/agent/propertiesList.ts: -------------------------------------------------------------------------------- 1 | import type { ContractRunner } from 'ethers' 2 | import { UndefinedOr } from '@devprotocol/util-ts' 3 | 4 | type PropertiesList = (options: { 5 | readonly provider: ContractRunner 6 | readonly user: string 7 | }) => Promise> 8 | -------------------------------------------------------------------------------- /lib/common/erc20/allowance.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | 4 | export type CreateAllowanceCaller = ( 5 | contract: ethers.Contract, 6 | ) => (from: string, to: string) => Promise 7 | 8 | export const createAllowanceCaller: CreateAllowanceCaller = 9 | (contract: ethers.Contract) => async (from: string, to: string) => 10 | execute({ 11 | contract, 12 | method: 'allowance', 13 | args: [from, to], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/common/erc20/approve.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateApproveCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | to: string, 13 | value: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createApproveCaller: CreateApproveCaller = 18 | (contract: ethers.Contract) => 19 | async (to: string, value: string, overrides?: FallbackableOverrides) => 20 | execute({ 21 | contract, 22 | method: 'approve', 23 | mutation: true, 24 | args: [to, value], 25 | overrides, 26 | }) 27 | -------------------------------------------------------------------------------- /lib/common/erc20/balanceOf.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | 4 | export type CreateBalanceOfCaller = ( 5 | contract: ethers.Contract, 6 | ) => (address: string) => Promise 7 | 8 | export const createBalanceOfCaller: CreateBalanceOfCaller = 9 | (contract: ethers.Contract) => async (address: string) => 10 | execute({ 11 | contract, 12 | method: 'balanceOf', 13 | args: [address], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/common/erc20/decimals.spec.ts: -------------------------------------------------------------------------------- 1 | import { createDecimalsCaller } from './decimals' 2 | 3 | describe('dcimals.spec.ts', () => { 4 | describe('createDecimalsCaller', () => { 5 | it('call success', async () => { 6 | const value = '18' 7 | 8 | const contract = { 9 | decimals: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createDecimalsCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | decimals: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createDecimalsCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/common/erc20/decimals.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateDecimalsCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createDecimalsCaller: CreateDecimalsCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'decimals', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/common/erc20/name.spec.ts: -------------------------------------------------------------------------------- 1 | import { createNameCaller } from './name' 2 | 3 | describe('name.spec.ts', () => { 4 | describe('createNameCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const contract = { 9 | name: jest.fn().mockImplementation(async () => Promise.resolve(value)), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createNameCaller(contract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | name: jest.fn().mockImplementation(async () => Promise.reject(error)), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createNameCaller(contract as any) 31 | 32 | const result = await caller().catch((err) => err) 33 | 34 | expect(result).toEqual(error) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /lib/common/erc20/name.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateNameCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createNameCaller: CreateNameCaller = (contract: ethers.Contract) => 10 | always( 11 | execute({ 12 | contract, 13 | method: 'name', 14 | mutation: false, 15 | }), 16 | ) 17 | -------------------------------------------------------------------------------- /lib/common/erc20/symbol.spec.ts: -------------------------------------------------------------------------------- 1 | import { createSymbolCaller } from './symbol' 2 | 3 | describe('symbol.spec.ts', () => { 4 | describe('createSymbolCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const contract = { 9 | symbol: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createSymbolCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | symbol: jest.fn().mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createSymbolCaller(contract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/common/erc20/symbol.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateSymbolCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createSymbolCaller: CreateSymbolCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'symbol', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/common/erc20/totalSupply.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTotalSupplyCaller } from './totalSupply' 2 | 3 | describe('totalSupply.spec.ts', () => { 4 | describe('createTotalSupplyCaller', () => { 5 | it('call success', async () => { 6 | const value = '10000000000000000000000000' 7 | 8 | const contract = { 9 | totalSupply: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTotalSupplyCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | totalSupply: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createTotalSupplyCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/common/erc20/totalSupply.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateTotalSupplyCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createTotalSupplyCaller: CreateTotalSupplyCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'totalSupply', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/common/erc20/transfer.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateTransferCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | to: string, 13 | value: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createTransferCaller: CreateTransferCaller = 18 | (contract: ethers.Contract) => 19 | async (to: string, value: string, overrides?: FallbackableOverrides) => 20 | execute({ 21 | contract, 22 | method: 'transfer', 23 | args: [to, value], 24 | mutation: true, 25 | overrides, 26 | }) 27 | -------------------------------------------------------------------------------- /lib/common/erc20/transferFrom.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateTransferFromCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | from: string, 13 | to: string, 14 | value: string, 15 | overrides?: FallbackableOverrides, 16 | ) => Promise 17 | 18 | export const createTransferFromCaller: CreateTransferFromCaller = 19 | (contract: ethers.Contract) => 20 | async ( 21 | from: string, 22 | to: string, 23 | value: string, 24 | overrides?: FallbackableOverrides, 25 | ) => 26 | execute({ 27 | contract, 28 | method: 'transferFrom', 29 | mutation: true, 30 | args: [from, to, value], 31 | overrides, 32 | }) 33 | -------------------------------------------------------------------------------- /lib/common/option.ts: -------------------------------------------------------------------------------- 1 | import type { ContractRunner } from 'ethers' 2 | 3 | export type CustomOptions = { 4 | readonly from?: string 5 | readonly gasPrice?: string 6 | readonly gas: number 7 | readonly data: string 8 | } 9 | 10 | export type ValidProvider = ContractRunner 11 | -------------------------------------------------------------------------------- /lib/common/utils/arrayify.spec.ts: -------------------------------------------------------------------------------- 1 | import { arrayify } from './arrayify' 2 | 3 | describe('arrayify.ts', () => { 4 | it("Returns an array of values from the passed object by numeric key's", async () => { 5 | const obj = { 6 | 0: 'A', 7 | 1: 'B', 8 | 2: 'C', 9 | str: 'D', 10 | } 11 | const result = arrayify(obj) 12 | expect(result).toEqual(['A', 'B', 'C']) 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /lib/common/utils/arrayify.ts: -------------------------------------------------------------------------------- 1 | export const arrayify = (obj: Record): ReadonlyArray => { 2 | const keys = Object.keys(obj) 3 | const numericKeys = keys.filter((k) => !isNaN(Number(k))) 4 | return numericKeys.map((k) => obj[k]) 5 | } 6 | -------------------------------------------------------------------------------- /lib/common/utils/const.ts: -------------------------------------------------------------------------------- 1 | export const DEV_GRAPHQL_ENDPOINT = 'https://api.devprotocol.xyz/v1/graphql' 2 | -------------------------------------------------------------------------------- /lib/common/utils/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { DevkitUtils, utils } from './index' 2 | import { execute } from './execute' 3 | import { arrayify } from './arrayify' 4 | 5 | describe('index.ts', () => { 6 | describe('utils', () => { 7 | it('check return object', () => { 8 | const expected: DevkitUtils = { 9 | execute, 10 | arrayify, 11 | } 12 | 13 | const result = utils 14 | 15 | expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /lib/common/utils/index.ts: -------------------------------------------------------------------------------- 1 | import { execute } from './execute' 2 | import { arrayify } from './arrayify' 3 | 4 | export type DevkitUtils = { 5 | readonly execute: typeof execute 6 | readonly arrayify: typeof arrayify 7 | } 8 | 9 | export const utils: DevkitUtils = { 10 | execute, 11 | arrayify, 12 | } 13 | 14 | export { execute, arrayify } 15 | -------------------------------------------------------------------------------- /lib/ethereum/allocator/abi.ts: -------------------------------------------------------------------------------- 1 | export const allocatorAbi = [ 2 | { 3 | inputs: [ 4 | { 5 | internalType: 'address', 6 | name: '_config', 7 | type: 'address', 8 | }, 9 | ], 10 | payable: false, 11 | stateMutability: 'nonpayable', 12 | type: 'constructor', 13 | }, 14 | { 15 | constant: true, 16 | inputs: [], 17 | name: 'configAddress', 18 | outputs: [ 19 | { 20 | internalType: 'address', 21 | name: '', 22 | type: 'address', 23 | }, 24 | ], 25 | payable: false, 26 | stateMutability: 'view', 27 | type: 'function', 28 | }, 29 | { 30 | constant: true, 31 | inputs: [], 32 | name: 'calculateMaxRewardsPerBlock', 33 | outputs: [ 34 | { 35 | internalType: 'uint256', 36 | name: '', 37 | type: 'uint256', 38 | }, 39 | ], 40 | payable: false, 41 | stateMutability: 'view', 42 | type: 'function', 43 | }, 44 | { 45 | constant: false, 46 | inputs: [ 47 | { 48 | internalType: 'address', 49 | name: '_property', 50 | type: 'address', 51 | }, 52 | { 53 | internalType: 'address', 54 | name: '_from', 55 | type: 'address', 56 | }, 57 | { 58 | internalType: 'address', 59 | name: '_to', 60 | type: 'address', 61 | }, 62 | ], 63 | name: 'beforeBalanceChange', 64 | outputs: [], 65 | payable: false, 66 | stateMutability: 'nonpayable', 67 | type: 'function', 68 | }, 69 | ] 70 | -------------------------------------------------------------------------------- /lib/ethereum/allocator/calculateMaxRewardsPerBlock.spec.ts: -------------------------------------------------------------------------------- 1 | import { createCalculateMaxRewardsPerBlockCaller } from './calculateMaxRewardsPerBlock' 2 | 3 | describe('calculateMaxRewardsPerBlock.spec.ts', () => { 4 | describe('createCalculateMaxRewardsPerBlockCaller', () => { 5 | it('call failure', async () => { 6 | const error = 'error' 7 | const allocatorContract = { 8 | calculateMaxRewardsPerBlock: jest 9 | .fn() 10 | .mockImplementation(async () => Promise.reject(error)), 11 | } 12 | 13 | const caller = createCalculateMaxRewardsPerBlockCaller( 14 | allocatorContract as any, 15 | ) 16 | const result = await caller().catch((err) => err) 17 | expect(result).toEqual(error) 18 | }) 19 | }) 20 | }) 21 | -------------------------------------------------------------------------------- /lib/ethereum/allocator/calculateMaxRewardsPerBlock.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateCalculateMaxRewardsPerBlockCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createCalculateMaxRewardsPerBlockCaller: CreateCalculateMaxRewardsPerBlockCaller = 10 | (contract: ethers.Contract) => 11 | always( 12 | execute({ 13 | contract, 14 | method: 'calculateMaxRewardsPerBlock', 15 | mutation: false, 16 | }), 17 | ) 18 | -------------------------------------------------------------------------------- /lib/ethereum/allocator/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { allocatorAbi } from './abi' 3 | import { createCalculateMaxRewardsPerBlockCaller } from './calculateMaxRewardsPerBlock' 4 | 5 | export type CreateAllocatorContract = { 6 | readonly calculateMaxRewardsPerBlock: () => Promise 7 | readonly contract: () => ethers.Contract 8 | } 9 | 10 | export const createAllocatorContract = 11 | (provider: ContractRunner) => 12 | (address: string): CreateAllocatorContract => { 13 | const contract = new ethers.Contract(address, [...allocatorAbi], provider) 14 | return { 15 | calculateMaxRewardsPerBlock: 16 | createCalculateMaxRewardsPerBlockCaller(contract), 17 | contract: () => contract, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/ethereum/client/createDetectSTokens.spec.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable functional/no-class */ 2 | import { createDetectSTokens } from './createDetectSTokens' 3 | 4 | describe('detectSTokens.ts', () => { 5 | describe('createDetectSTokens', () => { 6 | it('returns an array of IDs of the staking positions for the Property owned by the user', async () => { 7 | const propertyAddress = '0xPropertyAddress' 8 | const accountAddress = '0xAccountAddress' 9 | const sTokens = { 10 | positionsOfProperty: (a: string) => 11 | Promise.resolve( 12 | a === propertyAddress ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : [], 13 | ), 14 | positionsOfOwner: (a: string) => 15 | Promise.resolve(a === accountAddress ? [9, 5, 1, 2, 12] : []), 16 | } 17 | const result = await createDetectSTokens(sTokens as any)( 18 | propertyAddress, 19 | accountAddress, 20 | ) 21 | const expected = [1, 2, 5, 9] 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | }) 26 | }) 27 | -------------------------------------------------------------------------------- /lib/ethereum/client/createDetectSTokens.ts: -------------------------------------------------------------------------------- 1 | import { intersection, sort } from 'ramda' 2 | import { STokensContract } from '../s-tokens' 3 | 4 | export type CreateDetectSTokens = ( 5 | sTokens: STokensContract, 6 | ) => ( 7 | propertyAddress: string, 8 | accountAddress: string, 9 | ) => Promise 10 | 11 | const diff = function (a: number, b: number): number { 12 | return a - b 13 | } 14 | const asc = sort(diff) 15 | 16 | export const createDetectSTokens: CreateDetectSTokens = 17 | (sTokens: STokensContract) => 18 | async ( 19 | propertyAddress: string, 20 | accountAddress: string, 21 | ): Promise => { 22 | const [listForProperty, listForOwner] = await Promise.all([ 23 | sTokens.positionsOfProperty(propertyAddress), 24 | sTokens.positionsOfOwner(accountAddress), 25 | ]) 26 | return asc(intersection(listForProperty, listForOwner)) 27 | } 28 | -------------------------------------------------------------------------------- /lib/ethereum/client/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { DevkitClient, client } from './index' 2 | import { createDetectSTokens } from './createDetectSTokens' 3 | 4 | describe('index.ts', () => { 5 | describe('client', () => { 6 | it('check return object', () => { 7 | const expected: DevkitClient = { 8 | createDetectSTokens, 9 | } 10 | 11 | const result = client 12 | 13 | expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) 14 | }) 15 | }) 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/client/index.ts: -------------------------------------------------------------------------------- 1 | import { createDetectSTokens } from './createDetectSTokens' 2 | 3 | export type DevkitClient = { 4 | readonly createDetectSTokens: typeof createDetectSTokens 5 | } 6 | 7 | export const client: DevkitClient = { 8 | createDetectSTokens, 9 | } 10 | 11 | export { createDetectSTokens } 12 | -------------------------------------------------------------------------------- /lib/ethereum/dev/deposit.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | MutationOption, 5 | FallbackableOverrides, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateDepositCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | to: string, 13 | value: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createDepositCaller: CreateDepositCaller = 18 | (contract: ethers.Contract) => 19 | async (to: string, value: string, overrides?: FallbackableOverrides) => 20 | execute({ 21 | contract, 22 | method: 'deposit', 23 | args: [to, value], 24 | mutation: true, 25 | overrides, 26 | }) 27 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateCalculateCumulativeHoldersRewardAmountCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string) => Promise 7 | 8 | export const createCalculateCumulativeHoldersRewardAmountCaller: CreateCalculateCumulativeHoldersRewardAmountCaller = 9 | (contract: ethers.Contract) => async (propertyAddress: string) => 10 | execute({ 11 | contract, 12 | method: 'calculateCumulativeHoldersRewardAmount', 13 | args: [propertyAddress], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/calculateCumulativeRewardPrices.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | import { arrayify } from '../../common/utils/arrayify' 5 | 6 | export type CreateCalculateCumulativeRewardPricesCaller = ( 7 | contract: ethers.Contract, 8 | ) => () => Promise 9 | 10 | export const createCalculateCumulativeRewardPricesCaller: CreateCalculateCumulativeRewardPricesCaller = 11 | (contract: ethers.Contract) => 12 | always( 13 | execute>({ 14 | contract, 15 | method: 'calculateCumulativeRewardPrices', 16 | mutation: false, 17 | }).then((r) => arrayify(r) as readonly [string, string, string, string]), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/calculateRewardAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { arrayify } from '../../common/utils/arrayify' 4 | 5 | export type CreateCalculateRewardAmountCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string) => Promise 8 | 9 | export const createCalculateRewardAmountCaller: CreateCalculateRewardAmountCaller = 10 | (contract: ethers.Contract) => async (propertyAddress: string) => 11 | execute>({ 12 | contract, 13 | method: 'calculateRewardAmount', 14 | args: [propertyAddress], 15 | mutation: false, 16 | }).then((r) => arrayify(r) as readonly [string, string]) 17 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/calculateWithdrawableInterestAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateCalculateWithdrawableInterestAmountCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, account: string) => Promise 7 | 8 | export const createCalculateWithdrawableInterestAmountCaller: CreateCalculateWithdrawableInterestAmountCaller = 9 | 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string, account: string) => 12 | execute({ 13 | contract, 14 | method: 'calculateWithdrawableInterestAmount', 15 | args: [propertyAddress, account], 16 | mutation: false, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreatecalculateWithdrawableInterestAmountByPositionCaller = ( 6 | contract: ethers.Contract, 7 | ) => (positionTokenId: string) => Promise 8 | 9 | export const createcalculateWithdrawableInterestAmountByPositionCaller: CreatecalculateWithdrawableInterestAmountByPositionCaller = 10 | (contract: ethers.Contract) => async (positionTokenId: string) => 11 | execute({ 12 | contract, 13 | method: 'calculateWithdrawableInterestAmountByPosition', 14 | args: [positionTokenId], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/cap.spec.ts: -------------------------------------------------------------------------------- 1 | import { createCapCaller } from './cap' 2 | 3 | describe('cap.spec.ts', () => { 4 | describe('createCapCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const lockupContract = { 9 | cap: jest.fn().mockImplementation(async () => Promise.resolve(value)), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createCapCaller(lockupContract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const lockupContract = { 26 | cap: jest.fn().mockImplementation(async () => Promise.reject(error)), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createCapCaller(lockupContract as any) 31 | 32 | const result = await caller().catch((err) => err) 33 | 34 | expect(result).toEqual(error) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/cap.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateCapCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createCapCaller: CreateCapCaller = (contract: ethers.Contract) => 10 | always( 11 | execute({ 12 | contract, 13 | method: 'cap', 14 | mutation: false, 15 | }), 16 | ) 17 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/depositToPosition.spec.ts: -------------------------------------------------------------------------------- 1 | import { createDepositToPositionCaller } from './depositToPosition' 2 | import { stubTransactionResposeFactory } from '../../common/utils/for-test' 3 | 4 | describe('depositToPosition.spec.ts', () => { 5 | describe('createDepositToPositionCaller', () => { 6 | it('call success', async () => { 7 | const expected = stubTransactionResposeFactory({}) 8 | const lockupContract = { 9 | depositToPosition: jest 10 | .fn() 11 | .mockImplementation(() => Promise.resolve(expected)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createDepositToPositionCaller(lockupContract as any) 16 | 17 | const result = await caller('32', '100') 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | const lockupContract = { 25 | depositToPosition: jest 26 | .fn() 27 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 28 | .mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createDepositToPositionCaller(lockupContract as any) 33 | 34 | const result = await caller('32', '100').catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/depositToPosition.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { 4 | execute, 5 | FallbackableOverrides, 6 | MutationOption, 7 | } from '../../common/utils/execute' 8 | import type { TransactionResponse } from 'ethers' 9 | 10 | export type CreateDepositToPositionCaller = ( 11 | contract: ethers.Contract, 12 | ) => ( 13 | positionTokenId: string, 14 | amount: string, 15 | overrides?: FallbackableOverrides, 16 | ) => Promise 17 | 18 | export const createDepositToPositionCaller: CreateDepositToPositionCaller = 19 | (contract: ethers.Contract) => 20 | async ( 21 | positionTokenId: string, 22 | amount: string, 23 | overrides?: FallbackableOverrides, 24 | ) => 25 | execute({ 26 | contract, 27 | method: 'depositToPosition', 28 | mutation: true, 29 | args: [positionTokenId, amount], 30 | overrides, 31 | }) 32 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/depositToProperty.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { 4 | execute, 5 | FallbackableOverrides, 6 | MutationOption, 7 | } from '../../common/utils/execute' 8 | import type { TransactionResponse } from 'ethers' 9 | 10 | export type CreateDepositToPropertyCaller = ( 11 | contract: ethers.Contract, 12 | ) => ( 13 | propertyAddress: string, 14 | amount: string, 15 | payload?: string | Uint8Array, 16 | overrides?: FallbackableOverrides, 17 | ) => Promise 18 | 19 | export const createDepositToPropertyCaller: CreateDepositToPropertyCaller = 20 | (contract: ethers.Contract) => 21 | async ( 22 | propertyAddress: string, 23 | amount: string, 24 | payload?: string | Uint8Array, 25 | overrides?: FallbackableOverrides, 26 | ) => 27 | execute({ 28 | contract, 29 | method: 'depositToProperty', 30 | mutation: true, 31 | args: payload 32 | ? [propertyAddress, amount, payload] 33 | : [propertyAddress, amount], 34 | overrides, 35 | interface: payload ? 'address,uint256,bytes32' : 'address,uint256', 36 | }) 37 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/getAllValue.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetAllValueCaller } from './getAllValue' 2 | 3 | describe('getAllValue.spec.ts', () => { 4 | describe('createGetAllValueCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const lockupContract = { 9 | getAllValue: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createGetAllValueCaller(lockupContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const lockupContract = { 28 | getAllValue: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createGetAllValueCaller(lockupContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/getAllValue.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateGetAllValueCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createGetAllValueCaller: CreateGetAllValueCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'getAllValue', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/getPropertyValue.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetPropertyValueCaller = ( 5 | contract: ethers.Contract, 6 | ) => (address: string) => Promise 7 | 8 | export const createGetPropertyValueCaller: CreateGetPropertyValueCaller = 9 | (contract: ethers.Contract) => async (address: string) => 10 | execute({ 11 | contract, 12 | method: 'getPropertyValue', 13 | args: [address], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/getStorageWithdrawalStatus.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetStorageWithdrawalStatusCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, accountAddress: string) => Promise 7 | 8 | export const createGetStorageWithdrawalStatusCaller: CreateGetStorageWithdrawalStatusCaller = 9 | 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string, accountAddress: string) => 12 | execute({ 13 | contract, 14 | method: 'getStorageWithdrawalStatus', 15 | args: [propertyAddress, accountAddress], 16 | mutation: false, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/getValue.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetValueCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, accountAddress: string) => Promise 7 | 8 | export const createGetValueCaller: CreateGetValueCaller = 9 | (contract: ethers.Contract) => 10 | async (propertyAddress: string, accountAddress: string) => 11 | execute({ 12 | contract, 13 | method: 'getValue', 14 | args: [propertyAddress, accountAddress], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/migrateToSTokens.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMigrateToSTokensCaller } from './migrateToSTokens' 2 | import { stubTransactionResposeFactory } from '../../common/utils/for-test' 3 | 4 | describe('migrateToSTokens.spec.ts', () => { 5 | describe('createMigrateToSTokensCaller', () => { 6 | it('call success', async () => { 7 | const expected = stubTransactionResposeFactory({}) 8 | const lockupContract = { 9 | migrateToSTokens: jest 10 | .fn() 11 | .mockImplementation(() => Promise.resolve(expected)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createMigrateToSTokensCaller(lockupContract as any) 16 | 17 | const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | const lockupContract = { 25 | migrateToSTokens: jest 26 | .fn() 27 | .mockImplementation(async () => Promise.reject(error)), 28 | } 29 | 30 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 31 | const caller = createMigrateToSTokensCaller(lockupContract as any) 32 | 33 | const result = await caller( 34 | '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', 35 | ).catch((err) => err) 36 | 37 | expect(result).toEqual(error) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/migrateToSTokens.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { 4 | execute, 5 | FallbackableOverrides, 6 | MutationOption, 7 | } from '../../common/utils/execute' 8 | import type { TransactionResponse } from 'ethers' 9 | 10 | export type CreateMigrateToSTokensCaller = ( 11 | contract: ethers.Contract, 12 | ) => ( 13 | propertyAddress: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createMigrateToSTokensCaller: CreateMigrateToSTokensCaller = 18 | (contract: ethers.Contract) => 19 | async (propertyAddress: string, overrides?: FallbackableOverrides) => 20 | execute({ 21 | contract, 22 | method: 'migrateToSTokens', 23 | mutation: true, 24 | args: [propertyAddress], 25 | overrides, 26 | }) 27 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateWithdrawCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | propertyAddress: string, 13 | amount: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createWithdrawCaller: CreateWithdrawCaller = 18 | (contract: ethers.Contract) => 19 | async ( 20 | propertyAddress: string, 21 | amount: string, 22 | overrides?: FallbackableOverrides, 23 | ) => 24 | execute({ 25 | contract, 26 | method: 'withdraw', 27 | mutation: true, 28 | args: [propertyAddress, amount], 29 | overrides, 30 | }) 31 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/withdrawByPosition.spec.ts: -------------------------------------------------------------------------------- 1 | import { createWithdrawByPositionCaller } from './withdrawByPosition' 2 | import { stubTransactionResposeFactory } from '../../common/utils/for-test' 3 | 4 | describe('withdrawByPosition.spec.ts', () => { 5 | describe('createWithdrawByPositionCaller', () => { 6 | it('call success', async () => { 7 | const expected = stubTransactionResposeFactory({}) 8 | const lockupContract = { 9 | withdrawByPosition: jest 10 | .fn() 11 | .mockImplementation(() => Promise.resolve(expected)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createWithdrawByPositionCaller(lockupContract as any) 16 | 17 | const result = await caller('32', '100') 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | const lockupContract = { 25 | withdrawByPosition: jest 26 | .fn() 27 | .mockImplementation(async () => Promise.reject(error)), 28 | } 29 | 30 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 31 | const caller = createWithdrawByPositionCaller(lockupContract as any) 32 | 33 | const result = await caller('32', '100').catch((err) => err) 34 | 35 | expect(result).toEqual(error) 36 | }) 37 | }) 38 | }) 39 | -------------------------------------------------------------------------------- /lib/ethereum/lockup/withdrawByPosition.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { 4 | execute, 5 | FallbackableOverrides, 6 | MutationOption, 7 | } from '../../common/utils/execute' 8 | import type { TransactionResponse } from 'ethers' 9 | 10 | export type CreateWithdrawByPositionCaller = ( 11 | contract: ethers.Contract, 12 | ) => ( 13 | positionTokenId: string, 14 | amount: string, 15 | overrides?: FallbackableOverrides, 16 | ) => Promise 17 | 18 | export const createWithdrawByPositionCaller: CreateWithdrawByPositionCaller = 19 | (contract: ethers.Contract) => 20 | async ( 21 | positionTokenId: string, 22 | amount: string, 23 | overrides?: FallbackableOverrides, 24 | ) => 25 | execute({ 26 | contract, 27 | method: 'withdrawByPosition', 28 | mutation: true, 29 | args: [positionTokenId, amount], 30 | overrides, 31 | }) 32 | -------------------------------------------------------------------------------- /lib/ethereum/market-behavior/getId.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetIdCaller } from './getId' 2 | 3 | describe('getId.spec.ts', () => { 4 | describe('createGetIdCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x0000.........' 7 | 8 | const contract = { 9 | getId: jest.fn().mockImplementation(async () => Promise.resolve(value)), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createGetIdCaller(contract as any) 16 | 17 | const result = await caller('metrics') 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | getId: jest.fn().mockImplementation(async () => Promise.reject(error)), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createGetIdCaller(contract as any) 31 | 32 | const result = await caller('metrics').catch((err) => err) 33 | 34 | expect(result).toEqual(error) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /lib/ethereum/market-behavior/getId.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetIdCaller = ( 5 | contract: ethers.Contract, 6 | ) => (metricsAddress: string) => Promise 7 | 8 | export const createGetIdCaller: CreateGetIdCaller = 9 | (contract: ethers.Contract) => (metricsAddress: string) => 10 | execute({ 11 | contract, 12 | method: 'getId', 13 | args: [metricsAddress], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/ethereum/market-behavior/getMetrics.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetMetricsCaller } from './getMetrics' 2 | 3 | describe('getMetrics.spec.ts', () => { 4 | describe('createGetMetricsCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x12345..........' 7 | 8 | const contract = { 9 | getMetrics: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createGetMetricsCaller(contract as any) 18 | 19 | const result = await caller('hogehoge/hugahuga') 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | getMetrics: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createGetMetricsCaller(contract as any) 35 | 36 | const result = await caller('hogehoge/hugahuga').catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/market-behavior/getMetrics.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetMetricsCaller = ( 5 | contract: ethers.Contract, 6 | ) => (id: string) => Promise 7 | 8 | export const createGetMetricsCaller: CreateGetMetricsCaller = 9 | (contract: ethers.Contract) => (id: string) => 10 | execute({ 11 | contract, 12 | method: 'getMetrics', 13 | args: [id], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/ethereum/market-behavior/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { marketBehaviorAbi } from './abi' 3 | import { createGetIdCaller } from './getId' 4 | import { createGetMetricsCaller } from './getMetrics' 5 | 6 | export type CreateMarketBehaviorContract = { 7 | readonly getId: (metricsAddress: string) => Promise 8 | readonly getMetrics: (id: string) => Promise 9 | readonly contract: () => ethers.Contract 10 | } 11 | 12 | // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types 13 | export const createMarketBehaviorContract = 14 | (provider: ContractRunner) => 15 | (address: string): CreateMarketBehaviorContract => { 16 | const contract = new ethers.Contract( 17 | address, 18 | [...marketBehaviorAbi], 19 | provider, 20 | ) 21 | 22 | return { 23 | getId: createGetIdCaller(contract), 24 | getMetrics: createGetMetricsCaller(contract), 25 | contract: () => contract, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/ethereum/market-factory/create.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateCreateCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | marketBehaviorAddress: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createCreateCaller: CreateCreateCaller = 17 | (contract: ethers.Contract) => 18 | async (marketBehaviorAddress: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'create', 22 | mutation: true, 23 | args: [marketBehaviorAddress], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/market-factory/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { createMarketFactoryContract, MarketFactoryContract } from '.' 3 | import { marketFactoryAbi } from './abi' 4 | import { createCreateCaller } from './create' 5 | 6 | jest.mock('./create') 7 | jest.mock('ethers') 8 | 9 | describe('market-factory/index.ts', () => { 10 | ;(createCreateCaller as jest.Mock).mockImplementation(() => 123) 11 | ;(ethers.Contract as jest.Mock).mockImplementation(() => 123) 12 | describe('createMarketFactoryContract', () => { 13 | it('check return object', () => { 14 | const host = 'localhost' 15 | const address = '0x0000000000000000000000000000000000000000' 16 | const provider = new ethers.JsonRpcProvider(host) 17 | 18 | const expected: (address: string) => MarketFactoryContract = ( 19 | address: string, 20 | ) => { 21 | const contract = new ethers.Contract( 22 | address, 23 | [...marketFactoryAbi], 24 | provider, 25 | ) 26 | return { 27 | create: createCreateCaller(contract), 28 | contract: () => contract, 29 | } 30 | } 31 | 32 | const result = createMarketFactoryContract(provider) 33 | 34 | expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) 35 | expect(JSON.stringify(result(address))).toEqual( 36 | JSON.stringify(expected(address)), 37 | ) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /lib/ethereum/market-factory/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { marketFactoryAbi } from './abi' 3 | import { createCreateCaller } from './create' 4 | import { FallbackableOverrides } from '../../common/utils/execute' 5 | import type { TransactionResponse } from 'ethers' 6 | 7 | export type MarketFactoryContract = { 8 | readonly create: ( 9 | marketBehaviorAddress: string, 10 | overrides?: FallbackableOverrides, 11 | ) => Promise 12 | readonly contract: () => ethers.Contract 13 | } 14 | 15 | export const createMarketFactoryContract = 16 | (provider: ContractRunner) => 17 | (address: string): MarketFactoryContract => { 18 | const contract = new ethers.Contract( 19 | address, 20 | [...marketFactoryAbi], 21 | provider, 22 | ) 23 | return { 24 | create: createCreateCaller(contract), 25 | contract: () => contract, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/ethereum/market/behavior.spec.ts: -------------------------------------------------------------------------------- 1 | import { createBehaviorCaller } from './behavior' 2 | 3 | describe('behavior.spec.ts', () => { 4 | describe('createBehaviorCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x0000.........' 7 | 8 | const contract = { 9 | behavior: () => Promise.resolve(value), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createBehaviorCaller(contract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const err = new Error('error') 24 | 25 | const contract = { 26 | behavior: () => Promise.reject(err), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createBehaviorCaller(contract as any) 31 | 32 | await expect(caller()).rejects.toThrowError(err) 33 | }) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /lib/ethereum/market/behavior.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | import { ethers } from 'ethers' 5 | 6 | export type CreateBehaviorCaller = ( 7 | contract: ethers.Contract, 8 | ) => () => Promise 9 | 10 | export const createBehaviorCaller: CreateBehaviorCaller = ( 11 | contract: ethers.Contract, 12 | ) => 13 | always( 14 | execute({ 15 | contract, 16 | method: 'behavior', 17 | mutation: false, 18 | }), 19 | ) 20 | -------------------------------------------------------------------------------- /lib/ethereum/market/schema.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateSchemaCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | type ParsedValue = { 9 | readonly v: string 10 | readonly s: boolean 11 | } 12 | 13 | export const createSchemaCaller: CreateSchemaCaller = ( 14 | contract: ethers.Contract, 15 | ): (() => Promise) => 16 | always( 17 | execute({ contract, method: 'schema', mutation: false }).then( 18 | (result) => 19 | JSON.parse( 20 | result 21 | .split(`'`) 22 | .map((v) => ({ v, s: /[[\],:]/.test(v) })) 23 | .reduce((a, c) => `${a}${c.s ? c.v : `"${c.v}"`}`, ''), 24 | ) as readonly string[], 25 | ), 26 | ) 27 | -------------------------------------------------------------------------------- /lib/ethereum/market/vote.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import type { TransactionResponse } from 'ethers' 3 | import { 4 | execute, 5 | FallbackableOverrides, 6 | MutationOption, 7 | } from '../../common/utils/execute' 8 | 9 | export type CreateVoteCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | propertyAddress: string, 13 | agree: boolean, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createVoteCaller: CreateVoteCaller = 18 | ( 19 | contract: ethers.Contract, 20 | ): (( 21 | propertyAddress: string, 22 | agree: boolean, 23 | overrides?: FallbackableOverrides, 24 | ) => Promise) => 25 | async ( 26 | propertyAddress: string, 27 | agree: boolean, 28 | overrides?: FallbackableOverrides, 29 | ): Promise => 30 | execute({ 31 | contract, 32 | method: 'vote', 33 | args: [propertyAddress, agree], 34 | mutation: true, 35 | overrides, 36 | }) 37 | -------------------------------------------------------------------------------- /lib/ethereum/metrics-group/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { metricsGroupAbi } from './abi' 3 | import { createTotalAuthenticatedPropertiesCaller } from './totalAuthenticatedProperties' 4 | import { createTotalIssuedMetrics } from './totalIssuedMetrics' 5 | 6 | export type CreateMetricsGroupContract = { 7 | readonly totalAuthenticatedProperties: () => Promise 8 | readonly totalIssuedMetrics: () => Promise 9 | readonly contract: () => ethers.Contract 10 | } 11 | 12 | export const createMetricsGroupContract = 13 | (provider: ContractRunner) => 14 | (address: string): CreateMetricsGroupContract => { 15 | const contract = new ethers.Contract( 16 | address, 17 | [...metricsGroupAbi], 18 | provider, 19 | ) 20 | 21 | return { 22 | totalAuthenticatedProperties: 23 | createTotalAuthenticatedPropertiesCaller(contract), 24 | totalIssuedMetrics: createTotalIssuedMetrics(contract), 25 | contract: () => contract, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/ethereum/metrics-group/totalAuthenticatedProperties.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTotalAuthenticatedPropertiesCaller } from './totalAuthenticatedProperties' 2 | 3 | describe('totalAuthenticatedProperties.spec.ts', () => { 4 | describe('createTotalAuthenticatedPropertiesCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const metricsGroupContract = { 9 | totalAuthenticatedProperties: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTotalAuthenticatedPropertiesCaller( 18 | metricsGroupContract as any, 19 | ) 20 | 21 | const result = await caller() 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const error = 'error' 28 | 29 | const metricsGroupContract = { 30 | totalAuthenticatedProperties: jest 31 | .fn() 32 | .mockImplementation(async () => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createTotalAuthenticatedPropertiesCaller( 37 | metricsGroupContract as any, 38 | ) 39 | 40 | const result = await caller().catch((err) => err) 41 | 42 | expect(result).toEqual(error) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /lib/ethereum/metrics-group/totalAuthenticatedProperties.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateTotalAuthenticatedPropertiesCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createTotalAuthenticatedPropertiesCaller: CreateTotalAuthenticatedPropertiesCaller = 10 | (contract: ethers.Contract) => 11 | always( 12 | execute({ 13 | contract, 14 | method: 'totalAuthenticatedProperties', 15 | mutation: false, 16 | }), 17 | ) 18 | -------------------------------------------------------------------------------- /lib/ethereum/metrics-group/totalIssuedMetrics.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTotalIssuedMetrics } from './totalIssuedMetrics' 2 | 3 | describe('totalIssuedMetrics.spec.ts', () => { 4 | describe('createTotalIssuedMetrics', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const metricsGroupContract = { 9 | totalIssuedMetrics: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTotalIssuedMetrics(metricsGroupContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const metricsGroupContract = { 28 | totalIssuedMetrics: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createTotalIssuedMetrics(metricsGroupContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/metrics-group/totalIssuedMetrics.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateTotalIssuedMetrics = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createTotalIssuedMetrics: CreateTotalIssuedMetrics = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'totalIssuedMetrics', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/abi.ts: -------------------------------------------------------------------------------- 1 | export const metricsAbi = [ 2 | { 3 | inputs: [ 4 | { 5 | internalType: 'address', 6 | name: '_market', 7 | type: 'address', 8 | }, 9 | { 10 | internalType: 'address', 11 | name: '_property', 12 | type: 'address', 13 | }, 14 | ], 15 | payable: false, 16 | stateMutability: 'nonpayable', 17 | type: 'constructor', 18 | }, 19 | { 20 | constant: true, 21 | inputs: [], 22 | name: 'market', 23 | outputs: [ 24 | { 25 | internalType: 'address', 26 | name: '', 27 | type: 'address', 28 | }, 29 | ], 30 | payable: false, 31 | stateMutability: 'view', 32 | type: 'function', 33 | }, 34 | { 35 | constant: true, 36 | inputs: [], 37 | name: 'property', 38 | outputs: [ 39 | { 40 | internalType: 'address', 41 | name: '', 42 | type: 'address', 43 | }, 44 | ], 45 | payable: false, 46 | stateMutability: 'view', 47 | type: 'function', 48 | }, 49 | ] 50 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { metricsAbi } from './abi' 3 | import { createPropertyCaller } from './property' 4 | import { createMarketCaller } from './market' 5 | 6 | export type CreateMetricsContract = { 7 | readonly property: () => Promise 8 | readonly market: () => Promise 9 | readonly contract: () => ethers.Contract 10 | } 11 | 12 | // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types 13 | export const createMetricsContract = 14 | (provider: ContractRunner) => 15 | (address: string): CreateMetricsContract => { 16 | const contract = new ethers.Contract(address, [...metricsAbi], provider) 17 | 18 | return { 19 | property: createPropertyCaller(contract), 20 | market: createMarketCaller(contract), 21 | contract: () => contract, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/market.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMarketCaller } from './market' 2 | 3 | describe('market.spec.ts', () => { 4 | describe('createMarketCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x0000.........' 7 | 8 | const contract = { 9 | market: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMarketCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | market: jest.fn().mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createMarketCaller(contract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/market.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMarketCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMarketCaller: CreateMarketCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'market', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/property.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPropertyCaller } from './property' 2 | 3 | describe('property.spec.ts', () => { 4 | describe('createPropertyCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x0000.........' 7 | 8 | const contract = { 9 | property: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPropertyCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | property: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPropertyCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/metrics/property.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePropertyCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPropertyCaller: CreatePropertyCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'property', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/policy-factory/create.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateCreateCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | newPolicyAddress: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createCreateCaller: CreateCreateCaller = 17 | (contract: ethers.Contract) => 18 | async (newPolicyAddress: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'create', 22 | mutation: true, 23 | args: [newPolicyAddress], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/policy-factory/forceAttach.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateForceAttachCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | policy: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createForceAttachCaller: CreateForceAttachCaller = 17 | (contract: ethers.Contract) => 18 | async (policy: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'forceAttach', 22 | mutation: true, 23 | args: [policy], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/policy-factory/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { policyFactoryAbi } from './abi' 3 | import { createCreateCaller } from './create' 4 | import { createForceAttachCaller } from './forceAttach' 5 | import { FallbackableOverrides } from '../../common/utils/execute' 6 | import type { TransactionResponse } from 'ethers' 7 | 8 | export type PolicyFactoryContract = { 9 | readonly create: ( 10 | newPolicyAddress: string, 11 | overrides?: FallbackableOverrides, 12 | ) => Promise 13 | readonly forceAttach: ( 14 | policy: string, 15 | overrides?: FallbackableOverrides, 16 | ) => Promise 17 | readonly contract: () => ethers.Contract 18 | } 19 | 20 | export type CreatePolicyFactoryContract = ( 21 | provider: ContractRunner, 22 | ) => (address: string) => PolicyFactoryContract 23 | 24 | export const createPolicyFactoryContract: CreatePolicyFactoryContract = 25 | (provider: ContractRunner) => (address: string) => { 26 | const contract = new ethers.Contract( 27 | address, 28 | [...policyFactoryAbi], 29 | provider, 30 | ) 31 | 32 | return { 33 | create: createCreateCaller(contract), 34 | forceAttach: createForceAttachCaller(contract), 35 | contract: () => contract, 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/ethereum/policy-group/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { policyGroupAbi } from './abi' 3 | import { createIsGroupCaller } from './isGroup' 4 | 5 | export type PolicyGroupContract = { 6 | readonly isGroup: (policyAddress: string) => Promise 7 | readonly isDuringVotingPeriod: (policyAddress: string) => Promise 8 | readonly contract: () => ethers.Contract 9 | } 10 | 11 | export type CreatePolicyGroupContract = ( 12 | provider: ContractRunner, 13 | ) => (address: string) => PolicyGroupContract 14 | 15 | export const createPolicyGroupContract: CreatePolicyGroupContract = 16 | (provider: ContractRunner) => (address: string) => { 17 | const contract = new ethers.Contract(address, [...policyGroupAbi], provider) 18 | return { 19 | isGroup: createIsGroupCaller(contract), 20 | isDuringVotingPeriod: createIsGroupCaller(contract), 21 | contract: () => contract, 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lib/ethereum/policy-group/isDuringVotingPeriod.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | MutationOption, 5 | QueryOption, 6 | } from '../../common/utils/execute' 7 | import { T } from 'ramda' 8 | 9 | export type CreateIsDuringVotingPeriodCaller = ( 10 | contract: ethers.Contract, 11 | ) => (policyAddress: string) => Promise 12 | 13 | export const createIsDuringVotingPeriodCaller: CreateIsDuringVotingPeriodCaller = 14 | 15 | (contract: ethers.Contract) => 16 | async (policyAddress: string): Promise => 17 | execute({ 18 | contract, 19 | method: 'isDuringVotingPeriod', 20 | args: [policyAddress], 21 | mutation: false, 22 | }).then(T) 23 | -------------------------------------------------------------------------------- /lib/ethereum/policy-group/isGroup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createIsGroupCaller } from './isGroup' 2 | 3 | describe('isGroup.spec.ts', () => { 4 | describe('createIsGroupCaller', () => { 5 | it('call success', async () => { 6 | const value = true 7 | 8 | const policyGroupContract = { 9 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 10 | isGroup: jest.fn().mockImplementation(async (policy: string) => value), 11 | } 12 | 13 | const expected = value 14 | 15 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 16 | const caller = createIsGroupCaller(policyGroupContract as any) 17 | 18 | const result = await caller('0x0') 19 | 20 | expect(result).toEqual(expected) 21 | }) 22 | 23 | it('call failure', async () => { 24 | const error = 'error' 25 | 26 | const policyGroupContract = { 27 | isGroup: jest 28 | .fn() 29 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 30 | .mockImplementation(async (policy: string) => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createIsGroupCaller(policyGroupContract as any) 35 | 36 | const result = await caller('0x0').catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/policy-group/isGroup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { T } from 'ramda' 4 | 5 | export type CreateIsGroupCaller = ( 6 | contract: ethers.Contract, 7 | ) => (policyAddress: string) => Promise 8 | 9 | export const createIsGroupCaller: CreateIsGroupCaller = 10 | (contract: ethers.Contract) => 11 | async (policyAddress: string): Promise => 12 | execute({ 13 | contract, 14 | method: 'isGroup', 15 | args: [policyAddress], 16 | mutation: false, 17 | }).then(T) 18 | -------------------------------------------------------------------------------- /lib/ethereum/policy/authenticationFee.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateAuthenticationFeeCaller = ( 5 | contract: ethers.Contract, 6 | ) => (assets: string, propertyAssets: string) => Promise 7 | 8 | export const createAuthenticationFeeCaller: CreateAuthenticationFeeCaller = 9 | (contract: ethers.Contract) => 10 | async (assets: string, propertyAssets: string): Promise => 11 | execute({ 12 | contract, 13 | method: 'authenticationFee', 14 | args: [assets, propertyAssets], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/policy/capSetter.spec.ts: -------------------------------------------------------------------------------- 1 | import { createCapSetterCaller } from './capSetter' 2 | 3 | describe('capSetter.spec.ts', () => { 4 | describe('createCapSetterCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | capSetter: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createCapSetterCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | capSetter: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createCapSetterCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/policy/capSetter.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateCapSetterCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createCapSetterCaller: CreateCapSetterCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'capSetter', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/policy/holdersShare.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateHoldersShareCaller = ( 5 | contract: ethers.Contract, 6 | ) => (amount: string, lockups: string) => Promise 7 | 8 | export const createHoldersShareCaller: CreateHoldersShareCaller = 9 | (contract: ethers.Contract) => 10 | async (amount: string, lockups: string): Promise => 11 | execute({ 12 | contract, 13 | method: 'holdersShare', 14 | args: [amount, lockups], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/policy/marketVotingBlocks.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMarketVotingBlocksCaller } from './marketVotingBlocks' 2 | 3 | describe('marketVotingBlocks.spec.ts', () => { 4 | describe('createMarketVotingCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | marketVotingBlocks: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMarketVotingBlocksCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | marketVotingBlocks: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMarketVotingBlocksCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/policy/marketVotingBlocks.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMarketVotingBlocksCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMarketVotingBlocksCaller: CreateMarketVotingBlocksCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'marketVotingBlocks', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/policy/policyVotingBlocks.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicyVotingBlocksCaller } from './policyVotingBlocks' 2 | 3 | describe('policyVotingBlocks.spec.ts', () => { 4 | describe('createPolicyVotingBlocksCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | policyVotingBlocks: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicyVotingBlocksCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | policyVotingBlocks: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPolicyVotingBlocksCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/policy/policyVotingBlocks.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicyVotingBlocksCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicyVotingBlocksCaller: CreatePolicyVotingBlocksCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'policyVotingBlocks', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/policy/rewards.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateRewardsCaller = ( 5 | contract: ethers.Contract, 6 | ) => (lockups: string, assets: string) => Promise 7 | 8 | export const createRewardsCaller: CreateRewardsCaller = 9 | (contract: ethers.Contract) => 10 | async (lockups: string, assets: string): Promise => 11 | execute({ 12 | contract, 13 | method: 'rewards', 14 | args: [lockups, assets], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/policy/shareOfTreasury.spec.ts: -------------------------------------------------------------------------------- 1 | import { createShareOfTreasuryCaller } from './shareOfTreasury' 2 | 3 | describe('shareOfTreasury.spec.ts', () => { 4 | describe('createShareOfTreasuryCaller', () => { 5 | it('call success', async () => { 6 | const value = '12345' 7 | 8 | const policyContract = { 9 | shareOfTreasury: jest 10 | .fn() 11 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 12 | .mockImplementation(async (supply: string) => value), 13 | } 14 | 15 | const expected = value 16 | 17 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 18 | const caller = createShareOfTreasuryCaller(policyContract as any) 19 | 20 | const result = await caller('111111111111') 21 | 22 | expect(result).toEqual(expected) 23 | }) 24 | 25 | it('call failure', async () => { 26 | const error = 'error' 27 | 28 | const policyContract = { 29 | shareOfTreasury: jest 30 | .fn() 31 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 32 | .mockImplementation(async (supply: string) => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createShareOfTreasuryCaller(policyContract as any) 37 | 38 | const result = await caller('111111111111').catch((err) => err) 39 | 40 | expect(result).toEqual(error) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /lib/ethereum/policy/shareOfTreasury.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateShareOfTreasuryCaller = ( 5 | contract: ethers.Contract, 6 | ) => (supply: string) => Promise 7 | 8 | export const createShareOfTreasuryCaller: CreateShareOfTreasuryCaller = 9 | (contract: ethers.Contract) => 10 | async (supply: string): Promise => 11 | execute({ 12 | contract, 13 | method: 'shareOfTreasury', 14 | args: [supply], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/policy/treasury.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTreasuryCaller } from './treasury' 2 | 3 | describe('treasury.spec.ts', () => { 4 | describe('createTreasuryCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | treasury: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTreasuryCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | treasury: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createTreasuryCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/policy/treasury.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateTreasuryCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createTreasuryCaller: CreateTreasuryCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'treasury', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/property-factory/create.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | /* eslint-disable functional/no-expression-statement */ 3 | import { ethers } from 'ethers' 4 | import { 5 | execute, 6 | FallbackableOverrides, 7 | MutationOption, 8 | } from '../../common/utils/execute' 9 | 10 | export type CreateCreatePropertyCaller = ( 11 | contract: ethers.Contract, 12 | ) => ( 13 | name: string, 14 | symbol: string, 15 | author: string, 16 | overrides?: FallbackableOverrides, 17 | ) => Promise 18 | 19 | export const createCreatePropertyCaller: CreateCreatePropertyCaller = 20 | (contract) => 21 | async ( 22 | name: string, 23 | symbol: string, 24 | author: string, 25 | overrides?: FallbackableOverrides, 26 | ): Promise => { 27 | await execute({ 28 | contract, 29 | method: 'create', 30 | args: [name, symbol, author], 31 | mutation: true, 32 | overrides, 33 | }) 34 | 35 | return new Promise((resolve) => { 36 | const subscribedContract = contract.on( 37 | 'Create', 38 | async (_: string, propertyAddress: string) => { 39 | ;(await subscribedContract).removeAllListeners() 40 | resolve(propertyAddress) 41 | }, 42 | ) 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /lib/ethereum/property/author.spec.ts: -------------------------------------------------------------------------------- 1 | import { createAuthorCaller } from './author' 2 | 3 | describe('author.spec.ts', () => { 4 | describe('createAuthorCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const propertyContract = { 9 | author: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createAuthorCaller(propertyContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const propertyContract = { 28 | author: jest.fn().mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createAuthorCaller(propertyContract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/property/author.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateAuthorCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createAuthorCaller: CreateAuthorCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'author', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/property/changeAuthor.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateChangeAuthorCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | nextAuther: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createChangeAuthorCaller: CreateChangeAuthorCaller = 17 | (contract: ethers.Contract) => 18 | async (nextAuther: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'changeAuthor', 22 | mutation: true, 23 | args: [nextAuther], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/property/changeName.spec.ts: -------------------------------------------------------------------------------- 1 | import { createChangeNameCaller } from './changeName' 2 | import { stubTransactionResposeFactory } from '../../common/utils/for-test' 3 | 4 | describe('changeName.spec.ts', () => { 5 | describe('createChangeNameCaller', () => { 6 | it('call success', async () => { 7 | const expected = stubTransactionResposeFactory({}) 8 | const nextName = 'next' 9 | 10 | const contract = { 11 | changeName: jest 12 | .fn() 13 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 14 | .mockImplementation(async (nextName: string) => expected), 15 | } 16 | 17 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 18 | const caller = createChangeNameCaller(contract as any) 19 | 20 | const result = await caller(nextName) 21 | 22 | expect(result).toEqual(expected) 23 | }) 24 | 25 | it('call failure', async () => { 26 | const nextName = 'next' 27 | const error = 'error' 28 | 29 | const contract = { 30 | changeName: jest 31 | .fn() 32 | 33 | .mockImplementation(async () => Promise.reject(error)), 34 | } 35 | 36 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 37 | const caller = createChangeNameCaller(contract as any) 38 | 39 | const result = await caller(nextName).catch((err) => err) 40 | 41 | expect(result).toEqual(error) 42 | }) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /lib/ethereum/property/changeName.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateChangeNameCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | nextAuther: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createChangeNameCaller: CreateChangeNameCaller = 17 | (contract: ethers.Contract) => 18 | async (nextName: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'changeName', 22 | mutation: true, 23 | args: [nextName], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/property/changeSymbol.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateChangeSymbolCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | nextAuther: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createChangeSymbolCaller: CreateChangeSymbolCaller = 17 | (contract: ethers.Contract) => 18 | async (nextSymbol: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'changeSymbol', 22 | mutation: true, 23 | args: [nextSymbol], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/registry/allocator.spec.ts: -------------------------------------------------------------------------------- 1 | import { createAllocatorCaller } from './allocator' 2 | 3 | describe('createAllocatorCaller.spec.ts', () => { 4 | describe('createAllocatorCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | allocator: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createAllocatorCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | allocator: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createAllocatorCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/allocator.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateAllocatorCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createAllocatorCaller: CreateAllocatorCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'allocator', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/allocatorStorage.spec.ts: -------------------------------------------------------------------------------- 1 | import { createAllocatorStorageCaller } from './allocatorStorage' 2 | describe('createAllocatorStorageCaller.spec.ts', () => { 3 | describe('createAllocatorStorageCaller', () => { 4 | it('call success', async () => { 5 | const value = 'value' 6 | 7 | const addressConfigContract = { 8 | allocatorStorage: jest 9 | .fn() 10 | .mockImplementation(async () => Promise.resolve(value)), 11 | } 12 | 13 | const expected = value 14 | 15 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 16 | const caller = createAllocatorStorageCaller(addressConfigContract as any) 17 | 18 | const result = await caller() 19 | 20 | expect(result).toEqual(expected) 21 | }) 22 | 23 | it('call failure', async () => { 24 | const error = 'error' 25 | 26 | const addressConfigContract = { 27 | allocatorStorage: jest 28 | .fn() 29 | .mockImplementation(async () => Promise.reject(error)), 30 | } 31 | 32 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 33 | const caller = createAllocatorStorageCaller(addressConfigContract as any) 34 | 35 | const result = await caller().catch((err) => err) 36 | 37 | expect(result).toEqual(error) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /lib/ethereum/registry/allocatorStorage.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateAllocatorStorageCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createAllocatorStorageCaller: CreateAllocatorStorageCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'allocatorStorage', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/lockup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createLockupCaller } from './lockup' 2 | 3 | describe('createLockupCaller.spec.ts', () => { 4 | describe('createLockupCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | lockup: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createLockupCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | lockup: jest.fn().mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createLockupCaller(addressConfigContract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/registry/lockup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateLockupCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createLockupCaller: CreateLockupCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'lockup', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/lockupStorage.spec.ts: -------------------------------------------------------------------------------- 1 | import { createLockupStorageCaller } from './lockupStorage' 2 | 3 | describe('createLockupStorageCaller.spec.ts', () => { 4 | describe('createLockupStorageCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | lockupStorage: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createLockupStorageCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | lockupStorage: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createLockupStorageCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/lockupStorage.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateLockupStorageCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createLockupStorageCaller: CreateLockupStorageCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'lockupStorage', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/marketFactory.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMarketFactoryCaller } from './marketFactory' 2 | 3 | describe('createMarketFactoryCaller.spec.ts', () => { 4 | describe('createMarketFactoryCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | marketFactory: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMarketFactoryCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | marketFactory: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMarketFactoryCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/marketFactory.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMarketFactoryCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMarketFactoryCaller: CreateMarketFactoryCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'marketFactory', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/marketGroup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMarketGroupCaller } from './marketGroup' 2 | 3 | describe('createMarketGroupCaller.spec.ts', () => { 4 | describe('createMarketGroupCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | marketGroup: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMarketGroupCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | marketGroup: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMarketGroupCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/marketGroup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMarketGroupCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMarketGroupCaller: CreateMarketGroupCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'marketGroup', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/metricsFactory.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMetricsFactoryCaller } from './metricsFactory' 2 | 3 | describe('createMetricsFactoryCaller.spec.ts', () => { 4 | describe('createMetricsFactoryCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | metricsFactory: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMetricsFactoryCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | metricsFactory: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMetricsFactoryCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/metricsFactory.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMetricsFactoryCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMetricsFactoryCaller: CreateMetricsFactoryCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'metricsFactory', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/metricsGroup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMetricsGroupCaller } from './metricsGroup' 2 | 3 | describe('createMetricsGroupCaller.spec.ts', () => { 4 | describe('createMetricsGroupCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | metricsGroup: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMetricsGroupCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | metricsGroup: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMetricsGroupCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/metricsGroup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMetricsGroupCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMetricsGroupCaller: CreateMetricsGroupCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'metricsGroup', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policy.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicyCaller } from './policy' 2 | 3 | describe('createPolicyCaller.spec.ts', () => { 4 | describe('createPolicyCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | policy: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicyCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | policy: jest.fn().mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createPolicyCaller(addressConfigContract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policy.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicyCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicyCaller: CreatePolicyCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'policy', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policyFactory.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicyFactoryCaller } from './policyFactory' 2 | 3 | describe('createPolicyFactoryCaller.spec.ts', () => { 4 | describe('createPolicyFactoryCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | policyFactory: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicyFactoryCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | policyFactory: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPolicyFactoryCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policyFactory.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicyFactoryCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicyFactoryCaller: CreatePolicyFactoryCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'policyFactory', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policyGroup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicyGroupCaller } from './policyGroup' 2 | 3 | describe('createPolicyGroupCaller.spec.ts', () => { 4 | describe('createPolicyGroupCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | policyGroup: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicyGroupCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | policyGroup: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPolicyGroupCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policyGroup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicyGroupCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicyGroupCaller: CreatePolicyGroupCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'policyGroup', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policySet.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicySetCaller } from './policySet' 2 | 3 | describe('createPolicySetCaller.spec.ts', () => { 4 | describe('createPolicySetCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | policySet: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicySetCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | policySet: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPolicySetCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/policySet.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicySetCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicySetCaller: CreatePolicySetCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'policySet', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/propertyFactory.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPropertyFactoryCaller } from './propertyFactory' 2 | 3 | describe('createPropertyFactoryCaller.spec.ts', () => { 4 | describe('createPropertyFactoryCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | propertyFactory: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPropertyFactoryCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | propertyFactory: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPropertyFactoryCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/propertyFactory.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePropertyFactoryCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPropertyFactoryCaller: CreatePropertyFactoryCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'propertyFactory', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/propertyGroup.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPropertyGroupCaller } from './propertyGroup' 2 | 3 | describe('createPropertyGroupCaller.spec.ts', () => { 4 | describe('createPropertyGroupCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | propertyGroup: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPropertyGroupCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | propertyGroup: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPropertyGroupCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/propertyGroup.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePropertyGroupCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPropertyGroupCaller: CreatePropertyGroupCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'propertyGroup', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/token.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTokenCaller } from './token' 2 | 3 | describe('createTokenCaller.spec.ts', () => { 4 | describe('createTokenCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | token: jest.fn().mockImplementation(async () => Promise.resolve(value)), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createTokenCaller(addressConfigContract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const addressConfigContract = { 26 | token: jest.fn().mockImplementation(async () => Promise.reject(error)), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createTokenCaller(addressConfigContract as any) 31 | 32 | const result = await caller().catch((err) => err) 33 | 34 | expect(result).toEqual(error) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /lib/ethereum/registry/token.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateTokenCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createTokenCaller: CreateTokenCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'token', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/withdraw.spec.ts: -------------------------------------------------------------------------------- 1 | import { createWithdrawCaller } from './withdraw' 2 | 3 | describe('createWithdrawCaller.spec.ts', () => { 4 | describe('createWithdrawCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | withdraw: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createWithdrawCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | withdraw: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createWithdrawCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateWithdrawCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createWithdrawCaller: CreateWithdrawCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'withdraw', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/registry/withdrawStorage.spec.ts: -------------------------------------------------------------------------------- 1 | import { createWithdrawStorageCaller } from './withdrawStorage' 2 | 3 | describe('createWithdrawStorageCaller.spec.ts', () => { 4 | describe('createWithdrawStorageCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const addressConfigContract = { 9 | withdrawStorage: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createWithdrawStorageCaller(addressConfigContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const addressConfigContract = { 28 | withdrawStorage: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createWithdrawStorageCaller(addressConfigContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/registry/withdrawStorage.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateWithdrawStorageCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createWithdrawStorageCaller: CreateWithdrawStorageCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'withdrawStorage', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/descriptorOf.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateDescriptorOfCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string) => Promise 8 | 9 | export const createDescriptorOfCaller: CreateDescriptorOfCaller = 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string): Promise => { 12 | const res = execute({ 13 | contract, 14 | method: 'descriptorOf', 15 | args: [propertyAddress], 16 | mutation: false, 17 | }) 18 | return res 19 | } 20 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/descriptorOfPropertyByPayload.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateDescriptorOfPropertyByPayloadCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string, payload: string | Uint8Array) => Promise 8 | 9 | export const createDescriptorOfPropertyByPayloadCaller: CreateDescriptorOfPropertyByPayloadCaller = 10 | 11 | (contract: ethers.Contract) => 12 | async ( 13 | propertyAddress: string, 14 | payload: string | Uint8Array, 15 | ): Promise => { 16 | const res = execute({ 17 | contract, 18 | method: 'descriptorOfPropertyByPayload', 19 | args: [propertyAddress, payload], 20 | mutation: false, 21 | }) 22 | return res 23 | } 24 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/freezeTokenURI.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateFreezeTokenURICaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | tokenId: number, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createFreezeTokenURICaller: CreateFreezeTokenURICaller = 17 | (contract: ethers.Contract) => 18 | async (tokenId: number, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'freezeTokenURI', 22 | mutation: true, 23 | args: [String(tokenId)], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/isFreezed.spec.ts: -------------------------------------------------------------------------------- 1 | import { createIsFreezedCaller } from './isFreezed' 2 | 3 | describe('isFreezed.spec.ts', () => { 4 | describe('createIsFreezedCaller', () => { 5 | it('call success', async () => { 6 | const value = true 7 | const tokenId = 1 8 | 9 | const devContract = { 10 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 11 | isFreezed: jest 12 | .fn() 13 | .mockImplementation(async (tokenId: string) => value), 14 | } 15 | 16 | const expected = value 17 | 18 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 19 | const caller = createIsFreezedCaller(devContract as any) 20 | 21 | const result = await caller(tokenId) 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const tokenId = 1 28 | const error = 'error' 29 | 30 | const devContract = { 31 | isFreezed: jest 32 | .fn() 33 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 34 | .mockImplementation(async (tokenId: string) => Promise.reject(error)), 35 | } 36 | 37 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 38 | const caller = createIsFreezedCaller(devContract as any) 39 | 40 | const result = await caller(tokenId).catch((err) => err) 41 | 42 | expect(result).toEqual(error) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/isFreezed.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { T } from 'ramda' 5 | 6 | export type CreateIsFreezedCaller = ( 7 | contract: ethers.Contract, 8 | ) => (tokenId: number) => Promise 9 | 10 | export const createIsFreezedCaller: CreateIsFreezedCaller = 11 | (contract: ethers.Contract) => 12 | async (tokenId: number): Promise => 13 | execute({ 14 | contract, 15 | method: 'isFreezed', 16 | args: [String(tokenId)], 17 | mutation: false, 18 | }).then(T) 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/ownerOf.spec.ts: -------------------------------------------------------------------------------- 1 | import { createOwnerOfCaller } from './ownerOf' 2 | 3 | describe('ownerOf.spec.ts', () => { 4 | describe('createOwnerOfCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x00' 7 | 8 | const contract = { 9 | ownerOf: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = '0x00' 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createOwnerOfCaller(contract as any) 18 | 19 | const result = await caller(1) 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | ownerOf: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createOwnerOfCaller(contract as any) 35 | 36 | const result = await caller(1).catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/ownerOf.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateOwnerOfCaller = ( 6 | contract: ethers.Contract, 7 | ) => (tokenId: number) => Promise 8 | 9 | export const createOwnerOfCaller: CreateOwnerOfCaller = 10 | (contract: ethers.Contract) => async (tokenId: number) => 11 | execute({ 12 | contract, 13 | method: 'ownerOf', 14 | args: [String(tokenId)], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/payloadOf.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPayloadOfCaller } from './payloadOf' 2 | 3 | describe('payloadOf.spec.ts', () => { 4 | describe('createPayloadOfCaller', () => { 5 | it('call success', async () => { 6 | const value = '0x74657374696e67' 7 | const tokenId = 1 8 | 9 | const devContract = { 10 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 11 | payloadOf: jest 12 | .fn() 13 | .mockImplementation(async (tokenId: string) => value), 14 | } 15 | 16 | const expected = value 17 | 18 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 19 | const caller = createPayloadOfCaller(devContract as any) 20 | 21 | const result = await caller(tokenId) 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const tokenId = 1 28 | const error = 'error' 29 | 30 | const devContract = { 31 | payloadOf: jest 32 | .fn() 33 | // eslint-disable-next-line @typescript-eslint/no-unused-vars 34 | .mockImplementation(async (tokenId: string) => Promise.reject(error)), 35 | } 36 | 37 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 38 | const caller = createPayloadOfCaller(devContract as any) 39 | 40 | const result = await caller(tokenId).catch((err) => err) 41 | 42 | expect(result).toEqual(error) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/payloadOf.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreatePayloadOfCaller = ( 6 | contract: ethers.Contract, 7 | ) => (tokenId: number) => Promise 8 | 9 | export const createPayloadOfCaller: CreatePayloadOfCaller = 10 | (contract: ethers.Contract) => 11 | async (tokenId: number): Promise => { 12 | const res = execute({ 13 | contract, 14 | method: 'payloadOf', 15 | args: [String(tokenId)], 16 | mutation: false, 17 | }) 18 | return res 19 | } 20 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/positions.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { arrayify } from '../../common/utils/arrayify' 5 | 6 | export type Positions = { 7 | readonly property: string 8 | readonly amount: string 9 | readonly price: string 10 | readonly cumulativeReward: string 11 | readonly pendingReward: string 12 | } 13 | 14 | export type CreatePositionsCaller = ( 15 | contract: ethers.Contract, 16 | ) => (tokenId: number) => Promise 17 | 18 | export const createPositionsCaller: CreatePositionsCaller = 19 | (contract: ethers.Contract) => async (tokenId: number) => { 20 | const res = await execute< 21 | QueryOption, 22 | { 23 | readonly property_: string 24 | readonly amount_: string 25 | readonly price_: string 26 | readonly cumulativeReward_: string 27 | readonly pendingReward_: string 28 | } 29 | >({ 30 | contract, 31 | method: 'positions', 32 | args: [String(tokenId)], 33 | mutation: false, 34 | }) 35 | const arrayified = arrayify(res) 36 | return { 37 | property: arrayified[0], 38 | amount: arrayified[1], 39 | price: arrayified[2], 40 | cumulativeReward: arrayified[3], 41 | pendingReward: arrayified[4], 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/positionsOfOwner.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPositionsOfOwnerCaller } from './positionsOfOwner' 2 | 3 | describe('positionsOfOwner.spec.ts', () => { 4 | describe('createPositionsOfOwnerCaller', () => { 5 | it('call success', async () => { 6 | const value = ['1', '2', '3', '4', '5', '6'] 7 | 8 | const contract = { 9 | positionsOfOwner: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createPositionsOfOwnerCaller(contract as any) 16 | 17 | const result = await caller('0xAddress') 18 | 19 | expect(result).toEqual([1, 2, 3, 4, 5, 6]) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | positionsOfOwner: jest 27 | .fn() 28 | .mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createPositionsOfOwnerCaller(contract as any) 33 | 34 | const result = await caller('0xAddress').catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/positionsOfOwner.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreatePositionsOfOwnerCaller = ( 6 | contract: ethers.Contract, 7 | ) => (accountAddress: string) => Promise 8 | 9 | export const createPositionsOfOwnerCaller: CreatePositionsOfOwnerCaller = 10 | (contract: ethers.Contract) => async (accountAddress: string) => { 11 | const res = await execute({ 12 | contract, 13 | method: 'positionsOfOwner', 14 | args: [accountAddress], 15 | mutation: false, 16 | }) 17 | return res.map(Number) 18 | } 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/positionsOfProperty.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPositionsOfPropertyCaller } from './positionsOfProperty' 2 | 3 | describe('positionsOfProperty.spec.ts', () => { 4 | describe('createPositionsOfPropertyCaller', () => { 5 | it('call success', async () => { 6 | const value = ['1', '2', '3', '4', '5', '6'] 7 | 8 | const contract = { 9 | positionsOfProperty: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createPositionsOfPropertyCaller(contract as any) 16 | 17 | const result = await caller('0xAddress') 18 | 19 | expect(result).toEqual([1, 2, 3, 4, 5, 6]) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | positionsOfProperty: jest 27 | .fn() 28 | .mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createPositionsOfPropertyCaller(contract as any) 33 | 34 | const result = await caller('0xAddress').catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/positionsOfProperty.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreatePositionsOfPropertyCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string) => Promise 8 | 9 | export const createPositionsOfPropertyCaller: CreatePositionsOfPropertyCaller = 10 | (contract: ethers.Contract) => async (propertyAddress: string) => { 11 | const res = await execute({ 12 | contract, 13 | method: 'positionsOfProperty', 14 | args: [propertyAddress], 15 | mutation: false, 16 | }) 17 | return res.map(Number) 18 | } 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/rewards.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { arrayify } from '../../common/utils/arrayify' 5 | 6 | export type Rewards = { 7 | readonly entireReward: string 8 | readonly cumulativeReward: string 9 | readonly withdrawableReward: string 10 | } 11 | 12 | export type CreateRewardsCaller = ( 13 | contract: ethers.Contract, 14 | ) => (tokenId: number) => Promise 15 | 16 | export const createRewardsCaller: CreateRewardsCaller = 17 | (contract: ethers.Contract) => async (tokenId: number) => { 18 | const res = await execute< 19 | QueryOption, 20 | { 21 | readonly entireReward_: string 22 | readonly cumulativeReward_: string 23 | readonly withdrawableReward_: string 24 | } 25 | >({ 26 | contract, 27 | method: 'rewards', 28 | args: [String(tokenId)], 29 | mutation: false, 30 | }) 31 | const arrayified = arrayify(res) 32 | return { 33 | entireReward: arrayified[0], 34 | cumulativeReward: arrayified[1], 35 | withdrawableReward: arrayified[2], 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/royaltyOf.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateRoyaltyOfCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string) => Promise 8 | 9 | export const createRoyaltyOfCaller: CreateRoyaltyOfCaller = 10 | (contract: ethers.Contract) => async (propertyAddress: string) => { 11 | const res = execute({ 12 | contract, 13 | method: 'royaltyOf', 14 | args: [propertyAddress], 15 | mutation: false, 16 | }) 17 | return res 18 | } 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/setSTokenRoyaltyForProperty.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, MutationOption } from '../../common/utils/execute' 3 | import type { TransactionResponse } from 'ethers' 4 | 5 | export type CreateSetSTokenRoyaltyForPropertyCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string, royalty: number) => Promise 8 | 9 | export const createSetSTokenRoyaltyForPropertyCaller: CreateSetSTokenRoyaltyForPropertyCaller = 10 | 11 | (contract: ethers.Contract) => 12 | async (propertyAddress: string, royalty: number) => 13 | execute({ 14 | contract, 15 | method: 'setSTokenRoyaltyForProperty', 16 | mutation: true, 17 | args: [propertyAddress, String(royalty)], 18 | }) 19 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/setTokenURIDescriptor.ts: -------------------------------------------------------------------------------- 1 | import { ethers, keccak256 } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateSetTokenURIDescriptorCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | propertyAddress: string, 13 | descriptorAddress: string, 14 | payloads?: ReadonlyArray, 15 | overrides?: FallbackableOverrides, 16 | ) => Promise 17 | 18 | export const createSetTokenURIDescriptorCaller: CreateSetTokenURIDescriptorCaller = 19 | 20 | (contract: ethers.Contract) => 21 | async ( 22 | propertyAddress: string, 23 | descriptorAddress: string, 24 | payloads?: ReadonlyArray, 25 | overrides?: FallbackableOverrides, 26 | ) => 27 | execute({ 28 | contract, 29 | method: 'setTokenURIDescriptor', 30 | mutation: true, 31 | args: payloads 32 | ? [ 33 | propertyAddress, 34 | descriptorAddress, 35 | payloads.map((p) => (p instanceof Uint8Array ? keccak256(p) : p)), 36 | ] 37 | : [propertyAddress, descriptorAddress], 38 | overrides, 39 | interface: payloads ? 'address,address,bytes32[]' : 'address,address', 40 | }) 41 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/setTokenURIImage.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateSetTokenURIImageCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | tokenId: number, 13 | data: string, 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createSetTokenURIImageCaller: CreateSetTokenURIImageCaller = 18 | (contract: ethers.Contract) => 19 | async (tokenId: number, data: string, overrides?: FallbackableOverrides) => 20 | execute({ 21 | contract, 22 | method: 'setTokenURIImage', 23 | mutation: true, 24 | args: [String(tokenId), data], 25 | overrides, 26 | }) 27 | -------------------------------------------------------------------------------- /lib/ethereum/s-tokens/tokenURI.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { decode } from 'js-base64' 3 | import { ethers } from 'ethers' 4 | import { execute, QueryOption } from '../../common/utils/execute' 5 | 6 | export type TokenURI = { 7 | readonly name: string 8 | readonly description: string 9 | readonly image: string 10 | readonly attributes: readonly [ 11 | { 12 | readonly trait_type: 'Destination' 13 | readonly value: string 14 | }, 15 | { 16 | readonly trait_type: 'Locked Amount' 17 | readonly display_type: 'number' 18 | readonly value: number 19 | }, 20 | { 21 | readonly trait_type: 'Payload' 22 | readonly value: string 23 | }, 24 | ] 25 | } 26 | 27 | export type CreateTokenURICaller = ( 28 | contract: ethers.Contract, 29 | ) => (tokenId: number) => Promise 30 | 31 | export const createTokenURICaller: CreateTokenURICaller = 32 | (contract: ethers.Contract) => async (tokenId: number) => { 33 | const res = await execute({ 34 | contract, 35 | method: 'tokenURI', 36 | args: [String(tokenId)], 37 | mutation: false, 38 | }) 39 | const decoded = decode( 40 | res.replace(/^data:application\/json;base64,(.*)/, '$1'), 41 | ).replace(/\n/g, '\\n') 42 | return JSON.parse(decoded) 43 | } 44 | -------------------------------------------------------------------------------- /lib/ethereum/simpleCollection/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | 3 | import { createQueryCaller } from './queryCaller' 4 | import { simpleCollectionsAbi } from './abi' 5 | import { createSetImagesCaller } from './setImages' 6 | import { createRemoveImageCaller } from './removeImage' 7 | 8 | export const createSimpleCollectionsContract = 9 | (provider: ContractRunner) => (address: string) => { 10 | const contractClient: ethers.Contract = new ethers.Contract( 11 | address, 12 | [...simpleCollectionsAbi], 13 | provider, 14 | ) 15 | 16 | return { 17 | image: createQueryCaller(contractClient, 'image'), 18 | name: createQueryCaller(contractClient, 'name'), 19 | description: createQueryCaller(contractClient, 'description'), 20 | setImages: createSetImagesCaller(contractClient), 21 | removeImage: createRemoveImageCaller(contractClient), 22 | } 23 | } 24 | 25 | export { Image } from './types' 26 | -------------------------------------------------------------------------------- /lib/ethereum/simpleCollection/queryCaller.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | 3 | import { Rewards } from '../s-tokens/rewards' 4 | import { execute, QueryOption } from '../../common/utils/execute' 5 | import { Positions as StakingPosition } from '../s-tokens/positions' 6 | 7 | type QueryMethods = 'image' | 'name' | 'description' 8 | 9 | export type CreateQueryCaller = ( 10 | contract: ethers.Contract, 11 | method: QueryMethods, 12 | ) => ( 13 | id: number, 14 | address: string, 15 | stakingPositions: StakingPosition, 16 | rewards: Rewards, 17 | keys: readonly string[], 18 | ) => Promise 19 | 20 | export const createQueryCaller: CreateQueryCaller = 21 | (contract: ethers.Contract, method: QueryMethods) => 22 | async ( 23 | id: number, 24 | address: string, 25 | stakingPositions: StakingPosition, 26 | rewards: Rewards, 27 | keys: readonly string[], 28 | ) => 29 | execute({ 30 | contract, 31 | method: method, 32 | args: [String(id), address, stakingPositions, rewards, keys], 33 | mutation: false, 34 | }) 35 | -------------------------------------------------------------------------------- /lib/ethereum/simpleCollection/removeImage.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type RemoveImage = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | propertyAddress: string, 13 | keys: readonly string[], 14 | overrides?: FallbackableOverrides, 15 | ) => Promise 16 | 17 | export const createRemoveImageCaller: RemoveImage = 18 | (contract: ethers.Contract) => 19 | async ( 20 | propertyAddress: string, 21 | keys: readonly string[], 22 | overrides?: FallbackableOverrides, 23 | ) => 24 | execute({ 25 | contract, 26 | method: 'removeImage', 27 | mutation: true, 28 | args: [propertyAddress, keys], 29 | overrides, 30 | }) 31 | -------------------------------------------------------------------------------- /lib/ethereum/simpleCollection/setImages.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | import { Image } from './types' 10 | 11 | export type SetImages = ( 12 | contract: ethers.Contract, 13 | ) => ( 14 | propertyAddress: string, 15 | images: readonly Image[], 16 | keys: readonly string[], 17 | overrides?: FallbackableOverrides, 18 | ) => Promise 19 | 20 | export const createSetImagesCaller: SetImages = 21 | (contract: ethers.Contract) => 22 | async ( 23 | propertyAddress: string, 24 | images: readonly Image[], 25 | keys: readonly string[], 26 | overrides?: FallbackableOverrides, 27 | ) => 28 | execute({ 29 | contract, 30 | method: 'setImages', 31 | mutation: true, 32 | args: [propertyAddress, images, keys], 33 | overrides, 34 | }) 35 | -------------------------------------------------------------------------------- /lib/ethereum/simpleCollection/types.ts: -------------------------------------------------------------------------------- 1 | export type Image = { 2 | readonly src?: string 3 | readonly name?: string 4 | readonly description?: string 5 | readonly requiredETHAmount?: number | string 6 | readonly requiredETHFee?: number | string 7 | readonly gateway?: string 8 | } 9 | -------------------------------------------------------------------------------- /lib/ethereum/withdraw/bulkWithdraw.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, MutationOption } from '../../common/utils/execute' 3 | import type { TransactionResponse } from 'ethers' 4 | 5 | export type CreateBulkWithdrawCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddresses: readonly string[]) => Promise 8 | 9 | export const createBulkWithdrawCaller: CreateBulkWithdrawCaller = 10 | (contract: ethers.Contract) => 11 | async (propertyAddresses): Promise => 12 | execute({ 13 | contract, 14 | method: 'bulkWithdraw', 15 | mutation: true, 16 | args: propertyAddresses, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/ethereum/withdraw/calculateRewardAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type calculateRewardAmountCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, accountAddress: string) => Promise 7 | 8 | export const calculateRewardAmountCaller: calculateRewardAmountCaller = 9 | (contract: ethers.Contract) => 10 | async (propertyAddress: string, accountAddress: string) => 11 | execute({ 12 | contract, 13 | method: 'calculateRewardAmount', 14 | args: [propertyAddress, accountAddress], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/ethereum/withdraw/calculateWithdrawableAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateCalculateWithdrawableAmountCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, accountAddress: string) => Promise 7 | 8 | export const createCalculateWithdrawableAmountCaller: CreateCalculateWithdrawableAmountCaller = 9 | 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string, accountAddress: string) => 12 | execute({ 13 | contract, 14 | method: 'calculateWithdrawableAmount', 15 | args: [propertyAddress, accountAddress], 16 | mutation: false, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/ethereum/withdraw/getRewardsAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateGetRewardsAmountCaller = ( 5 | contract: ethers.Contract, 6 | ) => (address: string) => Promise 7 | 8 | export const createGetRewardsAmountCaller: CreateGetRewardsAmountCaller = 9 | (contract: ethers.Contract) => async (address: string) => 10 | execute({ 11 | contract, 12 | method: 'getRewardsAmount', 13 | args: [address], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/ethereum/withdraw/withdraw.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { 3 | execute, 4 | FallbackableOverrides, 5 | MutationOption, 6 | } from '../../common/utils/execute' 7 | import type { TransactionResponse } from 'ethers' 8 | 9 | export type CreateWithdrawCaller = ( 10 | contract: ethers.Contract, 11 | ) => ( 12 | propertyAddress: string, 13 | overrides?: FallbackableOverrides, 14 | ) => Promise 15 | 16 | export const createWithdrawCaller: CreateWithdrawCaller = 17 | (contract: ethers.Contract) => 18 | async (propertyAddress: string, overrides?: FallbackableOverrides) => 19 | execute({ 20 | contract, 21 | method: 'withdraw', 22 | mutation: true, 23 | args: [propertyAddress], 24 | overrides, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/l2/client/index.ts: -------------------------------------------------------------------------------- 1 | import { createDetectSTokens } from '../../ethereum/client/createDetectSTokens' 2 | 3 | export type DevkitClient = { 4 | readonly createDetectSTokens: typeof createDetectSTokens 5 | } 6 | 7 | export const client: DevkitClient = { 8 | createDetectSTokens, 9 | } 10 | 11 | export { createDetectSTokens } 12 | -------------------------------------------------------------------------------- /lib/l2/dev/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../ethereum/dev/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/dev/index.ts: -------------------------------------------------------------------------------- 1 | import { createErc20Contract, Erc20Contract } from '../../common/erc20' 2 | 3 | export const createDevContract = createErc20Contract 4 | export type DevContract = Erc20Contract 5 | -------------------------------------------------------------------------------- /lib/l2/erc20/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../common/erc20/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/erc20/index.ts: -------------------------------------------------------------------------------- 1 | export { createErc20Contract, Erc20Contract } from '../../common/erc20' 2 | -------------------------------------------------------------------------------- /lib/l2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './contract' 2 | export * from './client' 3 | export * from './dev' 4 | export * from './erc20' 5 | export * from './lockup' 6 | export * from './market' 7 | export * from './market-behavior' 8 | export * from './market-factory' 9 | export * from './metrics' 10 | export * from './metrics-factory' 11 | export * from './policy' 12 | export * from './policy-factory' 13 | export * from './property' 14 | export * from './property-factory' 15 | export * from './registry' 16 | export * from './s-tokens' 17 | export * from './withdraw' 18 | 19 | export * from './dev/abi' 20 | export * from './erc20/abi' 21 | export * from './lockup/abi' 22 | export * from './market/abi' 23 | export * from './market-behavior/abi' 24 | export * from './market-factory/abi' 25 | export * from './metrics/abi' 26 | export * from './metrics-factory/abi' 27 | export * from './policy/abi' 28 | export * from './policy-factory/abi' 29 | export * from './property/abi' 30 | export * from './property-factory/abi' 31 | export * from './registry/abi' 32 | export * from './s-tokens/abi' 33 | export * from './withdraw/abi' 34 | -------------------------------------------------------------------------------- /lib/l2/lockup/getLockedupProperties.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { always } from 'ramda' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type LockedupProperty = Readonly<{ 6 | readonly property: string 7 | readonly value: string 8 | }> 9 | 10 | export type CreateGetLockedupPropertiesCaller = ( 11 | contract: ethers.Contract, 12 | ) => () => Promise 13 | 14 | export const createGetLockedupPropertiesCaller: CreateGetLockedupPropertiesCaller = 15 | (contract: ethers.Contract) => 16 | always( 17 | execute({ 18 | contract, 19 | method: 'getLockedupProperties', 20 | mutation: false, 21 | }), 22 | ) 23 | -------------------------------------------------------------------------------- /lib/l2/lockup/totalLocked.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTotalLockedCaller } from './totalLocked' 2 | 3 | describe('totalLocked.spec.ts', () => { 4 | describe('createTotalLockedCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const lockupContract = { 9 | totalLocked: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTotalLockedCaller(lockupContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const lockupContract = { 28 | totalLocked: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createTotalLockedCaller(lockupContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/l2/lockup/totalLocked.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { always } from 'ramda' 5 | 6 | export type CreateTotalLockedCaller = ( 7 | contract: ethers.Contract, 8 | ) => () => Promise 9 | 10 | export const createTotalLockedCaller: CreateTotalLockedCaller = ( 11 | contract: ethers.Contract, 12 | ) => 13 | always( 14 | execute({ contract, method: 'totalLocked', mutation: false }), 15 | ) 16 | -------------------------------------------------------------------------------- /lib/l2/lockup/totalLockedForProperty.spec.ts: -------------------------------------------------------------------------------- 1 | import { createTotalLockedForPropertyCaller } from './totalLockedForProperty' 2 | 3 | describe('totalLockedForProperty.spec.ts', () => { 4 | describe('createTotalLockedForPropertyCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const lockupContract = { 9 | totalLockedForProperty: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createTotalLockedForPropertyCaller(lockupContract as any) 18 | 19 | const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const lockupContract = { 28 | totalLockedForProperty: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createTotalLockedForPropertyCaller(lockupContract as any) 35 | 36 | const result = await caller( 37 | '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', 38 | ).catch((err) => err) 39 | 40 | expect(result).toEqual(error) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /lib/l2/lockup/totalLockedForProperty.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateTotalLockedForPropertyCaller = ( 6 | contract: ethers.Contract, 7 | ) => (address: string) => Promise 8 | 9 | export const createTotalLockedForPropertyCaller: CreateTotalLockedForPropertyCaller = 10 | (contract: ethers.Contract) => async (address: string) => 11 | execute({ 12 | contract, 13 | method: 'totalLockedForProperty', 14 | args: [address], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/l2/market-behavior/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../ethereum/market-behavior/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/market-behavior/index.ts: -------------------------------------------------------------------------------- 1 | export { createMarketBehaviorContract } from '../../ethereum/market-behavior' 2 | -------------------------------------------------------------------------------- /lib/l2/market-factory/getEnabledMarkets.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetEnabledMarketsCaller } from './getEnabledMarkets' 2 | 3 | describe('getEnabledMarkets.spec.ts', () => { 4 | describe('createGetEnabledMarketsCaller', () => { 5 | it('call success', async () => { 6 | const value = ['0x0', '0x1', '0x2'] 7 | 8 | const marketFactoryContract = { 9 | getEnabledMarkets: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createGetEnabledMarketsCaller(marketFactoryContract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const marketFactoryContract = { 28 | getEnabledMarkets: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createGetEnabledMarketsCaller(marketFactoryContract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/l2/market-factory/getEnabledMarkets.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { always } from 'ramda' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateGetEnabledMarketsCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createGetEnabledMarketsCaller: CreateGetEnabledMarketsCaller = ( 10 | contract: ethers.Contract, 11 | ) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'getEnabledMarkets', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/l2/market-factory/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { marketFactoryAbi } from './abi' 3 | import { createCreateCaller } from '../../ethereum/market-factory/create' 4 | import { createGetEnabledMarketsCaller } from './getEnabledMarkets' 5 | import type { TransactionResponse } from 'ethers' 6 | 7 | export type MarketFactoryContract = { 8 | readonly create: ( 9 | marketBehaviorAddress: string, 10 | ) => Promise 11 | readonly getEnabledMarkets: () => Promise 12 | readonly contract: () => ethers.Contract 13 | } 14 | 15 | export const createMarketFactoryContract = 16 | (provider: ContractRunner) => 17 | (address: string): MarketFactoryContract => { 18 | const contract = new ethers.Contract( 19 | address, 20 | [...marketFactoryAbi], 21 | provider, 22 | ) 23 | return { 24 | create: createCreateCaller(contract), 25 | getEnabledMarkets: createGetEnabledMarketsCaller(contract), 26 | contract: () => contract, 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/l2/market/getAuthenticatedProperties.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetAuthenticatedPropertiesCaller } from './getAuthenticatedProperties' 2 | 3 | describe('getAuthenticatedProperties.spec.ts', () => { 4 | describe('createGetAuthenticatedPropertiesCaller', () => { 5 | it('call success', async () => { 6 | const value = ['0x0', '0x1', '0x2'] 7 | 8 | const marketContract = { 9 | getAuthenticatedProperties: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createGetAuthenticatedPropertiesCaller( 18 | marketContract as any, 19 | ) 20 | 21 | const result = await caller() 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const error = 'error' 28 | 29 | const marketContract = { 30 | getAuthenticatedProperties: jest 31 | .fn() 32 | .mockImplementation(async () => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createGetAuthenticatedPropertiesCaller( 37 | marketContract as any, 38 | ) 39 | 40 | const result = await caller().catch((err) => err) 41 | 42 | expect(result).toEqual(error) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /lib/l2/market/getAuthenticatedProperties.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { always } from 'ramda' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateGetAuthenticatedPropertiesCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createGetAuthenticatedPropertiesCaller: CreateGetAuthenticatedPropertiesCaller = 10 | (contract: ethers.Contract) => 11 | always( 12 | execute({ 13 | contract, 14 | method: 'getAuthenticatedProperties', 15 | mutation: false, 16 | }), 17 | ) 18 | -------------------------------------------------------------------------------- /lib/l2/market/name.spec.ts: -------------------------------------------------------------------------------- 1 | import { createNameCaller } from './name' 2 | 3 | describe('name.spec.ts', () => { 4 | describe('createNameCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const contract = { 9 | name: jest.fn().mockImplementation(async () => Promise.resolve(value)), 10 | } 11 | 12 | const expected = value 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createNameCaller(contract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(expected) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | name: jest.fn().mockImplementation(async () => Promise.reject(error)), 27 | } 28 | 29 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 30 | const caller = createNameCaller(contract as any) 31 | 32 | const result = await caller().catch((err) => err) 33 | 34 | expect(result).toEqual(error) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /lib/l2/market/name.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateNameCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createNameCaller: CreateNameCaller = (contract: ethers.Contract) => 10 | always( 11 | execute({ 12 | contract, 13 | method: 'name', 14 | mutation: false, 15 | }), 16 | ) 17 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/authenticatedPropertiesCount.spec.ts: -------------------------------------------------------------------------------- 1 | import { createAuthenticatedPropertiesCountCaller } from './authenticatedPropertiesCount' 2 | 3 | describe('authenticatedPropertiesCount.spec.ts', () => { 4 | describe('createAuthenticatedPropertiesCountCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const metricsFactoryContract = { 9 | authenticatedPropertiesCount: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createAuthenticatedPropertiesCountCaller( 18 | metricsFactoryContract as any, 19 | ) 20 | 21 | const result = await caller() 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const error = 'error' 28 | 29 | const metricsGroupContract = { 30 | authenticatedPropertiesCount: jest 31 | .fn() 32 | .mockImplementation(async () => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createAuthenticatedPropertiesCountCaller( 37 | metricsGroupContract as any, 38 | ) 39 | 40 | const result = await caller().catch((err) => err) 41 | 42 | expect(result).toEqual(error) 43 | }) 44 | }) 45 | }) 46 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/authenticatedPropertiesCount.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { always } from 'ramda' 5 | 6 | export type CreateAuthenticatedPropertiesCountCaller = ( 7 | contract: ethers.Contract, 8 | ) => () => Promise 9 | 10 | export const createAuthenticatedPropertiesCountCaller: CreateAuthenticatedPropertiesCountCaller = 11 | (contract: ethers.Contract) => 12 | always( 13 | execute({ 14 | contract, 15 | method: 'authenticatedPropertiesCount', 16 | mutation: false, 17 | }), 18 | ) 19 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { metricsFactoryAbi } from './abi' 3 | import { createAuthenticatedPropertiesCountCaller } from './authenticatedPropertiesCount' 4 | import { createMetricsOfPropertyCaller } from './metricsOfProperty' 5 | import { createMetricsCountCaller } from './metricsCount' 6 | 7 | export type MetricsFactoryContract = { 8 | readonly authenticatedPropertiesCount: () => Promise 9 | readonly metricsCount: () => Promise 10 | readonly metricsOfProperty: ( 11 | propertyAddress: string, 12 | ) => Promise 13 | readonly contract: () => ethers.Contract 14 | } 15 | 16 | // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types 17 | export const createMetricsFactoryContract = 18 | (provider: ContractRunner) => 19 | (address: string): MetricsFactoryContract => { 20 | const contract = new ethers.Contract( 21 | address, 22 | [...metricsFactoryAbi], 23 | provider, 24 | ) 25 | 26 | return { 27 | authenticatedPropertiesCount: 28 | createAuthenticatedPropertiesCountCaller(contract), 29 | metricsCount: createMetricsCountCaller(contract), 30 | metricsOfProperty: createMetricsOfPropertyCaller(contract), 31 | contract: () => contract, 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/metricsCount.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMetricsCountCaller } from './metricsCount' 2 | 3 | describe('metricsCount.spec.ts', () => { 4 | describe('createMetricsCountCaller', () => { 5 | it('call success', async () => { 6 | const value = 123456n 7 | 8 | const metricsFactoryContract = { 9 | metricsCount: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createMetricsCountCaller(metricsFactoryContract as any) 16 | 17 | const result = await caller() 18 | 19 | expect(result).toEqual(123456) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const metricsGroupContract = { 26 | metricsCount: jest 27 | .fn() 28 | .mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createMetricsCountCaller(metricsGroupContract as any) 33 | 34 | const result = await caller().catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/metricsCount.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | import { always } from 'ramda' 5 | 6 | export type CreateMetricsCountCaller = ( 7 | contract: ethers.Contract, 8 | ) => () => Promise 9 | 10 | export const createMetricsCountCaller: CreateMetricsCountCaller = ( 11 | contract: ethers.Contract, 12 | ) => 13 | always( 14 | execute({ 15 | contract, 16 | method: 'metricsCount', 17 | mutation: false, 18 | }).then(Number), 19 | ) 20 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/metricsOfProperty.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMetricsOfPropertyCaller } from './metricsOfProperty' 2 | 3 | describe('metricsOfProperty.spec.ts', () => { 4 | describe('createMetricsOfPropertyCaller', () => { 5 | it('call success', async () => { 6 | const value = ['0x0', '0x1', '0x2'] 7 | 8 | const metricsFactoryContract = { 9 | metricsOfProperty: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMetricsOfPropertyCaller( 18 | metricsFactoryContract as any, 19 | ) 20 | 21 | const result = await caller('property') 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const error = 'error' 28 | 29 | const metricsGroupContract = { 30 | metricsOfProperty: jest 31 | .fn() 32 | .mockImplementation(async () => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createMetricsOfPropertyCaller(metricsGroupContract as any) 37 | 38 | const result = await caller('property').catch((err) => err) 39 | 40 | expect(result).toEqual(error) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /lib/l2/metrics-factory/metricsOfProperty.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateMetricsOfPropertyCaller = ( 6 | contract: ethers.Contract, 7 | ) => (propertyAddress: string) => Promise 8 | 9 | export const createMetricsOfPropertyCaller: CreateMetricsOfPropertyCaller = 10 | (contract: ethers.Contract) => (propertyAddress: string) => 11 | execute({ 12 | contract, 13 | method: 'metricsOfProperty', 14 | args: [propertyAddress], 15 | mutation: false, 16 | }) 17 | -------------------------------------------------------------------------------- /lib/l2/metrics/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../ethereum/metrics/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/metrics/index.ts: -------------------------------------------------------------------------------- 1 | export { createMetricsContract } from '../../ethereum/metrics' 2 | -------------------------------------------------------------------------------- /lib/l2/policy-factory/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../ethereum/policy-factory/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/policy-factory/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | createPolicyFactoryContract, 3 | PolicyFactoryContract, 4 | } from '../../ethereum/policy-factory' 5 | -------------------------------------------------------------------------------- /lib/l2/policy/marketVotingSeconds.spec.ts: -------------------------------------------------------------------------------- 1 | import { createMarketVotingSecondsCaller } from './marketVotingSeconds' 2 | 3 | describe('marketVotingSeconds.spec.ts', () => { 4 | describe('createMarketVotingSecondsCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | marketVotingSeconds: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createMarketVotingSecondsCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | marketVotingSeconds: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createMarketVotingSecondsCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/l2/policy/marketVotingSeconds.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreateMarketVotingSecondsCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createMarketVotingSecondsCaller: CreateMarketVotingSecondsCaller = 10 | (contract: ethers.Contract) => 11 | always( 12 | execute({ 13 | contract, 14 | method: 'marketVotingSeconds', 15 | mutation: false, 16 | }), 17 | ) 18 | -------------------------------------------------------------------------------- /lib/l2/policy/policyVotingSeconds.spec.ts: -------------------------------------------------------------------------------- 1 | import { createPolicyVotingSecondsCaller } from './policyVotingSeconds' 2 | 3 | describe('policyVotingSeconds.spec.ts', () => { 4 | describe('createPolicyVotingSecondsCaller', () => { 5 | it('call success', async () => { 6 | const value = '1111' 7 | 8 | const contract = { 9 | policyVotingSeconds: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = createPolicyVotingSecondsCaller(contract as any) 18 | 19 | const result = await caller() 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const contract = { 28 | policyVotingSeconds: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = createPolicyVotingSecondsCaller(contract as any) 35 | 36 | const result = await caller().catch((err) => err) 37 | 38 | expect(result).toEqual(error) 39 | }) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /lib/l2/policy/policyVotingSeconds.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { always } from 'ramda' 4 | 5 | export type CreatePolicyVotingSecondsCaller = ( 6 | contract: ethers.Contract, 7 | ) => () => Promise 8 | 9 | export const createPolicyVotingSecondsCaller: CreatePolicyVotingSecondsCaller = 10 | (contract: ethers.Contract) => 11 | always( 12 | execute({ 13 | contract, 14 | method: 'policyVotingSeconds', 15 | mutation: false, 16 | }), 17 | ) 18 | -------------------------------------------------------------------------------- /lib/l2/property-factory/getPropertiesOfAuthor.spec.ts: -------------------------------------------------------------------------------- 1 | import { createGetPropertiesOfAuthorCaller } from './getPropertiesOfAuthor' 2 | 3 | describe('getPropertiesOfAuthor.spec.ts', () => { 4 | describe('createGetPropertiesOfAuthorrCaller', () => { 5 | it('call success', async () => { 6 | const value = ['0x1', '0x2', '0x3', '0x4', '0x5', '0x6'] 7 | 8 | const contract = { 9 | getPropertiesOfAuthor: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 15 | const caller = createGetPropertiesOfAuthorCaller(contract as any) 16 | 17 | const result = await caller('0xAddress') 18 | 19 | expect(result).toEqual(value) 20 | }) 21 | 22 | it('call failure', async () => { 23 | const error = 'error' 24 | 25 | const contract = { 26 | getPropertiesOfAuthor: jest 27 | .fn() 28 | .mockImplementation(async () => Promise.reject(error)), 29 | } 30 | 31 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 32 | const caller = createGetPropertiesOfAuthorCaller(contract as any) 33 | 34 | const result = await caller('0xAddress').catch((err) => err) 35 | 36 | expect(result).toEqual(error) 37 | }) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /lib/l2/property-factory/getPropertiesOfAuthor.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ 2 | import { ethers } from 'ethers' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type CreateGetPropertiesOfAuthorCaller = ( 6 | contract: ethers.Contract, 7 | ) => (authorAddress: string) => Promise 8 | 9 | export const createGetPropertiesOfAuthorCaller: CreateGetPropertiesOfAuthorCaller = 10 | (contract: ethers.Contract) => async (authorAddress: string) => { 11 | const res = await execute({ 12 | contract, 13 | method: 'getPropertiesOfAuthor', 14 | args: [authorAddress], 15 | mutation: false, 16 | }) 17 | return res 18 | } 19 | -------------------------------------------------------------------------------- /lib/l2/property/getBalances.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { always } from 'ramda' 3 | import { execute, QueryOption } from '../../common/utils/execute' 4 | 5 | export type PropertyBalance = Readonly<{ 6 | readonly account: string 7 | readonly balance: string 8 | }> 9 | 10 | export type CreateGetBalancesCaller = ( 11 | contract: ethers.Contract, 12 | ) => () => Promise 13 | 14 | export const createGetBalancesCaller: CreateGetBalancesCaller = ( 15 | contract: ethers.Contract, 16 | ) => 17 | always( 18 | execute({ 19 | contract, 20 | method: 'getBalances', 21 | mutation: false, 22 | }), 23 | ) 24 | -------------------------------------------------------------------------------- /lib/l2/registry/index.spec.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { createRegistryContract, RegistryContract } from '.' 3 | import { addressRegistryAbi } from './abi' 4 | import { createRegistriesCaller } from './registries' 5 | 6 | jest.mock('./registries') 7 | jest.mock('ethers') 8 | 9 | describe('registry/index.ts', () => { 10 | ;(createRegistriesCaller as jest.Mock).mockImplementation(() => 123) 11 | ;(ethers.Contract as jest.Mock).mockImplementation(() => 123) 12 | 13 | describe('createRegistryContract', () => { 14 | it('check return object', () => { 15 | const host = 'localhost' 16 | const address = '0x0000000000000000000000000000000000000000' 17 | const provider = new ethers.JsonRpcProvider(host) 18 | 19 | const expected: (address: string) => RegistryContract = ( 20 | address: string, 21 | ) => { 22 | const contract = new ethers.Contract( 23 | address, 24 | [...addressRegistryAbi], 25 | provider, 26 | ) 27 | 28 | return { 29 | registries: createRegistriesCaller(contract), 30 | contract: () => contract, 31 | } 32 | } 33 | 34 | const result = createRegistryContract(provider) 35 | 36 | expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) 37 | expect(JSON.stringify(result(address))).toEqual( 38 | JSON.stringify(expected(address)), 39 | ) 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /lib/l2/registry/index.ts: -------------------------------------------------------------------------------- 1 | import { ContractRunner, ethers } from 'ethers' 2 | import { addressRegistryAbi } from './abi' 3 | import { createRegistriesCaller } from './registries' 4 | 5 | export type RegistryContract = { 6 | readonly registries: (key: string) => Promise 7 | readonly contract: () => ethers.Contract 8 | } 9 | 10 | export type CreateRegistryContract = ( 11 | provider: ContractRunner, 12 | ) => (address: string) => RegistryContract 13 | 14 | export const createRegistryContract: CreateRegistryContract = 15 | (provider: ContractRunner) => 16 | (address: string): RegistryContract => { 17 | const contract = new ethers.Contract( 18 | address, 19 | [...addressRegistryAbi], 20 | provider, 21 | ) 22 | 23 | return { 24 | registries: createRegistriesCaller(contract), 25 | contract: () => contract, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/l2/registry/registries.spec.ts: -------------------------------------------------------------------------------- 1 | import { createRegistriesCaller } from './registries' 2 | 3 | describe('registries.spec.ts', () => { 4 | describe('createRegistriesCaller', () => { 5 | it('call success', async () => { 6 | const value = 'value' 7 | 8 | const contract = { 9 | registries: jest 10 | .fn() 11 | .mockImplementation(async (key: string) => 12 | Promise.resolve(key === 'test' ? value : undefined), 13 | ), 14 | } 15 | 16 | const expected = value 17 | 18 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 19 | const caller = createRegistriesCaller(contract as any) 20 | 21 | const result = await caller('test') 22 | 23 | expect(result).toEqual(expected) 24 | }) 25 | 26 | it('call failure', async () => { 27 | const error = 'error' 28 | 29 | const contract = { 30 | registries: jest 31 | .fn() 32 | .mockImplementation(async () => Promise.reject(error)), 33 | } 34 | 35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 36 | const caller = createRegistriesCaller(contract as any) 37 | 38 | const result = await caller('test').catch((err) => err) 39 | 40 | expect(result).toEqual(error) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /lib/l2/registry/registries.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type CreateRegistriesCaller = ( 5 | contract: ethers.Contract, 6 | ) => (key: string) => Promise 7 | 8 | export const createRegistriesCaller: CreateRegistriesCaller = 9 | (contract: ethers.Contract) => (key: string) => 10 | execute({ 11 | contract, 12 | method: 'registries', 13 | args: [key], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/l2/s-tokens/abi.ts: -------------------------------------------------------------------------------- 1 | export * from '../../ethereum/s-tokens/abi' 2 | -------------------------------------------------------------------------------- /lib/l2/s-tokens/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | createSTokensContract, 3 | STokensContract, 4 | Positions, 5 | } from '../../ethereum/s-tokens' 6 | -------------------------------------------------------------------------------- /lib/l2/withdraw/calculateRewardAmount.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | import { arrayify } from '../../common/utils' 4 | 5 | export type HolderRewards = { 6 | readonly amount: string 7 | readonly price: string 8 | readonly cap: string 9 | readonly allReward: string 10 | } 11 | 12 | export type calculateRewardAmountCaller = ( 13 | contract: ethers.Contract, 14 | ) => (propertyAddress: string, accountAddress: string) => Promise 15 | 16 | export const calculateRewardAmountCaller: calculateRewardAmountCaller = 17 | (contract: ethers.Contract) => 18 | async (propertyAddress: string, accountAddress: string) => { 19 | const res = await execute< 20 | QueryOption, 21 | { 22 | readonly _amount: string 23 | readonly _price: string 24 | readonly _cap: string 25 | readonly _allReward: string 26 | } 27 | >({ 28 | contract, 29 | method: 'calculateRewardAmount', 30 | args: [propertyAddress, accountAddress], 31 | mutation: false, 32 | }) 33 | const [amount, price, cap, allReward] = arrayify(res) 34 | return { amount, price, cap, allReward } 35 | } 36 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryLength.spec.ts: -------------------------------------------------------------------------------- 1 | import { transferHistoryLengthCaller } from './transferHistoryLength' 2 | 3 | describe('transferHistoryLength.spec.ts', () => { 4 | describe('transferHistoryLengthCaller', () => { 5 | it('call success', async () => { 6 | const value = '123' 7 | 8 | const rewardContract = { 9 | transferHistoryLength: jest 10 | .fn() 11 | .mockImplementation(async () => Promise.resolve(value)), 12 | } 13 | 14 | const expected = value 15 | 16 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 17 | const caller = transferHistoryLengthCaller(rewardContract as any) 18 | 19 | const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') 20 | 21 | expect(result).toEqual(expected) 22 | }) 23 | 24 | it('call failure', async () => { 25 | const error = 'error' 26 | 27 | const rewardContract = { 28 | transferHistoryLength: jest 29 | .fn() 30 | .mockImplementation(async () => Promise.reject(error)), 31 | } 32 | 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const caller = transferHistoryLengthCaller(rewardContract as any) 35 | 36 | const result = await caller( 37 | '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', 38 | ).catch((err) => err) 39 | 40 | expect(result).toEqual(error) 41 | }) 42 | }) 43 | }) 44 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryLength.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type transferHistoryLengthCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string) => Promise 7 | 8 | export const transferHistoryLengthCaller: transferHistoryLengthCaller = 9 | (contract: ethers.Contract) => async (propertyAddress: string) => 10 | execute({ 11 | contract, 12 | method: 'transferHistoryLength', 13 | args: [propertyAddress], 14 | mutation: false, 15 | }) 16 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryLengthOfRecipient.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type transferHistoryLengthOfRecipientCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, recipient: string) => Promise 7 | 8 | export const transferHistoryLengthOfRecipientCaller: transferHistoryLengthOfRecipientCaller = 9 | 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string, recipient: string) => 12 | execute({ 13 | contract, 14 | method: 'transferHistoryLengthOfRecipient', 15 | args: [propertyAddress, recipient], 16 | mutation: false, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryLengthOfSender.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type transferHistoryLengthOfSenderCaller = ( 5 | contract: ethers.Contract, 6 | ) => (propertyAddress: string, sender: string) => Promise 7 | 8 | export const transferHistoryLengthOfSenderCaller: transferHistoryLengthOfSenderCaller = 9 | 10 | (contract: ethers.Contract) => 11 | async (propertyAddress: string, sender: string) => 12 | execute({ 13 | contract, 14 | method: 'transferHistoryLengthOfSender', 15 | args: [propertyAddress, sender], 16 | mutation: false, 17 | }) 18 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryOfRecipientByIndex.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type transferHistoryOfRecipientByIndexCaller = ( 5 | contract: ethers.Contract, 6 | ) => ( 7 | propertyAddress: string, 8 | recipient: string, 9 | index: number | string, 10 | ) => Promise 11 | 12 | export const transferHistoryOfRecipientByIndexCaller: transferHistoryOfRecipientByIndexCaller = 13 | 14 | (contract: ethers.Contract) => 15 | async ( 16 | propertyAddress: string, 17 | recipient: string, 18 | index: number | string, 19 | ) => 20 | execute({ 21 | contract, 22 | method: 'transferHistoryOfRecipientByIndex', 23 | args: [propertyAddress, recipient, String(index)], 24 | mutation: false, 25 | }) 26 | -------------------------------------------------------------------------------- /lib/l2/withdraw/transferHistoryOfSenderByIndex.ts: -------------------------------------------------------------------------------- 1 | import { ethers } from 'ethers' 2 | import { execute, QueryOption } from '../../common/utils/execute' 3 | 4 | export type transferHistoryOfSenderByIndexCaller = ( 5 | contract: ethers.Contract, 6 | ) => ( 7 | propertyAddress: string, 8 | sender: string, 9 | index: number | string, 10 | ) => Promise 11 | 12 | export const transferHistoryOfSenderByIndexCaller: transferHistoryOfSenderByIndexCaller = 13 | 14 | (contract: ethers.Contract) => 15 | async (propertyAddress: string, sender: string, index: number | string) => 16 | execute({ 17 | contract, 18 | method: 'transferHistoryOfSenderByIndex', 19 | args: [propertyAddress, sender, String(index)], 20 | mutation: false, 21 | }) 22 | -------------------------------------------------------------------------------- /lib/marketAddresses.ts: -------------------------------------------------------------------------------- 1 | export const marketAddresses = { 2 | eth: { 3 | main: { 4 | github: '0x34A7AdC94C4D41C3e3469F98033B372cB2fAf318', 5 | youtube: '0x2AD380927F509A1d6338b89A7286cFAc52a896Dd', 6 | }, 7 | ropsten: { 8 | github: '0x1A45BA7BB4a5A4a01Eb5330C9F2fd8af47C16eBe', 9 | }, 10 | }, 11 | arbitrum: { 12 | one: { 13 | github: '0x84b9e407e2Ee76A641b45d007bBFd9e60a13FF7d', 14 | youtube: '0x61999A2F3f403957315255D08A969602f19F2Dcf', 15 | discord: '0x0f02e7c1bc8769B56B20E03d2Fe277b42194C260', 16 | }, 17 | rinkeby: { 18 | github: '0xeb85170bce4ea8a9ca0fb5b6620ab74ef111a50c', 19 | youtube: '0x53f8A1DEe0aF272d995aF1e206116172c00f2eb4', 20 | discord: '0xC3af4341f71EfD7F74523D4cD9eD87F36Ed75A99', 21 | }, 22 | }, 23 | polygon: { 24 | mainnet: { 25 | github: '0xa7d0A25Cb2378c935FF94863C8614367b9e85Ed8', 26 | youtube: '0xfe607787e14A90A320cdfc05710b382380B4fd12', 27 | discord: '0x75b2C22E5f1EF64814D574caa9c4506Eba268502', 28 | }, 29 | mumbai: { 30 | github: '0x9edc758B0477559AB6556BCA9971B4DD892d8E28', 31 | youtube: '0x7C7CDc82b195d4dcf9a789BD14CD1C73232025a8', 32 | discord: '0xb5A7CFb9F495De44e58177990dac004b84e7C501', 33 | }, 34 | }, 35 | } as const 36 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base"], 3 | "automerge": true 4 | } 5 | -------------------------------------------------------------------------------- /rollup.config.d.js: -------------------------------------------------------------------------------- 1 | import dts from 'rollup-plugin-dts' 2 | 3 | const plugins = [dts()] 4 | const [, , , , _mode] = process.argv 5 | const mode = 6 | _mode === '--index' 7 | ? 0 8 | : _mode === '--abi' 9 | ? 1 10 | : _mode === '--l2' 11 | ? 2 12 | : _mode === '--agent' 13 | ? 3 14 | : undefined 15 | 16 | export default [ 17 | { 18 | input: 'dist/lib/index.d.ts', 19 | output: [{ file: 'dist/dev-kit.d.ts', format: 'es' }], 20 | plugins, 21 | }, 22 | { 23 | input: 'dist/lib/l2/index.d.ts', 24 | output: [{ file: './l2/index.d.ts', format: 'es' }], 25 | plugins, 26 | }, 27 | { 28 | input: 'dist/lib/agent/index.d.ts', 29 | output: [{ file: './agent/index.d.ts', format: 'es' }], 30 | plugins, 31 | }, 32 | ].filter((_, i) => (typeof mode === 'number' ? i === mode : true)) 33 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "target": "ESNext", 5 | "lib": ["dom", "es2018"], 6 | "strict": true, 7 | "strictNullChecks": true, 8 | "noImplicitAny": true, 9 | "noImplicitReturns": true, 10 | "skipLibCheck": true, 11 | "declaration": true, 12 | "declarationMap": true, 13 | "pretty": true, 14 | "newLine": "lf", 15 | "esModuleInterop": true, 16 | "moduleResolution": "node", 17 | "outDir": "dist", 18 | "rootDir": "." 19 | }, 20 | "include": ["lib", "lib/agent/common/clients/.ts"], 21 | "exclude": ["node_modules", "**/*.spec.ts"] 22 | } 23 | --------------------------------------------------------------------------------