diff --git a/lib/addresses.ts b/lib/addresses.ts index 4eb8a5f38..180ba344f 100644 --- a/lib/addresses.ts +++ b/lib/addresses.ts @@ -9,4 +9,28 @@ export const addresses = { sTokens: '0x0000000000000000000000000000000000000000', }, }, + arbitrumOne: { + main: { + token: '0x0000000000000000000000000000000000000000', + lockup: '0x0000000000000000000000000000000000000000', + marketFactory: '0x0000000000000000000000000000000000000000', + metricsFactory: '0x0000000000000000000000000000000000000000', + policyFactory: '0x0000000000000000000000000000000000000000', + propertyFactory: '0x0000000000000000000000000000000000000000', + registry: '0x0000000000000000000000000000000000000000', + sTokens: '0x0000000000000000000000000000000000000000', + withdraw: '0x0000000000000000000000000000000000000000', + }, + rinkeby: { + token: '0x0000000000000000000000000000000000000000', + lockup: '0x0000000000000000000000000000000000000000', + marketFactory: '0x0000000000000000000000000000000000000000', + metricsFactory: '0x0000000000000000000000000000000000000000', + policyFactory: '0x0000000000000000000000000000000000000000', + propertyFactory: '0x0000000000000000000000000000000000000000', + registry: '0x0000000000000000000000000000000000000000', + sTokens: '0x0000000000000000000000000000000000000000', + withdraw: '0x0000000000000000000000000000000000000000', + }, + }, } as const diff --git a/lib/option.ts b/lib/common/option.ts similarity index 100% rename from lib/option.ts rename to lib/common/option.ts diff --git a/lib/utils/arrayify.spec.ts b/lib/common/utils/arrayify.spec.ts similarity index 100% rename from lib/utils/arrayify.spec.ts rename to lib/common/utils/arrayify.spec.ts diff --git a/lib/utils/arrayify.ts b/lib/common/utils/arrayify.ts similarity index 100% rename from lib/utils/arrayify.ts rename to lib/common/utils/arrayify.ts diff --git a/lib/utils/const.ts b/lib/common/utils/const.ts similarity index 100% rename from lib/utils/const.ts rename to lib/common/utils/const.ts diff --git a/lib/utils/execute.spec.ts b/lib/common/utils/execute.spec.ts similarity index 100% rename from lib/utils/execute.spec.ts rename to lib/common/utils/execute.spec.ts diff --git a/lib/utils/execute.ts b/lib/common/utils/execute.ts similarity index 100% rename from lib/utils/execute.ts rename to lib/common/utils/execute.ts diff --git a/lib/utils/for-test.ts b/lib/common/utils/for-test.ts similarity index 100% rename from lib/utils/for-test.ts rename to lib/common/utils/for-test.ts diff --git a/lib/utils/getAccount.spec.ts b/lib/common/utils/getAccount.spec.ts similarity index 100% rename from lib/utils/getAccount.spec.ts rename to lib/common/utils/getAccount.spec.ts diff --git a/lib/utils/getAccount.ts b/lib/common/utils/getAccount.ts similarity index 100% rename from lib/utils/getAccount.ts rename to lib/common/utils/getAccount.ts diff --git a/lib/utils/index.spec.ts b/lib/common/utils/index.spec.ts similarity index 100% rename from lib/utils/index.spec.ts rename to lib/common/utils/index.spec.ts diff --git a/lib/utils/index.ts b/lib/common/utils/index.ts similarity index 100% rename from lib/utils/index.ts rename to lib/common/utils/index.ts diff --git a/lib/utils/txPromisify.spec.ts b/lib/common/utils/txPromisify.spec.ts similarity index 100% rename from lib/utils/txPromisify.spec.ts rename to lib/common/utils/txPromisify.spec.ts diff --git a/lib/utils/txPromisify.ts b/lib/common/utils/txPromisify.ts similarity index 100% rename from lib/utils/txPromisify.ts rename to lib/common/utils/txPromisify.ts diff --git a/lib/utils/waitForCreateMetrics.spec.ts b/lib/common/utils/waitForCreateMetrics.spec.ts similarity index 100% rename from lib/utils/waitForCreateMetrics.spec.ts rename to lib/common/utils/waitForCreateMetrics.spec.ts diff --git a/lib/utils/waitForCreateMetrics.ts b/lib/common/utils/waitForCreateMetrics.ts similarity index 60% rename from lib/utils/waitForCreateMetrics.ts rename to lib/common/utils/waitForCreateMetrics.ts index 3ff59f1ec..afb7a0049 100644 --- a/lib/utils/waitForCreateMetrics.ts +++ b/lib/common/utils/waitForCreateMetrics.ts @@ -1,10 +1,51 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import Web3 from 'web3' -import { metricsFactoryAbi } from '../metrics-factory/abi' -import { metricsAbi } from '../metrics/abi' -import { watchEvent } from '../utils/watchEvent' +import { AbiItem } from 'web3-utils' +import { watchEvent } from '../../common/utils/watchEvent' import { execute } from './execute' +const metricsFactoryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_market', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_metrics', + type: 'address', + }, + ], + name: 'Create', + type: 'event', + }, +] as readonly AbiItem[] +const metricsAbi = [ + { + inputs: [], + name: 'property', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] const getMetricsProperty = async ( address: string, client: Web3 diff --git a/lib/utils/watchEvent.spec.ts b/lib/common/utils/watchEvent.spec.ts similarity index 100% rename from lib/utils/watchEvent.spec.ts rename to lib/common/utils/watchEvent.spec.ts diff --git a/lib/utils/watchEvent.ts b/lib/common/utils/watchEvent.ts similarity index 100% rename from lib/utils/watchEvent.ts rename to lib/common/utils/watchEvent.ts diff --git a/lib/utils/web3-txs.ts b/lib/common/utils/web3-txs.ts similarity index 100% rename from lib/utils/web3-txs.ts rename to lib/common/utils/web3-txs.ts diff --git a/lib/allocator/abi.ts b/lib/ethereum/allocator/abi.ts similarity index 100% rename from lib/allocator/abi.ts rename to lib/ethereum/allocator/abi.ts diff --git a/lib/allocator/calculateMaxRewardsPerBlock.spec.ts b/lib/ethereum/allocator/calculateMaxRewardsPerBlock.spec.ts similarity index 100% rename from lib/allocator/calculateMaxRewardsPerBlock.spec.ts rename to lib/ethereum/allocator/calculateMaxRewardsPerBlock.spec.ts diff --git a/lib/allocator/calculateMaxRewardsPerBlock.ts b/lib/ethereum/allocator/calculateMaxRewardsPerBlock.ts similarity index 89% rename from lib/allocator/calculateMaxRewardsPerBlock.ts rename to lib/ethereum/allocator/calculateMaxRewardsPerBlock.ts index 92ac5d9dc..ab6de8733 100644 --- a/lib/allocator/calculateMaxRewardsPerBlock.ts +++ b/lib/ethereum/allocator/calculateMaxRewardsPerBlock.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateCalculateMaxRewardsPerBlockCaller = ( diff --git a/lib/allocator/index.spec.ts b/lib/ethereum/allocator/index.spec.ts similarity index 95% rename from lib/allocator/index.spec.ts rename to lib/ethereum/allocator/index.spec.ts index d9190bb4c..1f4bc4765 100644 --- a/lib/allocator/index.spec.ts +++ b/lib/ethereum/allocator/index.spec.ts @@ -1,5 +1,5 @@ import Web3 from 'web3' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createAllocatorContract, CreateAllocatorContract } from '.' import { createCalculateMaxRewardsPerBlockCaller } from './calculateMaxRewardsPerBlock' import { allocatorAbi } from './abi' diff --git a/lib/allocator/index.ts b/lib/ethereum/allocator/index.ts similarity index 94% rename from lib/allocator/index.ts rename to lib/ethereum/allocator/index.ts index 27432d913..7a13ef5e4 100644 --- a/lib/allocator/index.ts +++ b/lib/ethereum/allocator/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { allocatorAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCalculateMaxRewardsPerBlockCaller } from './calculateMaxRewardsPerBlock' import { always } from 'ramda' diff --git a/lib/client/createDetectSTokens.spec.ts b/lib/ethereum/client/createDetectSTokens.spec.ts similarity index 100% rename from lib/client/createDetectSTokens.spec.ts rename to lib/ethereum/client/createDetectSTokens.spec.ts diff --git a/lib/client/createDetectSTokens.ts b/lib/ethereum/client/createDetectSTokens.ts similarity index 100% rename from lib/client/createDetectSTokens.ts rename to lib/ethereum/client/createDetectSTokens.ts diff --git a/lib/client/getStats.spec.ts b/lib/ethereum/client/getStats.spec.ts similarity index 100% rename from lib/client/getStats.spec.ts rename to lib/ethereum/client/getStats.spec.ts diff --git a/lib/client/getStats.ts b/lib/ethereum/client/getStats.ts similarity index 98% rename from lib/client/getStats.ts rename to lib/ethereum/client/getStats.ts index 04f9ed429..837f6493b 100644 --- a/lib/client/getStats.ts +++ b/lib/ethereum/client/getStats.ts @@ -3,9 +3,9 @@ import bent from 'bent' import BigNumber from 'bignumber.js' import Web3 from 'web3' import { always } from 'ramda' -import { addresses } from '../addresses' +import { addresses } from '../../addresses' import { createDevkitContract, DevkitContract } from '../contract' -import { DEV_GRAPHQL_ENDPOINT } from '../utils/const' +import { DEV_GRAPHQL_ENDPOINT } from '../../common/utils/const' const THEGRAPH_UNISWAP_ENDPOINT = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2' diff --git a/lib/client/getVotablePolicy.spec.ts b/lib/ethereum/client/getVotablePolicy.spec.ts similarity index 100% rename from lib/client/getVotablePolicy.spec.ts rename to lib/ethereum/client/getVotablePolicy.spec.ts diff --git a/lib/client/getVotablePolicy.ts b/lib/ethereum/client/getVotablePolicy.ts similarity index 95% rename from lib/client/getVotablePolicy.ts rename to lib/ethereum/client/getVotablePolicy.ts index 651c58de5..55195e170 100644 --- a/lib/client/getVotablePolicy.ts +++ b/lib/ethereum/client/getVotablePolicy.ts @@ -2,7 +2,7 @@ import bent from 'bent' import { always, not } from 'ramda' import { aFindIndex } from 'async-ray' import { PolicyGroupContract } from '../policy-group' -import { DEV_GRAPHQL_ENDPOINT } from '../utils/const' +import { DEV_GRAPHQL_ENDPOINT } from '../../common/utils/const' export type CreateGetVotablePolicyCaller = ( policyGroup: PolicyGroupContract diff --git a/lib/client/index.spec.ts b/lib/ethereum/client/index.spec.ts similarity index 100% rename from lib/client/index.spec.ts rename to lib/ethereum/client/index.spec.ts diff --git a/lib/client/index.ts b/lib/ethereum/client/index.ts similarity index 100% rename from lib/client/index.ts rename to lib/ethereum/client/index.ts diff --git a/lib/contract.spec.ts b/lib/ethereum/contract.spec.ts similarity index 100% rename from lib/contract.spec.ts rename to lib/ethereum/contract.spec.ts diff --git a/lib/contract.ts b/lib/ethereum/contract.ts similarity index 100% rename from lib/contract.ts rename to lib/ethereum/contract.ts diff --git a/lib/dev/abi.ts b/lib/ethereum/dev/abi.ts similarity index 100% rename from lib/dev/abi.ts rename to lib/ethereum/dev/abi.ts diff --git a/lib/dev/deposit.spec.ts b/lib/ethereum/dev/deposit.spec.ts similarity index 95% rename from lib/dev/deposit.spec.ts rename to lib/ethereum/dev/deposit.spec.ts index 62c99aea4..305365200 100644 --- a/lib/dev/deposit.spec.ts +++ b/lib/ethereum/dev/deposit.spec.ts @@ -1,5 +1,5 @@ import { createDepositCaller } from './deposit' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('deposit.spec.ts', () => { describe('createDepositCaller', () => { diff --git a/lib/dev/deposit.ts b/lib/ethereum/dev/deposit.ts similarity index 91% rename from lib/dev/deposit.ts rename to lib/ethereum/dev/deposit.ts index 80bf9b1c0..43753c015 100644 --- a/lib/dev/deposit.ts +++ b/lib/ethereum/dev/deposit.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateDepositCaller = ( diff --git a/lib/dev/index.spec.ts b/lib/ethereum/dev/index.spec.ts similarity index 97% rename from lib/dev/index.spec.ts rename to lib/ethereum/dev/index.spec.ts index 71b71f1a0..ff4bd9023 100644 --- a/lib/dev/index.spec.ts +++ b/lib/ethereum/dev/index.spec.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { createDevContract, DevContract } from '.' import { createTransferCaller } from './../erc20/transfer' import { devAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createDepositCaller } from './deposit' import { createBalanceOfCaller } from './../erc20/balanceOf' import { createTotalSupplyCaller } from './../erc20/totalSupply' diff --git a/lib/dev/index.ts b/lib/ethereum/dev/index.ts similarity index 97% rename from lib/dev/index.ts rename to lib/ethereum/dev/index.ts index cf0dae9f0..c0511c8bd 100644 --- a/lib/dev/index.ts +++ b/lib/ethereum/dev/index.ts @@ -3,7 +3,7 @@ import Web3 from 'web3' import { always } from 'ramda' import { Contract } from 'web3-eth-contract/types' import { devAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createTransferCaller } from './../erc20/transfer' import { createBalanceOfCaller } from './../erc20/balanceOf' import { createTotalSupplyCaller } from './../erc20/totalSupply' diff --git a/lib/erc20/allowance.spec.ts b/lib/ethereum/erc20/allowance.spec.ts similarity index 100% rename from lib/erc20/allowance.spec.ts rename to lib/ethereum/erc20/allowance.spec.ts diff --git a/lib/erc20/allowance.ts b/lib/ethereum/erc20/allowance.ts similarity index 89% rename from lib/erc20/allowance.ts rename to lib/ethereum/erc20/allowance.ts index d82a5782a..42027f08d 100644 --- a/lib/erc20/allowance.ts +++ b/lib/ethereum/erc20/allowance.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateAllowanceCaller = ( contract: Contract diff --git a/lib/erc20/approve.spec.ts b/lib/ethereum/erc20/approve.spec.ts similarity index 95% rename from lib/erc20/approve.spec.ts rename to lib/ethereum/erc20/approve.spec.ts index 80c301330..e4f06de04 100644 --- a/lib/erc20/approve.spec.ts +++ b/lib/ethereum/erc20/approve.spec.ts @@ -1,5 +1,5 @@ import { createApproveCaller } from './approve' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('approve.spec.ts', () => { describe('createApproveCaller', () => { diff --git a/lib/erc20/approve.ts b/lib/ethereum/erc20/approve.ts similarity index 91% rename from lib/erc20/approve.ts rename to lib/ethereum/erc20/approve.ts index 25b73f728..705b944c1 100644 --- a/lib/erc20/approve.ts +++ b/lib/ethereum/erc20/approve.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateApproveCaller = ( diff --git a/lib/erc20/balanceOf.spec.ts b/lib/ethereum/erc20/balanceOf.spec.ts similarity index 100% rename from lib/erc20/balanceOf.spec.ts rename to lib/ethereum/erc20/balanceOf.spec.ts diff --git a/lib/erc20/balanceOf.ts b/lib/ethereum/erc20/balanceOf.ts similarity index 88% rename from lib/erc20/balanceOf.ts rename to lib/ethereum/erc20/balanceOf.ts index c995cd03c..6757d60ba 100644 --- a/lib/erc20/balanceOf.ts +++ b/lib/ethereum/erc20/balanceOf.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateBalanceOfCaller = ( contract: Contract diff --git a/lib/erc20/decimals.spec.ts b/lib/ethereum/erc20/decimals.spec.ts similarity index 100% rename from lib/erc20/decimals.spec.ts rename to lib/ethereum/erc20/decimals.spec.ts diff --git a/lib/erc20/decimals.ts b/lib/ethereum/erc20/decimals.ts similarity index 87% rename from lib/erc20/decimals.ts rename to lib/ethereum/erc20/decimals.ts index 8a001a039..7a4c879e4 100644 --- a/lib/erc20/decimals.ts +++ b/lib/ethereum/erc20/decimals.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateDecimalsCaller = (contract: Contract) => () => Promise diff --git a/lib/erc20/name.spec.ts b/lib/ethereum/erc20/name.spec.ts similarity index 100% rename from lib/erc20/name.spec.ts rename to lib/ethereum/erc20/name.spec.ts diff --git a/lib/erc20/name.ts b/lib/ethereum/erc20/name.ts similarity index 86% rename from lib/erc20/name.ts rename to lib/ethereum/erc20/name.ts index 725d52805..c589adae2 100644 --- a/lib/erc20/name.ts +++ b/lib/ethereum/erc20/name.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateNameCaller = (contract: Contract) => () => Promise diff --git a/lib/erc20/symbol.spec.ts b/lib/ethereum/erc20/symbol.spec.ts similarity index 100% rename from lib/erc20/symbol.spec.ts rename to lib/ethereum/erc20/symbol.spec.ts diff --git a/lib/erc20/symbol.ts b/lib/ethereum/erc20/symbol.ts similarity index 87% rename from lib/erc20/symbol.ts rename to lib/ethereum/erc20/symbol.ts index 2ecd37fc7..a5b13f7cd 100644 --- a/lib/erc20/symbol.ts +++ b/lib/ethereum/erc20/symbol.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateSymbolCaller = (contract: Contract) => () => Promise diff --git a/lib/erc20/totalSupply.spec.ts b/lib/ethereum/erc20/totalSupply.spec.ts similarity index 100% rename from lib/erc20/totalSupply.spec.ts rename to lib/ethereum/erc20/totalSupply.spec.ts diff --git a/lib/erc20/totalSupply.ts b/lib/ethereum/erc20/totalSupply.ts similarity index 87% rename from lib/erc20/totalSupply.ts rename to lib/ethereum/erc20/totalSupply.ts index 080214295..e3f253206 100644 --- a/lib/erc20/totalSupply.ts +++ b/lib/ethereum/erc20/totalSupply.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateTotalSupplyCaller = ( diff --git a/lib/erc20/transfer.spec.ts b/lib/ethereum/erc20/transfer.spec.ts similarity index 95% rename from lib/erc20/transfer.spec.ts rename to lib/ethereum/erc20/transfer.spec.ts index 60381b983..c0fda3bb5 100644 --- a/lib/erc20/transfer.spec.ts +++ b/lib/ethereum/erc20/transfer.spec.ts @@ -1,5 +1,5 @@ import { createTransferCaller } from './transfer' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('transfer.spec.ts', () => { describe('createTransferCaller', () => { diff --git a/lib/erc20/transfer.ts b/lib/ethereum/erc20/transfer.ts similarity index 91% rename from lib/erc20/transfer.ts rename to lib/ethereum/erc20/transfer.ts index 86344f254..629dad57a 100644 --- a/lib/erc20/transfer.ts +++ b/lib/ethereum/erc20/transfer.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateTransferCaller = ( diff --git a/lib/erc20/transferFrom.spec.ts b/lib/ethereum/erc20/transferFrom.spec.ts similarity index 95% rename from lib/erc20/transferFrom.spec.ts rename to lib/ethereum/erc20/transferFrom.spec.ts index 72d8668f1..f4a455c12 100644 --- a/lib/erc20/transferFrom.spec.ts +++ b/lib/ethereum/erc20/transferFrom.spec.ts @@ -1,5 +1,5 @@ import { createTransferFromCaller } from './transferFrom' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('transferFrom.spec.ts', () => { describe('createTransferFromCaller', () => { diff --git a/lib/erc20/transferFrom.ts b/lib/ethereum/erc20/transferFrom.ts similarity index 91% rename from lib/erc20/transferFrom.ts rename to lib/ethereum/erc20/transferFrom.ts index 95ec8369f..ceee64677 100644 --- a/lib/erc20/transferFrom.ts +++ b/lib/ethereum/erc20/transferFrom.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateTransferFromCaller = ( diff --git a/lib/lockup/abi.ts b/lib/ethereum/lockup/abi.ts similarity index 100% rename from lib/lockup/abi.ts rename to lib/ethereum/lockup/abi.ts diff --git a/lib/lockup/calculateCumulativeHoldersRewardAmount.spec.ts b/lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.spec.ts similarity index 100% rename from lib/lockup/calculateCumulativeHoldersRewardAmount.spec.ts rename to lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.spec.ts diff --git a/lib/lockup/calculateCumulativeHoldersRewardAmount.ts b/lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.ts similarity index 91% rename from lib/lockup/calculateCumulativeHoldersRewardAmount.ts rename to lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.ts index 8f7f5da4c..cb98cc02f 100644 --- a/lib/lockup/calculateCumulativeHoldersRewardAmount.ts +++ b/lib/ethereum/lockup/calculateCumulativeHoldersRewardAmount.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateCalculateCumulativeHoldersRewardAmountCaller = ( contract: Contract diff --git a/lib/lockup/calculateCumulativeRewardPrices.spec.ts b/lib/ethereum/lockup/calculateCumulativeRewardPrices.spec.ts similarity index 100% rename from lib/lockup/calculateCumulativeRewardPrices.spec.ts rename to lib/ethereum/lockup/calculateCumulativeRewardPrices.spec.ts diff --git a/lib/lockup/calculateCumulativeRewardPrices.ts b/lib/ethereum/lockup/calculateCumulativeRewardPrices.ts similarity index 85% rename from lib/lockup/calculateCumulativeRewardPrices.ts rename to lib/ethereum/lockup/calculateCumulativeRewardPrices.ts index 0d944909d..bb98bd19b 100644 --- a/lib/lockup/calculateCumulativeRewardPrices.ts +++ b/lib/ethereum/lockup/calculateCumulativeRewardPrices.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' -import { arrayify } from '../utils/arrayify' +import { arrayify } from '../../common/utils/arrayify' export type CreateCalculateCumulativeRewardPricesCaller = ( contract: Contract diff --git a/lib/lockup/calculateRewardAmount.spec.ts b/lib/ethereum/lockup/calculateRewardAmount.spec.ts similarity index 100% rename from lib/lockup/calculateRewardAmount.spec.ts rename to lib/ethereum/lockup/calculateRewardAmount.spec.ts diff --git a/lib/lockup/calculateRewardAmount.ts b/lib/ethereum/lockup/calculateRewardAmount.ts similarity index 84% rename from lib/lockup/calculateRewardAmount.ts rename to lib/ethereum/lockup/calculateRewardAmount.ts index fb5e0ecb9..9292ab874 100644 --- a/lib/lockup/calculateRewardAmount.ts +++ b/lib/ethereum/lockup/calculateRewardAmount.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { arrayify } from '../utils/arrayify' -import { execute } from '../utils/execute' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' export type CreateCalculateRewardAmountCaller = ( contract: Contract diff --git a/lib/lockup/calculateWithdrawableInterestAmount.spec.ts b/lib/ethereum/lockup/calculateWithdrawableInterestAmount.spec.ts similarity index 100% rename from lib/lockup/calculateWithdrawableInterestAmount.spec.ts rename to lib/ethereum/lockup/calculateWithdrawableInterestAmount.spec.ts diff --git a/lib/lockup/calculateWithdrawableInterestAmount.ts b/lib/ethereum/lockup/calculateWithdrawableInterestAmount.ts similarity index 91% rename from lib/lockup/calculateWithdrawableInterestAmount.ts rename to lib/ethereum/lockup/calculateWithdrawableInterestAmount.ts index 699a908f2..f8d9211a7 100644 --- a/lib/lockup/calculateWithdrawableInterestAmount.ts +++ b/lib/ethereum/lockup/calculateWithdrawableInterestAmount.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateCalculateWithdrawableInterestAmountCaller = ( contract: Contract diff --git a/lib/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts b/lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts similarity index 100% rename from lib/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts rename to lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts diff --git a/lib/lockup/calculateWithdrawableInterestAmountByPosition.ts b/lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.ts similarity index 91% rename from lib/lockup/calculateWithdrawableInterestAmountByPosition.ts rename to lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.ts index 6719a4aa2..a084fc460 100644 --- a/lib/lockup/calculateWithdrawableInterestAmountByPosition.ts +++ b/lib/ethereum/lockup/calculateWithdrawableInterestAmountByPosition.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreatecalculateWithdrawableInterestAmountByPositionCaller = ( contract: Contract diff --git a/lib/lockup/cap.spec.ts b/lib/ethereum/lockup/cap.spec.ts similarity index 100% rename from lib/lockup/cap.spec.ts rename to lib/ethereum/lockup/cap.spec.ts diff --git a/lib/lockup/cap.ts b/lib/ethereum/lockup/cap.ts similarity index 86% rename from lib/lockup/cap.ts rename to lib/ethereum/lockup/cap.ts index 552231364..fa4981f3e 100644 --- a/lib/lockup/cap.ts +++ b/lib/ethereum/lockup/cap.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateCapCaller = (contract: Contract) => () => Promise diff --git a/lib/lockup/depositToPosition.spec.ts b/lib/ethereum/lockup/depositToPosition.spec.ts similarity index 94% rename from lib/lockup/depositToPosition.spec.ts rename to lib/ethereum/lockup/depositToPosition.spec.ts index 8305470fd..7d17fd8c4 100644 --- a/lib/lockup/depositToPosition.spec.ts +++ b/lib/ethereum/lockup/depositToPosition.spec.ts @@ -1,5 +1,5 @@ import { createDepositToPositionCaller } from './depositToPosition' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('depositToPosition.spec.ts', () => { describe('createDepositToPositionCaller', () => { diff --git a/lib/lockup/depositToPosition.ts b/lib/ethereum/lockup/depositToPosition.ts similarity index 92% rename from lib/lockup/depositToPosition.ts rename to lib/ethereum/lockup/depositToPosition.ts index 80195ce79..bc912249f 100644 --- a/lib/lockup/depositToPosition.ts +++ b/lib/ethereum/lockup/depositToPosition.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateDepositToPositionCaller = ( diff --git a/lib/lockup/depositToProperty.spec.ts b/lib/ethereum/lockup/depositToProperty.spec.ts similarity index 95% rename from lib/lockup/depositToProperty.spec.ts rename to lib/ethereum/lockup/depositToProperty.spec.ts index 68fef323d..db4d0a32f 100644 --- a/lib/lockup/depositToProperty.spec.ts +++ b/lib/ethereum/lockup/depositToProperty.spec.ts @@ -1,5 +1,5 @@ import { createDepositToPropertyCaller } from './depositToProperty' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('depositToProperty.spec.ts', () => { describe('createDepositToPropertyCaller', () => { diff --git a/lib/lockup/depositToProperty.ts b/lib/ethereum/lockup/depositToProperty.ts similarity index 92% rename from lib/lockup/depositToProperty.ts rename to lib/ethereum/lockup/depositToProperty.ts index e21051373..666a2ad99 100644 --- a/lib/lockup/depositToProperty.ts +++ b/lib/ethereum/lockup/depositToProperty.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateDepositToPropertyCaller = ( diff --git a/lib/lockup/getAllValue.spec.ts b/lib/ethereum/lockup/getAllValue.spec.ts similarity index 100% rename from lib/lockup/getAllValue.spec.ts rename to lib/ethereum/lockup/getAllValue.spec.ts diff --git a/lib/lockup/getAllValue.ts b/lib/ethereum/lockup/getAllValue.ts similarity index 87% rename from lib/lockup/getAllValue.ts rename to lib/ethereum/lockup/getAllValue.ts index f7f060a81..9dfec9264 100644 --- a/lib/lockup/getAllValue.ts +++ b/lib/ethereum/lockup/getAllValue.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateGetAllValueCaller = ( diff --git a/lib/lockup/getPropertyValue.spec.ts b/lib/ethereum/lockup/getPropertyValue.spec.ts similarity index 100% rename from lib/lockup/getPropertyValue.spec.ts rename to lib/ethereum/lockup/getPropertyValue.spec.ts diff --git a/lib/lockup/getPropertyValue.ts b/lib/ethereum/lockup/getPropertyValue.ts similarity index 88% rename from lib/lockup/getPropertyValue.ts rename to lib/ethereum/lockup/getPropertyValue.ts index 7bc9dd8fd..065e460e9 100644 --- a/lib/lockup/getPropertyValue.ts +++ b/lib/ethereum/lockup/getPropertyValue.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateGetPropertyValueCaller = ( contract: Contract diff --git a/lib/lockup/getStorageWithdrawalStatus.spec.ts b/lib/ethereum/lockup/getStorageWithdrawalStatus.spec.ts similarity index 100% rename from lib/lockup/getStorageWithdrawalStatus.spec.ts rename to lib/ethereum/lockup/getStorageWithdrawalStatus.spec.ts diff --git a/lib/lockup/getStorageWithdrawalStatus.ts b/lib/ethereum/lockup/getStorageWithdrawalStatus.ts similarity index 91% rename from lib/lockup/getStorageWithdrawalStatus.ts rename to lib/ethereum/lockup/getStorageWithdrawalStatus.ts index 127ae381b..a7af43073 100644 --- a/lib/lockup/getStorageWithdrawalStatus.ts +++ b/lib/ethereum/lockup/getStorageWithdrawalStatus.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateGetStorageWithdrawalStatusCaller = ( contract: Contract diff --git a/lib/lockup/getValue.spec.ts b/lib/ethereum/lockup/getValue.spec.ts similarity index 100% rename from lib/lockup/getValue.spec.ts rename to lib/ethereum/lockup/getValue.spec.ts diff --git a/lib/lockup/getValue.ts b/lib/ethereum/lockup/getValue.ts similarity index 90% rename from lib/lockup/getValue.ts rename to lib/ethereum/lockup/getValue.ts index 916e1e036..ca0c51064 100644 --- a/lib/lockup/getValue.ts +++ b/lib/ethereum/lockup/getValue.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateGetValueCaller = ( contract: Contract diff --git a/lib/lockup/index.spec.ts b/lib/ethereum/lockup/index.spec.ts similarity index 98% rename from lib/lockup/index.spec.ts rename to lib/ethereum/lockup/index.spec.ts index f1002c188..1b224ba07 100644 --- a/lib/lockup/index.spec.ts +++ b/lib/ethereum/lockup/index.spec.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { createLockupContract, LockupContract } from '.' import { createGetValueCaller } from './getValue' import { lockupAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createGetPropertyValueCaller } from './getPropertyValue' import { createWithdrawCaller } from './withdraw' import { createCalculateWithdrawableInterestAmountCaller } from './calculateWithdrawableInterestAmount' diff --git a/lib/lockup/index.ts b/lib/ethereum/lockup/index.ts similarity index 98% rename from lib/lockup/index.ts rename to lib/ethereum/lockup/index.ts index a967731ce..80c2982fe 100644 --- a/lib/lockup/index.ts +++ b/lib/ethereum/lockup/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { lockupAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createGetValueCaller } from './getValue' import { createGetPropertyValueCaller } from './getPropertyValue' import { createWithdrawCaller } from './withdraw' diff --git a/lib/lockup/migrateToSTokens.spec.ts b/lib/ethereum/lockup/migrateToSTokens.spec.ts similarity index 94% rename from lib/lockup/migrateToSTokens.spec.ts rename to lib/ethereum/lockup/migrateToSTokens.spec.ts index 0b82dd4a8..0540cc890 100644 --- a/lib/lockup/migrateToSTokens.spec.ts +++ b/lib/ethereum/lockup/migrateToSTokens.spec.ts @@ -1,5 +1,5 @@ import { createMigrateToSTokensCaller } from './migrateToSTokens' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('migrateToSTokens.spec.ts', () => { describe('createMigrateToSTokensCaller', () => { diff --git a/lib/lockup/migrateToSTokens.ts b/lib/ethereum/lockup/migrateToSTokens.ts similarity index 91% rename from lib/lockup/migrateToSTokens.ts rename to lib/ethereum/lockup/migrateToSTokens.ts index 96d65bb87..f093e2c4e 100644 --- a/lib/lockup/migrateToSTokens.ts +++ b/lib/ethereum/lockup/migrateToSTokens.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateMigrateToSTokensCaller = ( diff --git a/lib/lockup/withdraw.spec.ts b/lib/ethereum/lockup/withdraw.spec.ts similarity index 94% rename from lib/lockup/withdraw.spec.ts rename to lib/ethereum/lockup/withdraw.spec.ts index d04448c2d..fbe616e9a 100644 --- a/lib/lockup/withdraw.spec.ts +++ b/lib/ethereum/lockup/withdraw.spec.ts @@ -1,5 +1,5 @@ import { createWithdrawCaller } from './withdraw' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('withdraw.spec.ts', () => { describe('createWithdrawCaller', () => { diff --git a/lib/lockup/withdraw.ts b/lib/ethereum/lockup/withdraw.ts similarity index 91% rename from lib/lockup/withdraw.ts rename to lib/ethereum/lockup/withdraw.ts index 2aaf3c485..ec28856ea 100644 --- a/lib/lockup/withdraw.ts +++ b/lib/ethereum/lockup/withdraw.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateWithdrawCaller = ( diff --git a/lib/lockup/withdrawByPosition.spec.ts b/lib/ethereum/lockup/withdrawByPosition.spec.ts similarity index 94% rename from lib/lockup/withdrawByPosition.spec.ts rename to lib/ethereum/lockup/withdrawByPosition.spec.ts index 05276b53e..f84839be3 100644 --- a/lib/lockup/withdrawByPosition.spec.ts +++ b/lib/ethereum/lockup/withdrawByPosition.spec.ts @@ -1,5 +1,5 @@ import { createWithdrawByPositionCaller } from './withdrawByPosition' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('withdrawByPosition.spec.ts', () => { describe('createWithdrawByPositionCaller', () => { diff --git a/lib/lockup/withdrawByPosition.ts b/lib/ethereum/lockup/withdrawByPosition.ts similarity index 92% rename from lib/lockup/withdrawByPosition.ts rename to lib/ethereum/lockup/withdrawByPosition.ts index 05d01e60c..21c1b38a2 100644 --- a/lib/lockup/withdrawByPosition.ts +++ b/lib/ethereum/lockup/withdrawByPosition.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateWithdrawByPositionCaller = ( diff --git a/lib/market-factory/abi.ts b/lib/ethereum/market-factory/abi.ts similarity index 100% rename from lib/market-factory/abi.ts rename to lib/ethereum/market-factory/abi.ts diff --git a/lib/market-factory/create.spec.ts b/lib/ethereum/market-factory/create.spec.ts similarity index 94% rename from lib/market-factory/create.spec.ts rename to lib/ethereum/market-factory/create.spec.ts index 632cc0558..6b36a5ef5 100644 --- a/lib/market-factory/create.spec.ts +++ b/lib/ethereum/market-factory/create.spec.ts @@ -1,5 +1,5 @@ import { createCreateCaller } from './create' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('create.spec.ts', () => { describe('createCreateCaller', () => { diff --git a/lib/market-factory/create.ts b/lib/ethereum/market-factory/create.ts similarity index 91% rename from lib/market-factory/create.ts rename to lib/ethereum/market-factory/create.ts index 49b029c9e..2f20c6669 100644 --- a/lib/market-factory/create.ts +++ b/lib/ethereum/market-factory/create.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateCreateCaller = ( diff --git a/lib/market-factory/index.spec.ts b/lib/ethereum/market-factory/index.spec.ts similarity index 95% rename from lib/market-factory/index.spec.ts rename to lib/ethereum/market-factory/index.spec.ts index 984f4690c..e83ba6421 100644 --- a/lib/market-factory/index.spec.ts +++ b/lib/ethereum/market-factory/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createMarketFactoryContract, MarketFactoryContract } from '.' import { marketFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCreateCaller } from './create' describe('market-factory/index.ts', () => { diff --git a/lib/market-factory/index.ts b/lib/ethereum/market-factory/index.ts similarity index 94% rename from lib/market-factory/index.ts rename to lib/ethereum/market-factory/index.ts index 8b9e3e976..0a70bd2d3 100644 --- a/lib/market-factory/index.ts +++ b/lib/ethereum/market-factory/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { marketFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCreateCaller } from './create' import { always } from 'ramda' diff --git a/lib/market/abi.ts b/lib/ethereum/market/abi.ts similarity index 100% rename from lib/market/abi.ts rename to lib/ethereum/market/abi.ts diff --git a/lib/market/authenticate.spec.ts b/lib/ethereum/market/authenticate.spec.ts similarity index 97% rename from lib/market/authenticate.spec.ts rename to lib/ethereum/market/authenticate.spec.ts index a2d60349d..7f52840cd 100644 --- a/lib/market/authenticate.spec.ts +++ b/lib/ethereum/market/authenticate.spec.ts @@ -7,8 +7,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { createAuthenticateCaller } from './authenticate' -import { stubbedWeb3 } from '../utils/for-test' -import { Event } from '../utils/web3-txs' +import { stubbedWeb3 } from '../../common/utils/for-test' +import { Event } from '../../common/utils/web3-txs' import Web3 from 'web3' import { marketAbi } from './abi' diff --git a/lib/market/authenticate.ts b/lib/ethereum/market/authenticate.ts similarity index 89% rename from lib/market/authenticate.ts rename to lib/ethereum/market/authenticate.ts index ac7786a4c..f51ed7ff5 100644 --- a/lib/market/authenticate.ts +++ b/lib/ethereum/market/authenticate.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' -import { waitForCreateMetrics } from '../utils/waitForCreateMetrics' +import { execute } from '../../common/utils/execute' +import { waitForCreateMetrics } from '../../common/utils/waitForCreateMetrics' export type WaitForEventOptions = { readonly metricsFactory: string diff --git a/lib/market/behavior.spec.ts b/lib/ethereum/market/behavior.spec.ts similarity index 100% rename from lib/market/behavior.spec.ts rename to lib/ethereum/market/behavior.spec.ts diff --git a/lib/market/behavior.ts b/lib/ethereum/market/behavior.ts similarity index 87% rename from lib/market/behavior.ts rename to lib/ethereum/market/behavior.ts index 7e0566609..f4c88ff34 100644 --- a/lib/market/behavior.ts +++ b/lib/ethereum/market/behavior.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateBehaviorCaller = (contract: Contract) => () => Promise diff --git a/lib/market/index.spec.ts b/lib/ethereum/market/index.spec.ts similarity index 96% rename from lib/market/index.spec.ts rename to lib/ethereum/market/index.spec.ts index e1c0faebe..e20aae569 100644 --- a/lib/market/index.spec.ts +++ b/lib/ethereum/market/index.spec.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { createMarketContract, CreateMarketContract } from '.' import { createSchemaCaller } from './schema' import { createVoteCaller } from './vote' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { marketAbi } from './abi' import { createAuthenticateCaller } from './authenticate' import { createBehaviorCaller } from './behavior' diff --git a/lib/market/index.ts b/lib/ethereum/market/index.ts similarity index 92% rename from lib/market/index.ts rename to lib/ethereum/market/index.ts index f25a98931..9ee6bfa63 100644 --- a/lib/market/index.ts +++ b/lib/ethereum/market/index.ts @@ -1,12 +1,12 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { marketAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createSchemaCaller } from './schema' import { createVoteCaller } from './vote' import { createBehaviorCaller } from './behavior' import { createAuthenticateCaller } from './authenticate' -import { TxReceipt } from '../utils/web3-txs' +import { TxReceipt } from '../../common/utils/web3-txs' import { always } from 'ramda' export type CreateMarketContract = { diff --git a/lib/market/schema.spec.ts b/lib/ethereum/market/schema.spec.ts similarity index 100% rename from lib/market/schema.spec.ts rename to lib/ethereum/market/schema.spec.ts diff --git a/lib/market/schema.ts b/lib/ethereum/market/schema.ts similarity index 93% rename from lib/market/schema.ts rename to lib/ethereum/market/schema.ts index 7101d619a..6ecebcbcd 100644 --- a/lib/market/schema.ts +++ b/lib/ethereum/market/schema.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateSchemaCaller = ( diff --git a/lib/market/vote.spec.ts b/lib/ethereum/market/vote.spec.ts similarity index 91% rename from lib/market/vote.spec.ts rename to lib/ethereum/market/vote.spec.ts index eb15786d7..26b58f16b 100644 --- a/lib/market/vote.spec.ts +++ b/lib/ethereum/market/vote.spec.ts @@ -1,6 +1,6 @@ import { createVoteCaller } from './vote' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' -import { txPromisify } from '../utils/txPromisify' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' +import { txPromisify } from '../../common/utils/txPromisify' describe('vote.ts', () => { describe('createVoteCaller', () => { diff --git a/lib/market/vote.ts b/lib/ethereum/market/vote.ts similarity index 85% rename from lib/market/vote.ts rename to lib/ethereum/market/vote.ts index 3299a4e08..5e35d7f8e 100644 --- a/lib/market/vote.ts +++ b/lib/ethereum/market/vote.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' -import { TxReceipt } from '../utils/web3-txs' +import { execute } from '../../common/utils/execute' +import { TxReceipt } from '../../common/utils/web3-txs' export type CreateVoteCaller = ( contract: Contract, diff --git a/lib/metrics-factory/abi.ts b/lib/ethereum/metrics-factory/abi.ts similarity index 100% rename from lib/metrics-factory/abi.ts rename to lib/ethereum/metrics-factory/abi.ts diff --git a/lib/metrics-group/abi.ts b/lib/ethereum/metrics-group/abi.ts similarity index 100% rename from lib/metrics-group/abi.ts rename to lib/ethereum/metrics-group/abi.ts diff --git a/lib/metrics-group/index.spec.ts b/lib/ethereum/metrics-group/index.spec.ts similarity index 96% rename from lib/metrics-group/index.spec.ts rename to lib/ethereum/metrics-group/index.spec.ts index 3acb033b9..981301d2e 100644 --- a/lib/metrics-group/index.spec.ts +++ b/lib/ethereum/metrics-group/index.spec.ts @@ -1,6 +1,6 @@ import Web3 from 'web3' import { createMetricsGroupContract, CreateMetricsGroupContract } from '.' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { metricsGroupAbi } from './abi' import { createTotalAuthenticatedPropertiesCaller } from './totalAuthenticatedProperties' diff --git a/lib/metrics-group/index.ts b/lib/ethereum/metrics-group/index.ts similarity index 94% rename from lib/metrics-group/index.ts rename to lib/ethereum/metrics-group/index.ts index 97847a7c8..0b33f9884 100644 --- a/lib/metrics-group/index.ts +++ b/lib/ethereum/metrics-group/index.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { metricsGroupAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createTotalAuthenticatedPropertiesCaller } from './totalAuthenticatedProperties' import { always } from 'ramda' diff --git a/lib/metrics-group/totalAuthenticatedProperties.spec.ts b/lib/ethereum/metrics-group/totalAuthenticatedProperties.spec.ts similarity index 100% rename from lib/metrics-group/totalAuthenticatedProperties.spec.ts rename to lib/ethereum/metrics-group/totalAuthenticatedProperties.spec.ts diff --git a/lib/metrics-group/totalAuthenticatedProperties.ts b/lib/ethereum/metrics-group/totalAuthenticatedProperties.ts similarity index 89% rename from lib/metrics-group/totalAuthenticatedProperties.ts rename to lib/ethereum/metrics-group/totalAuthenticatedProperties.ts index a8d987880..bee4e3010 100644 --- a/lib/metrics-group/totalAuthenticatedProperties.ts +++ b/lib/ethereum/metrics-group/totalAuthenticatedProperties.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateTotalAuthenticatedPropertiesCaller = ( diff --git a/lib/metrics/abi.ts b/lib/ethereum/metrics/abi.ts similarity index 100% rename from lib/metrics/abi.ts rename to lib/ethereum/metrics/abi.ts diff --git a/lib/metrics/index.spec.ts b/lib/ethereum/metrics/index.spec.ts similarity index 95% rename from lib/metrics/index.spec.ts rename to lib/ethereum/metrics/index.spec.ts index ec905dac1..baca64eec 100644 --- a/lib/metrics/index.spec.ts +++ b/lib/ethereum/metrics/index.spec.ts @@ -1,5 +1,5 @@ import Web3 from 'web3' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createMetricsContract, CreateMetricsContract } from '.' import { createPropertyCaller } from './property' import { createMarketCaller } from './market' diff --git a/lib/metrics/index.ts b/lib/ethereum/metrics/index.ts similarity index 94% rename from lib/metrics/index.ts rename to lib/ethereum/metrics/index.ts index 014d81a89..9aa236967 100644 --- a/lib/metrics/index.ts +++ b/lib/ethereum/metrics/index.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { metricsAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createPropertyCaller } from './property' import { createMarketCaller } from './market' import { always } from 'ramda' diff --git a/lib/metrics/market.spec.ts b/lib/ethereum/metrics/market.spec.ts similarity index 100% rename from lib/metrics/market.spec.ts rename to lib/ethereum/metrics/market.spec.ts diff --git a/lib/metrics/market.ts b/lib/ethereum/metrics/market.ts similarity index 87% rename from lib/metrics/market.ts rename to lib/ethereum/metrics/market.ts index 923895bcf..58474e652 100644 --- a/lib/metrics/market.ts +++ b/lib/ethereum/metrics/market.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMarketCaller = (contract: Contract) => () => Promise diff --git a/lib/metrics/property.spec.ts b/lib/ethereum/metrics/property.spec.ts similarity index 100% rename from lib/metrics/property.spec.ts rename to lib/ethereum/metrics/property.spec.ts diff --git a/lib/metrics/property.ts b/lib/ethereum/metrics/property.ts similarity index 87% rename from lib/metrics/property.ts rename to lib/ethereum/metrics/property.ts index f8cd072e5..08699c226 100644 --- a/lib/metrics/property.ts +++ b/lib/ethereum/metrics/property.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePropertyCaller = (contract: Contract) => () => Promise diff --git a/lib/policy-factory/abi.ts b/lib/ethereum/policy-factory/abi.ts similarity index 100% rename from lib/policy-factory/abi.ts rename to lib/ethereum/policy-factory/abi.ts diff --git a/lib/policy-factory/create.spec.ts b/lib/ethereum/policy-factory/create.spec.ts similarity index 94% rename from lib/policy-factory/create.spec.ts rename to lib/ethereum/policy-factory/create.spec.ts index de54c0431..fde629424 100644 --- a/lib/policy-factory/create.spec.ts +++ b/lib/ethereum/policy-factory/create.spec.ts @@ -1,5 +1,5 @@ import { createCreateCaller } from './create' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('deposit.spec.ts', () => { describe('createDepositCaller', () => { diff --git a/lib/policy-factory/create.ts b/lib/ethereum/policy-factory/create.ts similarity index 91% rename from lib/policy-factory/create.ts rename to lib/ethereum/policy-factory/create.ts index eddaa0141..1719b921c 100644 --- a/lib/policy-factory/create.ts +++ b/lib/ethereum/policy-factory/create.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateCreateCaller = ( diff --git a/lib/policy-factory/forceAttach.spec.ts b/lib/ethereum/policy-factory/forceAttach.spec.ts similarity index 94% rename from lib/policy-factory/forceAttach.spec.ts rename to lib/ethereum/policy-factory/forceAttach.spec.ts index c7a00c897..e85ed749c 100644 --- a/lib/policy-factory/forceAttach.spec.ts +++ b/lib/ethereum/policy-factory/forceAttach.spec.ts @@ -1,5 +1,5 @@ import { createForceAttachCaller } from './forceAttach' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('forceAttach.spec.ts', () => { describe('createForceAttachCaller', () => { diff --git a/lib/policy-factory/forceAttach.ts b/lib/ethereum/policy-factory/forceAttach.ts similarity index 90% rename from lib/policy-factory/forceAttach.ts rename to lib/ethereum/policy-factory/forceAttach.ts index 376649236..56d31e81c 100644 --- a/lib/policy-factory/forceAttach.ts +++ b/lib/ethereum/policy-factory/forceAttach.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateForceAttachCaller = ( diff --git a/lib/policy-factory/index.spec.ts b/lib/ethereum/policy-factory/index.spec.ts similarity index 96% rename from lib/policy-factory/index.spec.ts rename to lib/ethereum/policy-factory/index.spec.ts index ab1bcc281..32ef2f070 100644 --- a/lib/policy-factory/index.spec.ts +++ b/lib/ethereum/policy-factory/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createPolicyFactoryContract, PolicyFactoryContract } from '.' import { policyFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCreateCaller } from './create' import { createForceAttachCaller } from './forceAttach' diff --git a/lib/policy-factory/index.ts b/lib/ethereum/policy-factory/index.ts similarity index 95% rename from lib/policy-factory/index.ts rename to lib/ethereum/policy-factory/index.ts index f8f234bbc..9583fafb0 100644 --- a/lib/policy-factory/index.ts +++ b/lib/ethereum/policy-factory/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { policyFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { always } from 'ramda' import { createCreateCaller } from './create' import { createForceAttachCaller } from './forceAttach' diff --git a/lib/policy-group/abi.ts b/lib/ethereum/policy-group/abi.ts similarity index 100% rename from lib/policy-group/abi.ts rename to lib/ethereum/policy-group/abi.ts diff --git a/lib/policy-group/index.spec.ts b/lib/ethereum/policy-group/index.spec.ts similarity index 95% rename from lib/policy-group/index.spec.ts rename to lib/ethereum/policy-group/index.spec.ts index a75caa1f9..52818b294 100644 --- a/lib/policy-group/index.spec.ts +++ b/lib/ethereum/policy-group/index.spec.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { createPolicyGroupContract, PolicyGroupContract } from '.' import { createIsGroupCaller } from './isGroup' import { policyGroupAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' describe('policy-group/index.ts', () => { describe('createPolicyGroupContract', () => { diff --git a/lib/policy-group/index.ts b/lib/ethereum/policy-group/index.ts similarity index 94% rename from lib/policy-group/index.ts rename to lib/ethereum/policy-group/index.ts index 01a478e17..78cd419b4 100644 --- a/lib/policy-group/index.ts +++ b/lib/ethereum/policy-group/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { policyGroupAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createIsGroupCaller } from './isGroup' import { always } from 'ramda' diff --git a/lib/policy-group/isDuringVotingPeriod.spec.ts b/lib/ethereum/policy-group/isDuringVotingPeriod.spec.ts similarity index 100% rename from lib/policy-group/isDuringVotingPeriod.spec.ts rename to lib/ethereum/policy-group/isDuringVotingPeriod.spec.ts diff --git a/lib/policy-group/isDuringVotingPeriod.ts b/lib/ethereum/policy-group/isDuringVotingPeriod.ts similarity index 90% rename from lib/policy-group/isDuringVotingPeriod.ts rename to lib/ethereum/policy-group/isDuringVotingPeriod.ts index 0baef36f6..ae1e0eebe 100644 --- a/lib/policy-group/isDuringVotingPeriod.ts +++ b/lib/ethereum/policy-group/isDuringVotingPeriod.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateIsDuringVotingPeriodCaller = ( contract: Contract diff --git a/lib/policy-group/isGroup.spec.ts b/lib/ethereum/policy-group/isGroup.spec.ts similarity index 100% rename from lib/policy-group/isGroup.spec.ts rename to lib/ethereum/policy-group/isGroup.spec.ts diff --git a/lib/policy-group/isGroup.ts b/lib/ethereum/policy-group/isGroup.ts similarity index 89% rename from lib/policy-group/isGroup.ts rename to lib/ethereum/policy-group/isGroup.ts index ff8cc9cf0..1128a6408 100644 --- a/lib/policy-group/isGroup.ts +++ b/lib/ethereum/policy-group/isGroup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateIsGroupCaller = ( contract: Contract diff --git a/lib/policy/abi.ts b/lib/ethereum/policy/abi.ts similarity index 100% rename from lib/policy/abi.ts rename to lib/ethereum/policy/abi.ts diff --git a/lib/policy/authenticationFee.spec.ts b/lib/ethereum/policy/authenticationFee.spec.ts similarity index 100% rename from lib/policy/authenticationFee.spec.ts rename to lib/ethereum/policy/authenticationFee.spec.ts diff --git a/lib/policy/authenticationFee.ts b/lib/ethereum/policy/authenticationFee.ts similarity index 90% rename from lib/policy/authenticationFee.ts rename to lib/ethereum/policy/authenticationFee.ts index 65b42e203..d8a333c81 100644 --- a/lib/policy/authenticationFee.ts +++ b/lib/ethereum/policy/authenticationFee.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateAuthenticationFeeCaller = ( contract: Contract diff --git a/lib/policy/capSetter.spec.ts b/lib/ethereum/policy/capSetter.spec.ts similarity index 100% rename from lib/policy/capSetter.spec.ts rename to lib/ethereum/policy/capSetter.spec.ts diff --git a/lib/policy/capSetter.ts b/lib/ethereum/policy/capSetter.ts similarity index 88% rename from lib/policy/capSetter.ts rename to lib/ethereum/policy/capSetter.ts index bfd94b635..e71e255e9 100644 --- a/lib/policy/capSetter.ts +++ b/lib/ethereum/policy/capSetter.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateCapSetterCaller = ( diff --git a/lib/policy/holdersShare.spec.ts b/lib/ethereum/policy/holdersShare.spec.ts similarity index 100% rename from lib/policy/holdersShare.spec.ts rename to lib/ethereum/policy/holdersShare.spec.ts diff --git a/lib/policy/holdersShare.ts b/lib/ethereum/policy/holdersShare.ts similarity index 90% rename from lib/policy/holdersShare.ts rename to lib/ethereum/policy/holdersShare.ts index d7efb6e82..f7d7a0026 100644 --- a/lib/policy/holdersShare.ts +++ b/lib/ethereum/policy/holdersShare.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateHoldersShareCaller = ( contract: Contract diff --git a/lib/policy/index.spec.ts b/lib/ethereum/policy/index.spec.ts similarity index 97% rename from lib/policy/index.spec.ts rename to lib/ethereum/policy/index.spec.ts index fde9ac27e..b27556e40 100644 --- a/lib/policy/index.spec.ts +++ b/lib/ethereum/policy/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createPolicyContract, PolicyContract } from '.' import { policyAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createHoldersShareCaller } from './holdersShare' import { createRewardsCaller } from './rewards' import { createAuthenticationFeeCaller } from './authenticationFee' diff --git a/lib/policy/index.ts b/lib/ethereum/policy/index.ts similarity index 97% rename from lib/policy/index.ts rename to lib/ethereum/policy/index.ts index ba4776229..b3092c493 100644 --- a/lib/policy/index.ts +++ b/lib/ethereum/policy/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { policyAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { always } from 'ramda' import { createHoldersShareCaller } from './holdersShare' import { createRewardsCaller } from './rewards' diff --git a/lib/policy/marketVotingBlocks.spec.ts b/lib/ethereum/policy/marketVotingBlocks.spec.ts similarity index 100% rename from lib/policy/marketVotingBlocks.spec.ts rename to lib/ethereum/policy/marketVotingBlocks.spec.ts diff --git a/lib/policy/marketVotingBlocks.ts b/lib/ethereum/policy/marketVotingBlocks.ts similarity index 89% rename from lib/policy/marketVotingBlocks.ts rename to lib/ethereum/policy/marketVotingBlocks.ts index 0ec31d11f..86474a082 100644 --- a/lib/policy/marketVotingBlocks.ts +++ b/lib/ethereum/policy/marketVotingBlocks.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMarketVotingBlocksCaller = ( diff --git a/lib/policy/policyVotingBlocks.spec.ts b/lib/ethereum/policy/policyVotingBlocks.spec.ts similarity index 100% rename from lib/policy/policyVotingBlocks.spec.ts rename to lib/ethereum/policy/policyVotingBlocks.spec.ts diff --git a/lib/policy/policyVotingBlocks.ts b/lib/ethereum/policy/policyVotingBlocks.ts similarity index 89% rename from lib/policy/policyVotingBlocks.ts rename to lib/ethereum/policy/policyVotingBlocks.ts index e8fcb93c9..bec2efb40 100644 --- a/lib/policy/policyVotingBlocks.ts +++ b/lib/ethereum/policy/policyVotingBlocks.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePolicyVotingBlocksCaller = ( diff --git a/lib/policy/rewards.spec.ts b/lib/ethereum/policy/rewards.spec.ts similarity index 100% rename from lib/policy/rewards.spec.ts rename to lib/ethereum/policy/rewards.spec.ts diff --git a/lib/policy/rewards.ts b/lib/ethereum/policy/rewards.ts similarity index 89% rename from lib/policy/rewards.ts rename to lib/ethereum/policy/rewards.ts index e99985bea..431bce969 100644 --- a/lib/policy/rewards.ts +++ b/lib/ethereum/policy/rewards.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateRewardsCaller = ( contract: Contract diff --git a/lib/policy/shareOfTreasury.spec.ts b/lib/ethereum/policy/shareOfTreasury.spec.ts similarity index 100% rename from lib/policy/shareOfTreasury.spec.ts rename to lib/ethereum/policy/shareOfTreasury.spec.ts diff --git a/lib/policy/shareOfTreasury.ts b/lib/ethereum/policy/shareOfTreasury.ts similarity index 89% rename from lib/policy/shareOfTreasury.ts rename to lib/ethereum/policy/shareOfTreasury.ts index a4e451bb9..2a7b2b2f5 100644 --- a/lib/policy/shareOfTreasury.ts +++ b/lib/ethereum/policy/shareOfTreasury.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateShareOfTreasuryCaller = ( contract: Contract diff --git a/lib/policy/treasury.spec.ts b/lib/ethereum/policy/treasury.spec.ts similarity index 100% rename from lib/policy/treasury.spec.ts rename to lib/ethereum/policy/treasury.spec.ts diff --git a/lib/policy/treasury.ts b/lib/ethereum/policy/treasury.ts similarity index 87% rename from lib/policy/treasury.ts rename to lib/ethereum/policy/treasury.ts index 915655c91..ffe73d8d3 100644 --- a/lib/policy/treasury.ts +++ b/lib/ethereum/policy/treasury.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateTreasuryCaller = (contract: Contract) => () => Promise diff --git a/lib/property-factory/abi.ts b/lib/ethereum/property-factory/abi.ts similarity index 100% rename from lib/property-factory/abi.ts rename to lib/ethereum/property-factory/abi.ts diff --git a/lib/property-factory/create.spec.ts b/lib/ethereum/property-factory/create.spec.ts similarity index 96% rename from lib/property-factory/create.spec.ts rename to lib/ethereum/property-factory/create.spec.ts index f1821178f..3e1f49a53 100644 --- a/lib/property-factory/create.spec.ts +++ b/lib/ethereum/property-factory/create.spec.ts @@ -1,5 +1,5 @@ import { createCreatePropertyCaller } from './create' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('createProperty.spec.ts', () => { describe('createCreatePropertyCaller', () => { diff --git a/lib/property-factory/create.ts b/lib/ethereum/property-factory/create.ts similarity index 92% rename from lib/property-factory/create.ts rename to lib/ethereum/property-factory/create.ts index 32f8aa281..1fe53bf05 100644 --- a/lib/property-factory/create.ts +++ b/lib/ethereum/property-factory/create.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateCreatePropertyCaller = ( contract: Contract, diff --git a/lib/property-factory/createAndAuthenticate.spec.ts b/lib/ethereum/property-factory/createAndAuthenticate.spec.ts similarity index 97% rename from lib/property-factory/createAndAuthenticate.spec.ts rename to lib/ethereum/property-factory/createAndAuthenticate.spec.ts index d4f0b90e3..17233ffb0 100644 --- a/lib/property-factory/createAndAuthenticate.spec.ts +++ b/lib/ethereum/property-factory/createAndAuthenticate.spec.ts @@ -7,8 +7,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' -import { Event } from '../utils/web3-txs' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' +import { Event } from '../../common/utils/web3-txs' import Web3 from 'web3' import { propertyFactoryAbi } from './abi' diff --git a/lib/property-factory/createAndAuthenticate.ts b/lib/ethereum/property-factory/createAndAuthenticate.ts similarity index 88% rename from lib/property-factory/createAndAuthenticate.ts rename to lib/ethereum/property-factory/createAndAuthenticate.ts index c01961d9d..3620f47e4 100644 --- a/lib/property-factory/createAndAuthenticate.ts +++ b/lib/ethereum/property-factory/createAndAuthenticate.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { WaitForEventOptions } from '../market/authenticate' -import { waitForCreateMetrics } from '../utils/waitForCreateMetrics' -import { TxReceipt } from '../utils/web3-txs' +import { waitForCreateMetrics } from '../../common/utils/waitForCreateMetrics' +import { TxReceipt } from '../../common/utils/web3-txs' import { always } from 'ramda' export type CreateCreateAndAuthenticateCaller = ( diff --git a/lib/property-factory/index.spec.ts b/lib/ethereum/property-factory/index.spec.ts similarity index 96% rename from lib/property-factory/index.spec.ts rename to lib/ethereum/property-factory/index.spec.ts index 6196756bc..058baf73d 100644 --- a/lib/property-factory/index.spec.ts +++ b/lib/ethereum/property-factory/index.spec.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { createPropertyFactoryContract, PropertyFactoryContract } from '.' import { createCreatePropertyCaller } from './create' import { propertyFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' describe('property/index.ts', () => { diff --git a/lib/property-factory/index.ts b/lib/ethereum/property-factory/index.ts similarity index 93% rename from lib/property-factory/index.ts rename to lib/ethereum/property-factory/index.ts index cf9b43e4f..a8f1a0d25 100644 --- a/lib/property-factory/index.ts +++ b/lib/ethereum/property-factory/index.ts @@ -2,12 +2,12 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { propertyFactoryAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createCreatePropertyCaller } from './create' import { WaitForEventOptions } from '../market/authenticate' import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' import { always } from 'ramda' -import { TxReceipt } from '../utils/web3-txs' +import { TxReceipt } from '../../common/utils/web3-txs' export type PropertyFactoryContract = { readonly create: ( diff --git a/lib/property/abi.ts b/lib/ethereum/property/abi.ts similarity index 100% rename from lib/property/abi.ts rename to lib/ethereum/property/abi.ts diff --git a/lib/property/author.spec.ts b/lib/ethereum/property/author.spec.ts similarity index 100% rename from lib/property/author.spec.ts rename to lib/ethereum/property/author.spec.ts diff --git a/lib/property/author.ts b/lib/ethereum/property/author.ts similarity index 87% rename from lib/property/author.ts rename to lib/ethereum/property/author.ts index 2b494ee48..5e3017517 100644 --- a/lib/property/author.ts +++ b/lib/ethereum/property/author.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateAuthorCaller = (contract: Contract) => () => Promise diff --git a/lib/property/changeAuthor.spec.ts b/lib/ethereum/property/changeAuthor.spec.ts similarity index 94% rename from lib/property/changeAuthor.spec.ts rename to lib/ethereum/property/changeAuthor.spec.ts index c1ae07d34..4762b3a15 100644 --- a/lib/property/changeAuthor.spec.ts +++ b/lib/ethereum/property/changeAuthor.spec.ts @@ -1,5 +1,5 @@ import { createChangeAuthorCaller } from './changeAuthor' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('changeAuthor.spec.ts', () => { describe('createChangeAuthorCaller', () => { diff --git a/lib/property/changeAuthor.ts b/lib/ethereum/property/changeAuthor.ts similarity index 91% rename from lib/property/changeAuthor.ts rename to lib/ethereum/property/changeAuthor.ts index 942963d7a..32cdaf648 100644 --- a/lib/property/changeAuthor.ts +++ b/lib/ethereum/property/changeAuthor.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateChangeAuthorCaller = ( diff --git a/lib/property/changeName.spec.ts b/lib/ethereum/property/changeName.spec.ts similarity index 94% rename from lib/property/changeName.spec.ts rename to lib/ethereum/property/changeName.spec.ts index 33b8a1c6d..91d50d6d8 100644 --- a/lib/property/changeName.spec.ts +++ b/lib/ethereum/property/changeName.spec.ts @@ -1,5 +1,5 @@ import { createChangeNameCaller } from './changeName' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('changeName.spec.ts', () => { describe('createChangeNameCaller', () => { diff --git a/lib/property/changeName.ts b/lib/ethereum/property/changeName.ts similarity index 91% rename from lib/property/changeName.ts rename to lib/ethereum/property/changeName.ts index 264a48135..f7d8e6bce 100644 --- a/lib/property/changeName.ts +++ b/lib/ethereum/property/changeName.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateChangeNameCaller = ( diff --git a/lib/property/changeSymbol.spec.ts b/lib/ethereum/property/changeSymbol.spec.ts similarity index 94% rename from lib/property/changeSymbol.spec.ts rename to lib/ethereum/property/changeSymbol.spec.ts index 89b162965..c67373a33 100644 --- a/lib/property/changeSymbol.spec.ts +++ b/lib/ethereum/property/changeSymbol.spec.ts @@ -1,5 +1,5 @@ import { createChangeSymbolCaller } from './changeSymbol' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('changeSymbol.spec.ts', () => { describe('createChangeSymbolCaller', () => { diff --git a/lib/property/changeSymbol.ts b/lib/ethereum/property/changeSymbol.ts similarity index 91% rename from lib/property/changeSymbol.ts rename to lib/ethereum/property/changeSymbol.ts index a30ca0e32..e33c3343d 100644 --- a/lib/property/changeSymbol.ts +++ b/lib/ethereum/property/changeSymbol.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateChangeSymbolCaller = ( diff --git a/lib/property/index.spec.ts b/lib/ethereum/property/index.spec.ts similarity index 97% rename from lib/property/index.spec.ts rename to lib/ethereum/property/index.spec.ts index 667972f65..22166b279 100644 --- a/lib/property/index.spec.ts +++ b/lib/ethereum/property/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createPropertyContract, PropertyContract } from '.' import { propertyAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createAuthorCaller } from './author' import { createChangeNameCaller } from './changeName' import { createChangeSymbolCaller } from './changeSymbol' diff --git a/lib/property/index.ts b/lib/ethereum/property/index.ts similarity index 98% rename from lib/property/index.ts rename to lib/ethereum/property/index.ts index 3826427d1..38b747e02 100644 --- a/lib/property/index.ts +++ b/lib/ethereum/property/index.ts @@ -3,7 +3,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { always } from 'ramda' import { propertyAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createAuthorCaller } from './author' import { createChangeAuthorCaller } from './changeAuthor' import { createChangeNameCaller } from './changeName' diff --git a/lib/registry/abi.ts b/lib/ethereum/registry/abi.ts similarity index 100% rename from lib/registry/abi.ts rename to lib/ethereum/registry/abi.ts diff --git a/lib/registry/allocator.spec.ts b/lib/ethereum/registry/allocator.spec.ts similarity index 100% rename from lib/registry/allocator.spec.ts rename to lib/ethereum/registry/allocator.spec.ts diff --git a/lib/registry/allocator.ts b/lib/ethereum/registry/allocator.ts similarity index 87% rename from lib/registry/allocator.ts rename to lib/ethereum/registry/allocator.ts index 8d0fe1ce4..4aeb9ceab 100644 --- a/lib/registry/allocator.ts +++ b/lib/ethereum/registry/allocator.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateAllocatorCaller = ( diff --git a/lib/registry/allocatorStorage.spec.ts b/lib/ethereum/registry/allocatorStorage.spec.ts similarity index 100% rename from lib/registry/allocatorStorage.spec.ts rename to lib/ethereum/registry/allocatorStorage.spec.ts diff --git a/lib/registry/allocatorStorage.ts b/lib/ethereum/registry/allocatorStorage.ts similarity index 88% rename from lib/registry/allocatorStorage.ts rename to lib/ethereum/registry/allocatorStorage.ts index bbc3c1783..228fc6bc3 100644 --- a/lib/registry/allocatorStorage.ts +++ b/lib/ethereum/registry/allocatorStorage.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateAllocatorStorageCaller = ( diff --git a/lib/registry/index.spec.ts b/lib/ethereum/registry/index.spec.ts similarity index 98% rename from lib/registry/index.spec.ts rename to lib/ethereum/registry/index.spec.ts index 5c0dd7dc3..5663131af 100644 --- a/lib/registry/index.spec.ts +++ b/lib/ethereum/registry/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createRegistryContract, RegistryContract } from '.' import { addressConfigAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createTokenCaller } from './token' import { createAllocatorCaller } from './allocator' import { createAllocatorStorageCaller } from './allocatorStorage' diff --git a/lib/registry/index.ts b/lib/ethereum/registry/index.ts similarity index 98% rename from lib/registry/index.ts rename to lib/ethereum/registry/index.ts index 4d1e6c461..1e6f07de8 100644 --- a/lib/registry/index.ts +++ b/lib/ethereum/registry/index.ts @@ -2,7 +2,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { addressConfigAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createTokenCaller } from './token' import { createAllocatorCaller } from './allocator' import { createAllocatorStorageCaller } from './allocatorStorage' diff --git a/lib/registry/lockup.spec.ts b/lib/ethereum/registry/lockup.spec.ts similarity index 100% rename from lib/registry/lockup.spec.ts rename to lib/ethereum/registry/lockup.spec.ts diff --git a/lib/registry/lockup.ts b/lib/ethereum/registry/lockup.ts similarity index 87% rename from lib/registry/lockup.ts rename to lib/ethereum/registry/lockup.ts index 873208fc7..136af3513 100644 --- a/lib/registry/lockup.ts +++ b/lib/ethereum/registry/lockup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateLockupCaller = (contract: Contract) => () => Promise diff --git a/lib/registry/lockupStorage.spec.ts b/lib/ethereum/registry/lockupStorage.spec.ts similarity index 100% rename from lib/registry/lockupStorage.spec.ts rename to lib/ethereum/registry/lockupStorage.spec.ts diff --git a/lib/registry/lockupStorage.ts b/lib/ethereum/registry/lockupStorage.ts similarity index 88% rename from lib/registry/lockupStorage.ts rename to lib/ethereum/registry/lockupStorage.ts index e30fe0764..f7449ae8a 100644 --- a/lib/registry/lockupStorage.ts +++ b/lib/ethereum/registry/lockupStorage.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateLockupStorageCaller = ( diff --git a/lib/registry/marketFactory.spec.ts b/lib/ethereum/registry/marketFactory.spec.ts similarity index 100% rename from lib/registry/marketFactory.spec.ts rename to lib/ethereum/registry/marketFactory.spec.ts diff --git a/lib/registry/marketFactory.ts b/lib/ethereum/registry/marketFactory.ts similarity index 88% rename from lib/registry/marketFactory.ts rename to lib/ethereum/registry/marketFactory.ts index e5ce90bea..47d629261 100644 --- a/lib/registry/marketFactory.ts +++ b/lib/ethereum/registry/marketFactory.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMarketFactoryCaller = ( diff --git a/lib/registry/marketGroup.spec.ts b/lib/ethereum/registry/marketGroup.spec.ts similarity index 100% rename from lib/registry/marketGroup.spec.ts rename to lib/ethereum/registry/marketGroup.spec.ts diff --git a/lib/registry/marketGroup.ts b/lib/ethereum/registry/marketGroup.ts similarity index 87% rename from lib/registry/marketGroup.ts rename to lib/ethereum/registry/marketGroup.ts index 5d94328ac..a41afcd13 100644 --- a/lib/registry/marketGroup.ts +++ b/lib/ethereum/registry/marketGroup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMarketGroupCaller = ( diff --git a/lib/registry/metricsFactory.spec.ts b/lib/ethereum/registry/metricsFactory.spec.ts similarity index 100% rename from lib/registry/metricsFactory.spec.ts rename to lib/ethereum/registry/metricsFactory.spec.ts diff --git a/lib/registry/metricsFactory.ts b/lib/ethereum/registry/metricsFactory.ts similarity index 88% rename from lib/registry/metricsFactory.ts rename to lib/ethereum/registry/metricsFactory.ts index 5efd42a20..3e58b8ef0 100644 --- a/lib/registry/metricsFactory.ts +++ b/lib/ethereum/registry/metricsFactory.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMetricsFactoryCaller = ( diff --git a/lib/registry/metricsGroup.spec.ts b/lib/ethereum/registry/metricsGroup.spec.ts similarity index 100% rename from lib/registry/metricsGroup.spec.ts rename to lib/ethereum/registry/metricsGroup.spec.ts diff --git a/lib/registry/metricsGroup.ts b/lib/ethereum/registry/metricsGroup.ts similarity index 88% rename from lib/registry/metricsGroup.ts rename to lib/ethereum/registry/metricsGroup.ts index e3f62309d..d7d38d891 100644 --- a/lib/registry/metricsGroup.ts +++ b/lib/ethereum/registry/metricsGroup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateMetricsGroupCaller = ( diff --git a/lib/registry/policy.spec.ts b/lib/ethereum/registry/policy.spec.ts similarity index 100% rename from lib/registry/policy.spec.ts rename to lib/ethereum/registry/policy.spec.ts diff --git a/lib/registry/policy.ts b/lib/ethereum/registry/policy.ts similarity index 87% rename from lib/registry/policy.ts rename to lib/ethereum/registry/policy.ts index 45239493b..37c50fb0a 100644 --- a/lib/registry/policy.ts +++ b/lib/ethereum/registry/policy.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePolicyCaller = (contract: Contract) => () => Promise diff --git a/lib/registry/policyFactory.spec.ts b/lib/ethereum/registry/policyFactory.spec.ts similarity index 100% rename from lib/registry/policyFactory.spec.ts rename to lib/ethereum/registry/policyFactory.spec.ts diff --git a/lib/registry/policyFactory.ts b/lib/ethereum/registry/policyFactory.ts similarity index 88% rename from lib/registry/policyFactory.ts rename to lib/ethereum/registry/policyFactory.ts index b89ae7223..8336f707c 100644 --- a/lib/registry/policyFactory.ts +++ b/lib/ethereum/registry/policyFactory.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePolicyFactoryCaller = ( diff --git a/lib/registry/policyGroup.spec.ts b/lib/ethereum/registry/policyGroup.spec.ts similarity index 100% rename from lib/registry/policyGroup.spec.ts rename to lib/ethereum/registry/policyGroup.spec.ts diff --git a/lib/registry/policyGroup.ts b/lib/ethereum/registry/policyGroup.ts similarity index 87% rename from lib/registry/policyGroup.ts rename to lib/ethereum/registry/policyGroup.ts index 44d7a75c1..68be3eb36 100644 --- a/lib/registry/policyGroup.ts +++ b/lib/ethereum/registry/policyGroup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePolicyGroupCaller = ( diff --git a/lib/registry/policySet.spec.ts b/lib/ethereum/registry/policySet.spec.ts similarity index 100% rename from lib/registry/policySet.spec.ts rename to lib/ethereum/registry/policySet.spec.ts diff --git a/lib/registry/policySet.ts b/lib/ethereum/registry/policySet.ts similarity index 87% rename from lib/registry/policySet.ts rename to lib/ethereum/registry/policySet.ts index 5856b0216..8b1be6ffd 100644 --- a/lib/registry/policySet.ts +++ b/lib/ethereum/registry/policySet.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePolicySetCaller = ( diff --git a/lib/registry/propertyFactory.spec.ts b/lib/ethereum/registry/propertyFactory.spec.ts similarity index 100% rename from lib/registry/propertyFactory.spec.ts rename to lib/ethereum/registry/propertyFactory.spec.ts diff --git a/lib/registry/propertyFactory.ts b/lib/ethereum/registry/propertyFactory.ts similarity index 88% rename from lib/registry/propertyFactory.ts rename to lib/ethereum/registry/propertyFactory.ts index 55c00fcd5..050ec5580 100644 --- a/lib/registry/propertyFactory.ts +++ b/lib/ethereum/registry/propertyFactory.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePropertyFactoryCaller = ( diff --git a/lib/registry/propertyGroup.spec.ts b/lib/ethereum/registry/propertyGroup.spec.ts similarity index 100% rename from lib/registry/propertyGroup.spec.ts rename to lib/ethereum/registry/propertyGroup.spec.ts diff --git a/lib/registry/propertyGroup.ts b/lib/ethereum/registry/propertyGroup.ts similarity index 88% rename from lib/registry/propertyGroup.ts rename to lib/ethereum/registry/propertyGroup.ts index 76f802669..d532ca373 100644 --- a/lib/registry/propertyGroup.ts +++ b/lib/ethereum/registry/propertyGroup.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreatePropertyGroupCaller = ( diff --git a/lib/registry/token.spec.ts b/lib/ethereum/registry/token.spec.ts similarity index 100% rename from lib/registry/token.spec.ts rename to lib/ethereum/registry/token.spec.ts diff --git a/lib/registry/token.ts b/lib/ethereum/registry/token.ts similarity index 87% rename from lib/registry/token.ts rename to lib/ethereum/registry/token.ts index 1368f8f31..e02d740a9 100644 --- a/lib/registry/token.ts +++ b/lib/ethereum/registry/token.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateTokenCaller = (contract: Contract) => () => Promise diff --git a/lib/registry/withdraw.spec.ts b/lib/ethereum/registry/withdraw.spec.ts similarity index 100% rename from lib/registry/withdraw.spec.ts rename to lib/ethereum/registry/withdraw.spec.ts diff --git a/lib/registry/withdraw.ts b/lib/ethereum/registry/withdraw.ts similarity index 87% rename from lib/registry/withdraw.ts rename to lib/ethereum/registry/withdraw.ts index 6a7f4fa4a..bf8e40261 100644 --- a/lib/registry/withdraw.ts +++ b/lib/ethereum/registry/withdraw.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateWithdrawCaller = (contract: Contract) => () => Promise diff --git a/lib/registry/withdrawStorage.spec.ts b/lib/ethereum/registry/withdrawStorage.spec.ts similarity index 100% rename from lib/registry/withdrawStorage.spec.ts rename to lib/ethereum/registry/withdrawStorage.spec.ts diff --git a/lib/registry/withdrawStorage.ts b/lib/ethereum/registry/withdrawStorage.ts similarity index 88% rename from lib/registry/withdrawStorage.ts rename to lib/ethereum/registry/withdrawStorage.ts index 36722ec35..148f858a7 100644 --- a/lib/registry/withdrawStorage.ts +++ b/lib/ethereum/registry/withdrawStorage.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { always } from 'ramda' export type CreateWithdrawStorageCaller = ( diff --git a/lib/s-tokens/abi.ts b/lib/ethereum/s-tokens/abi.ts similarity index 100% rename from lib/s-tokens/abi.ts rename to lib/ethereum/s-tokens/abi.ts diff --git a/lib/s-tokens/index.spec.ts b/lib/ethereum/s-tokens/index.spec.ts similarity index 92% rename from lib/s-tokens/index.spec.ts rename to lib/ethereum/s-tokens/index.spec.ts index 34487d619..2a65aa3cf 100644 --- a/lib/s-tokens/index.spec.ts +++ b/lib/ethereum/s-tokens/index.spec.ts @@ -1,5 +1,5 @@ import Web3 from 'web3' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createSTokensContract, STokensContract } from '.' import { createPositionsCaller } from './positions' import { createRewardsCaller } from './rewards' @@ -18,10 +18,7 @@ describe('s-tokens/index.ts', () => { const expected: ( address?: string, options?: CustomOptions - ) => STokensContract = ( - address?: string, - options?: CustomOptions - ) => { + ) => STokensContract = (address?: string, options?: CustomOptions) => { const sTokensContract = new client.eth.Contract( [...sTokensAbi], address, diff --git a/lib/s-tokens/index.ts b/lib/ethereum/s-tokens/index.ts similarity index 96% rename from lib/s-tokens/index.ts rename to lib/ethereum/s-tokens/index.ts index b1fc01eb4..a7cb9fdb6 100644 --- a/lib/s-tokens/index.ts +++ b/lib/ethereum/s-tokens/index.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { sTokensAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createPositionsCaller, Positions } from './positions' import { createRewardsCaller, Rewards } from './rewards' import { always } from 'ramda' diff --git a/lib/s-tokens/positions.spec.ts b/lib/ethereum/s-tokens/positions.spec.ts similarity index 100% rename from lib/s-tokens/positions.spec.ts rename to lib/ethereum/s-tokens/positions.spec.ts diff --git a/lib/s-tokens/positions.ts b/lib/ethereum/s-tokens/positions.ts similarity index 90% rename from lib/s-tokens/positions.ts rename to lib/ethereum/s-tokens/positions.ts index 6541baf9f..0f5e84d1b 100644 --- a/lib/s-tokens/positions.ts +++ b/lib/ethereum/s-tokens/positions.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { arrayify } from '../utils/arrayify' -import { execute } from '../utils/execute' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' export type Positions = { readonly property: string diff --git a/lib/s-tokens/positionsOfOwner.spec.ts b/lib/ethereum/s-tokens/positionsOfOwner.spec.ts similarity index 100% rename from lib/s-tokens/positionsOfOwner.spec.ts rename to lib/ethereum/s-tokens/positionsOfOwner.spec.ts diff --git a/lib/s-tokens/positionsOfOwner.ts b/lib/ethereum/s-tokens/positionsOfOwner.ts similarity index 91% rename from lib/s-tokens/positionsOfOwner.ts rename to lib/ethereum/s-tokens/positionsOfOwner.ts index 7d5f9528a..27790a5bb 100644 --- a/lib/s-tokens/positionsOfOwner.ts +++ b/lib/ethereum/s-tokens/positionsOfOwner.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreatePositionsOfOwnerCaller = ( contract: Contract diff --git a/lib/s-tokens/positionsOfProperty.spec.ts b/lib/ethereum/s-tokens/positionsOfProperty.spec.ts similarity index 100% rename from lib/s-tokens/positionsOfProperty.spec.ts rename to lib/ethereum/s-tokens/positionsOfProperty.spec.ts diff --git a/lib/s-tokens/positionsOfProperty.ts b/lib/ethereum/s-tokens/positionsOfProperty.ts similarity index 91% rename from lib/s-tokens/positionsOfProperty.ts rename to lib/ethereum/s-tokens/positionsOfProperty.ts index 2a6b888cd..7ca17f0e4 100644 --- a/lib/s-tokens/positionsOfProperty.ts +++ b/lib/ethereum/s-tokens/positionsOfProperty.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreatePositionsOfPropertyCaller = ( contract: Contract diff --git a/lib/s-tokens/rewards.spec.ts b/lib/ethereum/s-tokens/rewards.spec.ts similarity index 100% rename from lib/s-tokens/rewards.spec.ts rename to lib/ethereum/s-tokens/rewards.spec.ts diff --git a/lib/s-tokens/rewards.ts b/lib/ethereum/s-tokens/rewards.ts similarity index 88% rename from lib/s-tokens/rewards.ts rename to lib/ethereum/s-tokens/rewards.ts index f597bedfe..4579227e1 100644 --- a/lib/s-tokens/rewards.ts +++ b/lib/ethereum/s-tokens/rewards.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { arrayify } from '../utils/arrayify' -import { execute } from '../utils/execute' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' export type Rewards = { readonly entireReward: string diff --git a/lib/s-tokens/tokenURI.spec.ts b/lib/ethereum/s-tokens/tokenURI.spec.ts similarity index 100% rename from lib/s-tokens/tokenURI.spec.ts rename to lib/ethereum/s-tokens/tokenURI.spec.ts diff --git a/lib/s-tokens/tokenURI.ts b/lib/ethereum/s-tokens/tokenURI.ts similarity index 91% rename from lib/s-tokens/tokenURI.ts rename to lib/ethereum/s-tokens/tokenURI.ts index cc4412eae..fd461040c 100644 --- a/lib/s-tokens/tokenURI.ts +++ b/lib/ethereum/s-tokens/tokenURI.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type TokenURI = { readonly name: string diff --git a/lib/withdraw/abi.ts b/lib/ethereum/withdraw/abi.ts similarity index 100% rename from lib/withdraw/abi.ts rename to lib/ethereum/withdraw/abi.ts diff --git a/lib/withdraw/bulkWithdraw.spec.ts b/lib/ethereum/withdraw/bulkWithdraw.spec.ts similarity index 91% rename from lib/withdraw/bulkWithdraw.spec.ts rename to lib/ethereum/withdraw/bulkWithdraw.spec.ts index 5cd791fc6..c82fbd5ab 100644 --- a/lib/withdraw/bulkWithdraw.spec.ts +++ b/lib/ethereum/withdraw/bulkWithdraw.spec.ts @@ -1,6 +1,6 @@ import { createBulkWithdrawCaller } from './bulkWithdraw' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' -import { txPromisify } from '../utils/txPromisify' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' +import { txPromisify } from '../../common/utils/txPromisify' describe('bulkWithdraw.spec.ts', () => { describe('createBulkWithdrawCaller', () => { diff --git a/lib/withdraw/bulkWithdraw.ts b/lib/ethereum/withdraw/bulkWithdraw.ts similarity index 83% rename from lib/withdraw/bulkWithdraw.ts rename to lib/ethereum/withdraw/bulkWithdraw.ts index eaee5326c..2cad94445 100644 --- a/lib/withdraw/bulkWithdraw.ts +++ b/lib/ethereum/withdraw/bulkWithdraw.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' -import { TxReceipt } from '../utils/web3-txs' +import { execute } from '../../common/utils/execute' +import { TxReceipt } from '../../common/utils/web3-txs' export type CreateBulkWithdrawCaller = ( contract: Contract, diff --git a/lib/withdraw/calculateRewardAmount.spec.ts b/lib/ethereum/withdraw/calculateRewardAmount.spec.ts similarity index 100% rename from lib/withdraw/calculateRewardAmount.spec.ts rename to lib/ethereum/withdraw/calculateRewardAmount.spec.ts diff --git a/lib/withdraw/calculateRewardAmount.ts b/lib/ethereum/withdraw/calculateRewardAmount.ts similarity index 85% rename from lib/withdraw/calculateRewardAmount.ts rename to lib/ethereum/withdraw/calculateRewardAmount.ts index ccf37f2fc..4dac1158d 100644 --- a/lib/withdraw/calculateRewardAmount.ts +++ b/lib/ethereum/withdraw/calculateRewardAmount.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract' -import { arrayify } from '../utils/arrayify' -import { execute } from '../utils/execute' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' export type calculateRewardAmountCaller = ( contract: Contract diff --git a/lib/withdraw/calculateWithdrawableAmount.spec.ts b/lib/ethereum/withdraw/calculateWithdrawableAmount.spec.ts similarity index 100% rename from lib/withdraw/calculateWithdrawableAmount.spec.ts rename to lib/ethereum/withdraw/calculateWithdrawableAmount.spec.ts diff --git a/lib/withdraw/calculateWithdrawableAmount.ts b/lib/ethereum/withdraw/calculateWithdrawableAmount.ts similarity index 91% rename from lib/withdraw/calculateWithdrawableAmount.ts rename to lib/ethereum/withdraw/calculateWithdrawableAmount.ts index 3542bd802..940874a83 100644 --- a/lib/withdraw/calculateWithdrawableAmount.ts +++ b/lib/ethereum/withdraw/calculateWithdrawableAmount.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateCalculateWithdrawableAmountCaller = ( contract: Contract diff --git a/lib/withdraw/getRewardsAmount.spec.ts b/lib/ethereum/withdraw/getRewardsAmount.spec.ts similarity index 100% rename from lib/withdraw/getRewardsAmount.spec.ts rename to lib/ethereum/withdraw/getRewardsAmount.spec.ts diff --git a/lib/withdraw/getRewardsAmount.ts b/lib/ethereum/withdraw/getRewardsAmount.ts similarity index 88% rename from lib/withdraw/getRewardsAmount.ts rename to lib/ethereum/withdraw/getRewardsAmount.ts index fdfc36208..5ff431f96 100644 --- a/lib/withdraw/getRewardsAmount.ts +++ b/lib/ethereum/withdraw/getRewardsAmount.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' export type CreateGetRewardsAmountCaller = ( contract: Contract diff --git a/lib/withdraw/index.spec.ts b/lib/ethereum/withdraw/index.spec.ts similarity index 97% rename from lib/withdraw/index.spec.ts rename to lib/ethereum/withdraw/index.spec.ts index 90e4dcfa9..d67ff4b12 100644 --- a/lib/withdraw/index.spec.ts +++ b/lib/ethereum/withdraw/index.spec.ts @@ -1,7 +1,7 @@ import Web3 from 'web3' import { createWithdrawContract, WithdrawContract } from '.' import { withdrawAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createWithdrawCaller } from './withdraw' import { createBulkWithdrawCaller } from './bulkWithdraw' import { createGetRewardsAmountCaller } from './getRewardsAmount' diff --git a/lib/withdraw/index.ts b/lib/ethereum/withdraw/index.ts similarity index 94% rename from lib/withdraw/index.ts rename to lib/ethereum/withdraw/index.ts index 0bb82e432..8bb7ef56e 100644 --- a/lib/withdraw/index.ts +++ b/lib/ethereum/withdraw/index.ts @@ -2,12 +2,12 @@ import Web3 from 'web3' import { Contract } from 'web3-eth-contract/types' import { withdrawAbi } from './abi' -import { CustomOptions } from '../option' +import { CustomOptions } from '../../common/option' import { createWithdrawCaller } from './withdraw' import { createGetRewardsAmountCaller } from './getRewardsAmount' import { createCalculateWithdrawableAmountCaller } from './calculateWithdrawableAmount' import { createBulkWithdrawCaller } from './bulkWithdraw' -import { TxReceipt } from '../utils/web3-txs' +import { TxReceipt } from '../../common/utils/web3-txs' import { always } from 'ramda' import { calculateRewardAmountCaller } from './calculateRewardAmount' diff --git a/lib/withdraw/withdraw.spec.ts b/lib/ethereum/withdraw/withdraw.spec.ts similarity index 94% rename from lib/withdraw/withdraw.spec.ts rename to lib/ethereum/withdraw/withdraw.spec.ts index ddc9bb96b..8b409fdfd 100644 --- a/lib/withdraw/withdraw.spec.ts +++ b/lib/ethereum/withdraw/withdraw.spec.ts @@ -1,5 +1,5 @@ import { createWithdrawCaller } from './withdraw' -import { stubbedWeb3, stubbedSendTx } from '../utils/for-test' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' describe('withdraw.spec.ts', () => { describe('createwithdrawCaller', () => { diff --git a/lib/withdraw/withdraw.ts b/lib/ethereum/withdraw/withdraw.ts similarity index 91% rename from lib/withdraw/withdraw.ts rename to lib/ethereum/withdraw/withdraw.ts index edcf76d24..e12f7b064 100644 --- a/lib/withdraw/withdraw.ts +++ b/lib/ethereum/withdraw/withdraw.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ import { Contract } from 'web3-eth-contract/types' import Web3 from 'web3' -import { execute } from '../utils/execute' +import { execute } from '../../common/utils/execute' import { T } from 'ramda' export type CreateWithdrawCaller = ( diff --git a/lib/index.ts b/lib/index.ts index 3aad5ba1d..93e8e6c9d 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,6 @@ -import { contractFactory } from './contract' +import { contractFactory } from './ethereum/contract' import { addresses } from './addresses' -import { utils } from './utils' -import { client } from './client' +import { utils } from './common/utils' +import { client } from './ethereum/client' export default { contractFactory, addresses, utils, client } diff --git a/lib/l2/client/createDetectSTokens.spec.ts b/lib/l2/client/createDetectSTokens.spec.ts new file mode 100644 index 000000000..67557016d --- /dev/null +++ b/lib/l2/client/createDetectSTokens.spec.ts @@ -0,0 +1,26 @@ +/* eslint-disable functional/no-class */ +import { createDetectSTokens } from './createDetectSTokens' + +describe('detectSTokens.ts', () => { + describe('createDetectSTokens', () => { + it('returns an array of IDs of the staking positions for the Property owned by the user', async () => { + const propertyAddress = '0xPropertyAddress' + const accountAddress = '0xAccountAddress' + const sTokens = { + positionsOfProperty: (a: string) => + Promise.resolve( + a === propertyAddress ? [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] : [] + ), + positionsOfOwner: (a: string) => + Promise.resolve(a === accountAddress ? [9, 5, 1, 2, 12] : []), + } + const result = await createDetectSTokens(sTokens as any)( + propertyAddress, + accountAddress + ) + const expected = [1, 2, 5, 9] + + expect(result).toEqual(expected) + }) + }) +}) diff --git a/lib/l2/client/createDetectSTokens.ts b/lib/l2/client/createDetectSTokens.ts new file mode 100644 index 000000000..8944f0762 --- /dev/null +++ b/lib/l2/client/createDetectSTokens.ts @@ -0,0 +1,27 @@ +import { intersection, sort } from 'ramda' +import { STokensContract } from '../s-tokens' + +export type CreateDetectSTokens = ( + sTokens: STokensContract +) => ( + propertyAddress: string, + accountAddress: string +) => Promise + +const diff = function (a: number, b: number): number { + return a - b +} +const asc = sort(diff) + +export const createDetectSTokens: CreateDetectSTokens = + (sTokens: STokensContract) => + async ( + propertyAddress: string, + accountAddress: string + ): Promise => { + const [listForProperty, listForOwner] = await Promise.all([ + sTokens.positionsOfProperty(propertyAddress), + sTokens.positionsOfOwner(accountAddress), + ]) + return asc(intersection(listForProperty, listForOwner)) + } diff --git a/lib/l2/client/index.spec.ts b/lib/l2/client/index.spec.ts new file mode 100644 index 000000000..cb81e5a05 --- /dev/null +++ b/lib/l2/client/index.spec.ts @@ -0,0 +1,16 @@ +import { DevkitClient, client } from './index' +import { createDetectSTokens } from './createDetectSTokens' + +describe('index.ts', () => { + describe('client', () => { + it('check return object', () => { + const expected: DevkitClient = { + createDetectSTokens, + } + + const result = client + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + }) + }) +}) diff --git a/lib/l2/client/index.ts b/lib/l2/client/index.ts new file mode 100644 index 000000000..5b26957f7 --- /dev/null +++ b/lib/l2/client/index.ts @@ -0,0 +1,9 @@ +import { createDetectSTokens } from './createDetectSTokens' + +export type DevkitClient = { + readonly createDetectSTokens: typeof createDetectSTokens +} + +export const client: DevkitClient = { + createDetectSTokens, +} diff --git a/lib/l2/contract.spec.ts b/lib/l2/contract.spec.ts new file mode 100644 index 000000000..78513079d --- /dev/null +++ b/lib/l2/contract.spec.ts @@ -0,0 +1,61 @@ +import Web3 from 'web3' +import { + createDevkitContract, + contractFactory, + DevkitContract, +} from './contract' +import { createMarketContract } from './market' +import { createPropertyContract } from './property/index' +import { createPropertyFactoryContract } from './property-factory/index' +import { createLockupContract } from './lockup/index' +import { createDevContract } from './dev' +import { createWithdrawContract } from './withdraw' +import { createRegistryContract } from './registry' +import { createPolicyContract } from './policy' +import { createMetricsContract } from './metrics' +import { createPolicyFactoryContract } from './policy-factory' +import { createSTokensContract } from './s-tokens' + +describe('contract.ts', () => { + describe('createDevkitContract', () => { + it('check return object', () => { + const host = 'localhost' + + const client = new Web3() + + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: DevkitContract = { + market: createMarketContract(client), + property: createPropertyContract(client), + propertyFactory: createPropertyFactoryContract(client), + lockup: createLockupContract(client), + withdraw: createWithdrawContract(client), + dev: createDevContract(client), + registry: createRegistryContract(client), + policy: createPolicyContract(client), + metrics: createMetricsContract(client), + policyFactory: createPolicyFactoryContract(client), + sTokens: createSTokensContract(client), + } + + const result = createDevkitContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + }) + }) + + describe('contractFactory', () => { + it('check return object', () => { + const client = new Web3() + + client.setProvider(new Web3.providers.HttpProvider('localhost')) + + const expected = createDevkitContract(client) + + const result = contractFactory(client.currentProvider) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + }) + }) +}) diff --git a/lib/l2/contract.ts b/lib/l2/contract.ts new file mode 100644 index 000000000..a1ca31b1a --- /dev/null +++ b/lib/l2/contract.ts @@ -0,0 +1,54 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { provider } from 'web3-core' +import { createMarketContract } from './market/index' +import { createPropertyContract } from './property/index' +import { createPropertyFactoryContract } from './property-factory/index' +import { createLockupContract } from './lockup/index' +import { createDevContract } from './dev/index' +import { createWithdrawContract } from './withdraw/index' +import { createRegistryContract } from './registry/index' +import { createPolicyContract } from './policy' +import { createMetricsContract } from './metrics' +import { createPolicyFactoryContract } from './policy-factory' +import { createSTokensContract } from './s-tokens' + +export type DevkitContract = { + readonly market: ReturnType + readonly property: ReturnType + readonly propertyFactory: ReturnType + readonly lockup: ReturnType + readonly withdraw: ReturnType + readonly dev: ReturnType + readonly registry: ReturnType + readonly policy: ReturnType + readonly metrics: ReturnType + readonly policyFactory: ReturnType + readonly sTokens: ReturnType +} +export type ContractFactory = (provider: provider) => DevkitContract +export type CreateDevkitContract = (client: Web3) => DevkitContract + +export const createDevkitContract: CreateDevkitContract = ( + client: Web3 +): DevkitContract => ({ + market: createMarketContract(client), + property: createPropertyContract(client), + propertyFactory: createPropertyFactoryContract(client), + lockup: createLockupContract(client), + withdraw: createWithdrawContract(client), + dev: createDevContract(client), + registry: createRegistryContract(client), + policy: createPolicyContract(client), + metrics: createMetricsContract(client), + policyFactory: createPolicyFactoryContract(client), + sTokens: createSTokensContract(client), +}) + +export const contractFactory: ContractFactory = ( + provider: provider +): DevkitContract => { + const client = new Web3(provider) + + return createDevkitContract(client) +} diff --git a/lib/l2/dev/abi.ts b/lib/l2/dev/abi.ts new file mode 100644 index 000000000..115e646dc --- /dev/null +++ b/lib/l2/dev/abi.ts @@ -0,0 +1,645 @@ +import { AbiItem } from 'web3-utils' + +export const devAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'bytes32', + name: 'previousAdminRole', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'bytes32', + name: 'newAdminRole', + type: 'bytes32', + }, + ], + name: 'RoleAdminChanged', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'RoleGranted', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + indexed: true, + internalType: 'address', + name: 'account', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'sender', + type: 'address', + }, + ], + name: 'RoleRevoked', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [], + name: 'BURNER_ROLE', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'DEFAULT_ADMIN_ROLE', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'MINTER_ROLE', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'subtractedValue', + type: 'uint256', + }, + ], + name: 'decreaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + ], + name: 'getRoleAdmin', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + ], + name: 'getRoleMember', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + ], + name: 'getRoleMemberCount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'grantRole', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'hasRole', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'addedValue', + type: 'uint256', + }, + ], + name: 'increaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'l1Address', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'renounceRole', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'role', + type: 'bytes32', + }, + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'revokeRole', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4', + }, + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'sender', + type: 'address', + }, + { + internalType: 'address', + name: 'recipient', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_l1DevAddress', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'bridgeMint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'bridgeBurn', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_account', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'burn', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/dev/index.spec.ts b/lib/l2/dev/index.spec.ts new file mode 100644 index 000000000..2cd3cb09a --- /dev/null +++ b/lib/l2/dev/index.spec.ts @@ -0,0 +1,53 @@ +import Web3 from 'web3' +import { createDevContract, DevContract } from '.' +import { createTransferCaller } from '../erc20/transfer' +import { devAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createBalanceOfCaller } from '../erc20/balanceOf' +import { createTotalSupplyCaller } from '../erc20/totalSupply' +import { createApproveCaller } from '../erc20/approve' +import { createTransferFromCaller } from '../erc20/transferFrom' +import { createNameCaller } from '../erc20/name' +import { createSymbolCaller } from '../erc20/symbol' +import { createDecimalsCaller } from '../erc20/decimals' +import { createAllowanceCaller } from '../erc20/allowance' + +describe('dev/index.ts', () => { + describe('createDevContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => DevContract = (address?: string, options?: CustomOptions) => { + const devContract = new client.eth.Contract([...devAbi], address, { + ...options, + }) + return { + totalSupply: createTotalSupplyCaller(devContract), + balanceOf: createBalanceOfCaller(devContract), + transfer: createTransferCaller(devContract, client), + allowance: createAllowanceCaller(devContract), + approve: createApproveCaller(devContract, client), + transferFrom: createTransferFromCaller(devContract, client), + name: createNameCaller(devContract), + symbol: createSymbolCaller(devContract), + decimals: createDecimalsCaller(devContract), + contract: () => devContract, + } + } + + const result = createDevContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/dev/index.ts b/lib/l2/dev/index.ts new file mode 100644 index 000000000..8e73482eb --- /dev/null +++ b/lib/l2/dev/index.ts @@ -0,0 +1,61 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { always } from 'ramda' +import { Contract } from 'web3-eth-contract/types' +import { devAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createTransferCaller } from '../erc20/transfer' +import { createBalanceOfCaller } from '../erc20/balanceOf' +import { createTotalSupplyCaller } from '../erc20/totalSupply' +import { createApproveCaller } from '../erc20/approve' +import { createTransferFromCaller } from '../erc20/transferFrom' +import { createNameCaller } from '../erc20/name' +import { createSymbolCaller } from '../erc20/symbol' +import { createDecimalsCaller } from '../erc20/decimals' +import { createAllowanceCaller } from '../erc20/allowance' + +export type DevContract = { + readonly totalSupply: () => Promise + readonly balanceOf: (address: string) => Promise + readonly transfer: (to: string, value: string) => Promise + readonly allowance: (from: string, to: string) => Promise + readonly approve: (to: string, value: string) => Promise + readonly transferFrom: ( + from: string, + to: string, + value: string + ) => Promise + readonly name: () => Promise + readonly symbol: () => Promise + readonly decimals: () => Promise + readonly contract: () => Contract +} + +export type CreateDevContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => DevContract + +export const createDevContract: CreateDevContract = + (client: Web3) => + (address?: string, options?: CustomOptions): DevContract => { + const contractClient: Contract = new client.eth.Contract( + [...devAbi], + address, + { + ...options, + } + ) + + return { + totalSupply: createTotalSupplyCaller(contractClient), + balanceOf: createBalanceOfCaller(contractClient), + transfer: createTransferCaller(contractClient, client), + allowance: createAllowanceCaller(contractClient), + approve: createApproveCaller(contractClient, client), + transferFrom: createTransferFromCaller(contractClient, client), + name: createNameCaller(contractClient), + symbol: createSymbolCaller(contractClient), + decimals: createDecimalsCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/erc20/allowance.spec.ts b/lib/l2/erc20/allowance.spec.ts new file mode 100644 index 000000000..9ad7487a9 --- /dev/null +++ b/lib/l2/erc20/allowance.spec.ts @@ -0,0 +1,54 @@ +import { createAllowanceCaller } from './allowance' + +describe('allowance.spec.ts', () => { + describe('createAllowanceCaller', () => { + it('call success', async () => { + const from = '0x1E9342827907CD370CB8Ba2F768d7D50b2f457F9' + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + allowance: (from: string, to: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAllowanceCaller(contract as any) + + const result = await caller(from, to) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + const from = '0x1E9342827907CD370CB8Ba2F768d7D50b2f457F9' + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + allowance: (from: string, to: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAllowanceCaller(contract as any) + + const result = await caller(from, to).catch((err) => err) + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/allowance.ts b/lib/l2/erc20/allowance.ts new file mode 100644 index 000000000..42027f08d --- /dev/null +++ b/lib/l2/erc20/allowance.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateAllowanceCaller = ( + contract: Contract +) => (from: string, to: string) => Promise + +export const createAllowanceCaller: CreateAllowanceCaller = + (contract: Contract) => async (from: string, to: string) => + execute({ + contract, + method: 'allowance', + args: [from, to], + }) diff --git a/lib/l2/erc20/approve.spec.ts b/lib/l2/erc20/approve.spec.ts new file mode 100644 index 000000000..e4f06de04 --- /dev/null +++ b/lib/l2/erc20/approve.spec.ts @@ -0,0 +1,53 @@ +import { createApproveCaller } from './approve' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('approve.spec.ts', () => { + describe('createApproveCaller', () => { + it('call success', async () => { + const success = true + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + approve: (to: string, value: number) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = success + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createApproveCaller(contract as any, stubbedWeb3) + + const result = await caller(to, value) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + approve: (to: string, value: number) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createApproveCaller(contract as any, stubbedWeb3) + + const result = await caller(to, value).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/erc20/approve.ts b/lib/l2/erc20/approve.ts new file mode 100644 index 000000000..705b944c1 --- /dev/null +++ b/lib/l2/erc20/approve.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateApproveCaller = ( + contract: Contract, + client: Web3 +) => (to: string, value: string) => Promise + +export const createApproveCaller: CreateApproveCaller = + (contract: Contract, client: Web3) => async (to: string, value: string) => + execute({ + contract, + method: 'approve', + mutation: true, + client, + args: [to, value], + }).then(T) diff --git a/lib/l2/erc20/balanceOf.spec.ts b/lib/l2/erc20/balanceOf.spec.ts new file mode 100644 index 000000000..2cb2937b5 --- /dev/null +++ b/lib/l2/erc20/balanceOf.spec.ts @@ -0,0 +1,53 @@ +import { createBalanceOfCaller } from './balanceOf' + +describe('balanceOf.spec.ts', () => { + describe('createBalanceOfCaller', () => { + it('call success', async () => { + const address = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + balanceOf: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createBalanceOfCaller(contract as any) + + const result = await caller(address) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + const address = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + balanceOf: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createBalanceOfCaller(contract as any) + + const result = await caller(address).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/balanceOf.ts b/lib/l2/erc20/balanceOf.ts new file mode 100644 index 000000000..6757d60ba --- /dev/null +++ b/lib/l2/erc20/balanceOf.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateBalanceOfCaller = ( + contract: Contract +) => (address: string) => Promise + +export const createBalanceOfCaller: CreateBalanceOfCaller = + (contract: Contract) => async (address: string) => + execute({ contract, method: 'balanceOf', args: [address] }) diff --git a/lib/l2/erc20/decimals.spec.ts b/lib/l2/erc20/decimals.spec.ts new file mode 100644 index 000000000..b62b7d402 --- /dev/null +++ b/lib/l2/erc20/decimals.spec.ts @@ -0,0 +1,49 @@ +import { createDecimalsCaller } from './decimals' + +describe('dcimals.spec.ts', () => { + describe('createDecimalsCaller', () => { + it('call success', async () => { + const value = '18' + + const contract = { + methods: { + decimals: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDecimalsCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + decimals: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDecimalsCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/decimals.ts b/lib/l2/erc20/decimals.ts new file mode 100644 index 000000000..7a4c879e4 --- /dev/null +++ b/lib/l2/erc20/decimals.ts @@ -0,0 +1,10 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateDecimalsCaller = (contract: Contract) => () => Promise + +export const createDecimalsCaller: CreateDecimalsCaller = ( + contract: Contract +) => always(execute({ contract, method: 'decimals' })) diff --git a/lib/l2/erc20/name.spec.ts b/lib/l2/erc20/name.spec.ts new file mode 100644 index 000000000..855f749de --- /dev/null +++ b/lib/l2/erc20/name.spec.ts @@ -0,0 +1,49 @@ +import { createNameCaller } from './name' + +describe('name.spec.ts', () => { + describe('createNameCaller', () => { + it('call success', async () => { + const value = 'value' + + const contract = { + methods: { + name: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createNameCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + name: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createNameCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/name.ts b/lib/l2/erc20/name.ts new file mode 100644 index 000000000..c589adae2 --- /dev/null +++ b/lib/l2/erc20/name.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateNameCaller = (contract: Contract) => () => Promise + +export const createNameCaller: CreateNameCaller = (contract: Contract) => + always(execute({ contract, method: 'name' })) diff --git a/lib/l2/erc20/symbol.spec.ts b/lib/l2/erc20/symbol.spec.ts new file mode 100644 index 000000000..5f3886059 --- /dev/null +++ b/lib/l2/erc20/symbol.spec.ts @@ -0,0 +1,49 @@ +import { createSymbolCaller } from './symbol' + +describe('symbol.spec.ts', () => { + describe('createSymbolCaller', () => { + it('call success', async () => { + const value = 'value' + + const contract = { + methods: { + symbol: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createSymbolCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + symbol: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createSymbolCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/symbol.ts b/lib/l2/erc20/symbol.ts new file mode 100644 index 000000000..a5b13f7cd --- /dev/null +++ b/lib/l2/erc20/symbol.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateSymbolCaller = (contract: Contract) => () => Promise + +export const createSymbolCaller: CreateSymbolCaller = (contract: Contract) => + always(execute({ contract, method: 'symbol' })) diff --git a/lib/l2/erc20/totalSupply.spec.ts b/lib/l2/erc20/totalSupply.spec.ts new file mode 100644 index 000000000..1d08dba2a --- /dev/null +++ b/lib/l2/erc20/totalSupply.spec.ts @@ -0,0 +1,49 @@ +import { createTotalSupplyCaller } from './totalSupply' + +describe('totalSupply.spec.ts', () => { + describe('createTotalSupplyCaller', () => { + it('call success', async () => { + const value = '10000000000000000000000000' + + const contract = { + methods: { + totalSupply: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalSupplyCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + totalSupply: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalSupplyCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/erc20/totalSupply.ts b/lib/l2/erc20/totalSupply.ts new file mode 100644 index 000000000..e3f253206 --- /dev/null +++ b/lib/l2/erc20/totalSupply.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateTotalSupplyCaller = ( + contract: Contract +) => () => Promise + +export const createTotalSupplyCaller: CreateTotalSupplyCaller = ( + contract: Contract +) => always(execute({ contract, method: 'totalSupply' })) diff --git a/lib/l2/erc20/transfer.spec.ts b/lib/l2/erc20/transfer.spec.ts new file mode 100644 index 000000000..c0fda3bb5 --- /dev/null +++ b/lib/l2/erc20/transfer.spec.ts @@ -0,0 +1,53 @@ +import { createTransferCaller } from './transfer' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('transfer.spec.ts', () => { + describe('createTransferCaller', () => { + it('call success', async () => { + const success = true + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + transfer: (to: string, value: number) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = success + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTransferCaller(contract as any, stubbedWeb3) + + const result = await caller(to, value) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + transfer: (to: string, value: number) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTransferCaller(contract as any, stubbedWeb3) + + const result = await caller(to, value).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/erc20/transfer.ts b/lib/l2/erc20/transfer.ts new file mode 100644 index 000000000..629dad57a --- /dev/null +++ b/lib/l2/erc20/transfer.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateTransferCaller = ( + contract: Contract, + client: Web3 +) => (to: string, value: string) => Promise + +export const createTransferCaller: CreateTransferCaller = + (contract: Contract, client: Web3) => async (to: string, value: string) => + execute({ + contract, + method: 'transfer', + mutation: true, + client, + args: [to, value], + }).then(T) diff --git a/lib/l2/erc20/transferFrom.spec.ts b/lib/l2/erc20/transferFrom.spec.ts new file mode 100644 index 000000000..f4a455c12 --- /dev/null +++ b/lib/l2/erc20/transferFrom.spec.ts @@ -0,0 +1,55 @@ +import { createTransferFromCaller } from './transferFrom' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('transferFrom.spec.ts', () => { + describe('createTransferFromCaller', () => { + it('call success', async () => { + const success = true + const from = '0x1E9342827907CD370CB8Ba2F768d7D50b2f457F9' + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + transferFrom: (from: string, to: string, value: number) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = success + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTransferFromCaller(contract as any, stubbedWeb3) + + const result = await caller(from, to, value) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const from = '0x1E9342827907CD370CB8Ba2F768d7D50b2f457F9' + const to = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const value = '12345' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + transferFrom: (from: string, to: string, value: number) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTransferFromCaller(contract as any, stubbedWeb3) + + const result = await caller(from, to, value).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/erc20/transferFrom.ts b/lib/l2/erc20/transferFrom.ts new file mode 100644 index 000000000..ceee64677 --- /dev/null +++ b/lib/l2/erc20/transferFrom.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateTransferFromCaller = ( + contract: Contract, + client: Web3 +) => (from: string, to: string, value: string) => Promise + +export const createTransferFromCaller: CreateTransferFromCaller = + (contract: Contract, client: Web3) => + async (from: string, to: string, value: string) => + execute({ + contract, + method: 'transferFrom', + mutation: true, + client, + args: [from, to, value], + }).then(T) diff --git a/lib/l2/index.ts b/lib/l2/index.ts new file mode 100644 index 000000000..7f7d45ce0 --- /dev/null +++ b/lib/l2/index.ts @@ -0,0 +1,4 @@ +import { contractFactory } from './contract' +import { client } from './client' + +export default { contractFactory, client } diff --git a/lib/l2/lockup/abi.ts b/lib/l2/lockup/abi.ts new file mode 100644 index 000000000..9036429fb --- /dev/null +++ b/lib/l2/lockup/abi.ts @@ -0,0 +1,480 @@ +import { AbiItem } from 'web3-utils' + +export const lockupAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: '_value', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'Lockedup', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: '_cap', + type: 'uint256', + }, + ], + name: 'UpdateCap', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: '_value', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: '_reward', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'Withdrew', + type: 'event', + }, + { + inputs: [], + name: 'cap', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'cumulativeGlobalReward', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'cumulativeHoldersRewardCap', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'initialCumulativeHoldersRewardCap', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastCumulativeHoldersPriceCap', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'lastCumulativeHoldersRewardAmountPerProperty', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastCumulativeHoldersRewardPrice', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'lastCumulativeHoldersRewardPricePerProperty', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastCumulativeRewardPrice', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastLockedChangedCumulativeReward', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastSameGlobalRewardAmount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lastSameGlobalRewardTimestamp', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalLocked', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'totalLockedForProperty', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'depositToProperty', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'depositToPosition', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'withdrawByPosition', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_cap', + type: 'uint256', + }, + ], + name: 'updateCap', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'calculateCumulativeRewardPrices', + outputs: [ + { + internalType: 'uint256', + name: '_reward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_holders', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_interest', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_holdersCap', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'calculateRewardAmount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'update', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'calculateWithdrawableInterestAmountByPosition', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.spec.ts b/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.spec.ts new file mode 100644 index 000000000..e7d2adbf3 --- /dev/null +++ b/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.spec.ts @@ -0,0 +1,61 @@ +import { createCalculateCumulativeHoldersRewardAmountCaller } from './calculateCumulativeHoldersRewardAmount' + +describe('calculateCumulativeHoldersRewardAmount.spec.ts', () => { + describe('calculateCumulativeHoldersRewardAmount', () => { + it('call success', async () => { + const value = 'value' + + const lockupContract = { + methods: { + calculateCumulativeHoldersRewardAmount: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + propertyAddress: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateCumulativeHoldersRewardAmountCaller( + lockupContract as any + ) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + calculateCumulativeHoldersRewardAmount: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + propertyAddress: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateCumulativeHoldersRewardAmountCaller( + lockupContract as any + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.ts b/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.ts new file mode 100644 index 000000000..cb98cc02f --- /dev/null +++ b/lib/l2/lockup/calculateCumulativeHoldersRewardAmount.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateCalculateCumulativeHoldersRewardAmountCaller = ( + contract: Contract +) => (propertyAddress: string) => Promise + +export const createCalculateCumulativeHoldersRewardAmountCaller: CreateCalculateCumulativeHoldersRewardAmountCaller = + (contract: Contract) => async (propertyAddress: string) => + execute({ + contract, + method: 'calculateCumulativeHoldersRewardAmount', + args: [propertyAddress], + }) diff --git a/lib/l2/lockup/calculateCumulativeRewardPrices.spec.ts b/lib/l2/lockup/calculateCumulativeRewardPrices.spec.ts new file mode 100644 index 000000000..deec1d6fa --- /dev/null +++ b/lib/l2/lockup/calculateCumulativeRewardPrices.spec.ts @@ -0,0 +1,54 @@ +import { createCalculateCumulativeRewardPricesCaller } from './calculateCumulativeRewardPrices' + +describe('calculateCumulativeRewardPrices.spec.ts', () => { + describe('createCalculateCumulativeRewardPricesCaller', () => { + it('call success', async () => { + const value = ['value1', 'value2', 'value3', 'value4'] + + const lockupContract = { + methods: { + calculateCumulativeRewardPrices: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateCumulativeRewardPricesCaller( + lockupContract as any + ) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + calculateCumulativeRewardPrices: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateCumulativeRewardPricesCaller( + lockupContract as any + ) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/calculateCumulativeRewardPrices.ts b/lib/l2/lockup/calculateCumulativeRewardPrices.ts new file mode 100644 index 000000000..bb98bd19b --- /dev/null +++ b/lib/l2/lockup/calculateCumulativeRewardPrices.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' +import { arrayify } from '../../common/utils/arrayify' + +export type CreateCalculateCumulativeRewardPricesCaller = ( + contract: Contract +) => () => Promise + +export const createCalculateCumulativeRewardPricesCaller: CreateCalculateCumulativeRewardPricesCaller = + (contract: Contract) => + always( + execute>({ + contract, + method: 'calculateCumulativeRewardPrices', + }).then((r) => arrayify(r) as readonly [string, string, string, string]) + ) diff --git a/lib/l2/lockup/calculateRewardAmount.spec.ts b/lib/l2/lockup/calculateRewardAmount.spec.ts new file mode 100644 index 000000000..2d350ee45 --- /dev/null +++ b/lib/l2/lockup/calculateRewardAmount.spec.ts @@ -0,0 +1,57 @@ +import { createCalculateRewardAmountCaller } from './calculateRewardAmount' + +describe('calculateRewardAmount.spec.ts', () => { + describe('calculateRewardAmount', () => { + it('call success', async () => { + const value = ['value', 'value2'] + + const lockupContract = { + methods: { + calculateRewardAmount: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + propertyAddress: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateRewardAmountCaller(lockupContract as any) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + calculateRewardAmount: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + propertyAddress: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateRewardAmountCaller(lockupContract as any) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/calculateRewardAmount.ts b/lib/l2/lockup/calculateRewardAmount.ts new file mode 100644 index 000000000..9292ab874 --- /dev/null +++ b/lib/l2/lockup/calculateRewardAmount.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' + +export type CreateCalculateRewardAmountCaller = ( + contract: Contract +) => (propertyAddress: string) => Promise + +export const createCalculateRewardAmountCaller: CreateCalculateRewardAmountCaller = + (contract: Contract) => async (propertyAddress: string) => + execute>({ + contract, + method: 'calculateRewardAmount', + args: [propertyAddress], + }).then((r) => arrayify(r) as readonly [string, string]) diff --git a/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts b/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts new file mode 100644 index 000000000..9e176698b --- /dev/null +++ b/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.spec.ts @@ -0,0 +1,59 @@ +import { createcalculateWithdrawableInterestAmountByPositionCaller } from './calculateWithdrawableInterestAmountByPosition' + +describe('calculateWithdrawableInterestAmountByPosition.spec.ts', () => { + describe('createcalculateWithdrawableInterestAmountByPositionCaller', () => { + it('call success', async () => { + const value = 'value' + + const lockupContract = { + methods: { + calculateWithdrawableInterestAmountByPosition: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + positionTokenId: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createcalculateWithdrawableInterestAmountByPositionCaller( + lockupContract as any + ) + + const result = await caller('123') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + calculateWithdrawableInterestAmountByPosition: ( + // eslint-disable-next-line @typescript-eslint/no-unused-vars + positionTokenId: string + ) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createcalculateWithdrawableInterestAmountByPositionCaller( + lockupContract as any + ) + + const result = await caller('123').catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.ts b/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.ts new file mode 100644 index 000000000..a084fc460 --- /dev/null +++ b/lib/l2/lockup/calculateWithdrawableInterestAmountByPosition.ts @@ -0,0 +1,15 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreatecalculateWithdrawableInterestAmountByPositionCaller = ( + contract: Contract +) => (positionTokenId: string) => Promise + +export const createcalculateWithdrawableInterestAmountByPositionCaller: CreatecalculateWithdrawableInterestAmountByPositionCaller = + (contract: Contract) => async (positionTokenId: string) => + execute({ + contract, + method: 'calculateWithdrawableInterestAmountByPosition', + args: [positionTokenId], + }) diff --git a/lib/l2/lockup/cap.spec.ts b/lib/l2/lockup/cap.spec.ts new file mode 100644 index 000000000..f9758e484 --- /dev/null +++ b/lib/l2/lockup/cap.spec.ts @@ -0,0 +1,50 @@ +import { createCapCaller } from './cap' + +describe('cap.spec.ts', () => { + describe('createCapCaller', () => { + it('call success', async () => { + const value = 'value' + + const lockupContract = { + methods: { + cap: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCapCaller(lockupContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + cap: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCapCaller(lockupContract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/cap.ts b/lib/l2/lockup/cap.ts new file mode 100644 index 000000000..fa4981f3e --- /dev/null +++ b/lib/l2/lockup/cap.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateCapCaller = (contract: Contract) => () => Promise + +export const createCapCaller: CreateCapCaller = (contract: Contract) => + always(execute({ contract, method: 'cap' })) diff --git a/lib/l2/lockup/depositToPosition.spec.ts b/lib/l2/lockup/depositToPosition.spec.ts new file mode 100644 index 000000000..7d17fd8c4 --- /dev/null +++ b/lib/l2/lockup/depositToPosition.spec.ts @@ -0,0 +1,51 @@ +import { createDepositToPositionCaller } from './depositToPosition' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('depositToPosition.spec.ts', () => { + describe('createDepositToPositionCaller', () => { + it('call success', async () => { + const expected = true + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + depositToPosition: (tokenId: string, amount: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDepositToPositionCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller('32', '100') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + depositToPosition: (tokenId: string, amount: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDepositToPositionCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller('32', '100').catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/lockup/depositToPosition.ts b/lib/l2/lockup/depositToPosition.ts new file mode 100644 index 000000000..bc912249f --- /dev/null +++ b/lib/l2/lockup/depositToPosition.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateDepositToPositionCaller = ( + contract: Contract, + client: Web3 +) => (positionTokenId: string, amount: string) => Promise + +export const createDepositToPositionCaller: CreateDepositToPositionCaller = + (contract: Contract, client: Web3) => + async (positionTokenId: string, amount: string) => + execute({ + contract, + method: 'depositToPosition', + mutation: true, + client, + args: [positionTokenId, amount], + }).then(T) diff --git a/lib/l2/lockup/depositToProperty.spec.ts b/lib/l2/lockup/depositToProperty.spec.ts new file mode 100644 index 000000000..db4d0a32f --- /dev/null +++ b/lib/l2/lockup/depositToProperty.spec.ts @@ -0,0 +1,57 @@ +import { createDepositToPropertyCaller } from './depositToProperty' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('depositToProperty.spec.ts', () => { + describe('createDepositToPropertyCaller', () => { + it('call success', async () => { + const expected = true + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + depositToProperty: (property: string, amount: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDepositToPropertyCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '100' + ) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + depositToProperty: (property: string, amount: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createDepositToPropertyCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '100' + ).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/lockup/depositToProperty.ts b/lib/l2/lockup/depositToProperty.ts new file mode 100644 index 000000000..666a2ad99 --- /dev/null +++ b/lib/l2/lockup/depositToProperty.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateDepositToPropertyCaller = ( + contract: Contract, + client: Web3 +) => (propertyAddress: string, amount: string) => Promise + +export const createDepositToPropertyCaller: CreateDepositToPropertyCaller = + (contract: Contract, client: Web3) => + async (propertyAddress: string, amount: string) => + execute({ + contract, + method: 'depositToProperty', + mutation: true, + client, + args: [propertyAddress, amount], + }).then(T) diff --git a/lib/l2/lockup/index.spec.ts b/lib/l2/lockup/index.spec.ts new file mode 100644 index 000000000..a36471a83 --- /dev/null +++ b/lib/l2/lockup/index.spec.ts @@ -0,0 +1,75 @@ +import Web3 from 'web3' +import { createLockupContract, LockupContract } from '.' +import { lockupAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCalculateCumulativeHoldersRewardAmountCaller } from './calculateCumulativeHoldersRewardAmount' +import { createCalculateCumulativeRewardPricesCaller } from './calculateCumulativeRewardPrices' +import { createCalculateRewardAmountCaller } from './calculateRewardAmount' +import { createCapCaller } from './cap' +import { createDepositToPropertyCaller } from './depositToProperty' +import { createDepositToPositionCaller } from './depositToPosition' +import { createWithdrawByPositionCaller } from './withdrawByPosition' +import { createcalculateWithdrawableInterestAmountByPositionCaller } from './calculateWithdrawableInterestAmountByPosition' +import { createTotalLockedCaller } from './totalLocked' +import { createTotalLockedForPropertyCaller } from './totalLockedForProperty' + +describe('lockup/index.ts', () => { + describe('createLockupContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => LockupContract = (address?: string, options?: CustomOptions) => { + const lockupContract = new client.eth.Contract( + [...lockupAbi], + address, + { + ...options, + } + ) + return { + withdrawByPosition: createWithdrawByPositionCaller( + lockupContract, + client + ), + calculateWithdrawableInterestAmountByPosition: + createcalculateWithdrawableInterestAmountByPositionCaller( + lockupContract + ), + calculateCumulativeHoldersRewardAmount: + createCalculateCumulativeHoldersRewardAmountCaller(lockupContract), + calculateCumulativeRewardPrices: + createCalculateCumulativeRewardPricesCaller(lockupContract), + calculateRewardAmount: + createCalculateRewardAmountCaller(lockupContract), + cap: createCapCaller(lockupContract), + depositToProperty: createDepositToPropertyCaller( + lockupContract, + client + ), + depositToPosition: createDepositToPositionCaller( + lockupContract, + client + ), + totalLocked: createTotalLockedCaller(lockupContract), + totalLockedForProperty: + createTotalLockedForPropertyCaller(lockupContract), + contract: () => lockupContract, + } + } + + const result = createLockupContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/lockup/index.ts b/lib/l2/lockup/index.ts new file mode 100644 index 000000000..ee4e4fefa --- /dev/null +++ b/lib/l2/lockup/index.ts @@ -0,0 +1,86 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { lockupAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCalculateCumulativeHoldersRewardAmountCaller } from './calculateCumulativeHoldersRewardAmount' +import { createCalculateCumulativeRewardPricesCaller } from './calculateCumulativeRewardPrices' +import { createCalculateRewardAmountCaller } from './calculateRewardAmount' +import { createCapCaller } from './cap' +import { always } from 'ramda' +import { createDepositToPropertyCaller } from './depositToProperty' +import { createDepositToPositionCaller } from './depositToPosition' +import { createWithdrawByPositionCaller } from './withdrawByPosition' +import { createcalculateWithdrawableInterestAmountByPositionCaller } from './calculateWithdrawableInterestAmountByPosition' +import { createTotalLockedCaller } from './totalLocked' +import { createTotalLockedForPropertyCaller } from './totalLockedForProperty' + +export type LockupContract = { + readonly withdrawByPosition: ( + positionTokenId: string, + amount: string + ) => Promise + readonly calculateWithdrawableInterestAmountByPosition: ( + positionTokenId: string + ) => Promise + readonly calculateCumulativeHoldersRewardAmount: ( + propertyAddress: string + ) => Promise + readonly calculateCumulativeRewardPrices: () => Promise< + readonly [string, string, string, string] + > + readonly calculateRewardAmount: ( + propertyAddress: string + ) => Promise + readonly cap: () => Promise + readonly depositToProperty: ( + propertyAddress: string, + amount: string + ) => Promise + readonly depositToPosition: ( + positionTokenId: string, + amount: string + ) => Promise + readonly totalLocked: () => Promise + readonly totalLockedForProperty: (address: string) => Promise + readonly contract: () => Contract +} + +export type CreateLockupContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => LockupContract + +export const createLockupContract: CreateLockupContract = + (client: Web3) => + (address?: string, options?: CustomOptions): LockupContract => { + const contractClient: Contract = new client.eth.Contract( + [...lockupAbi], + address, + { + ...options, + } + ) + + return { + withdrawByPosition: createWithdrawByPositionCaller( + contractClient, + client + ), + calculateWithdrawableInterestAmountByPosition: + createcalculateWithdrawableInterestAmountByPositionCaller( + contractClient + ), + calculateCumulativeHoldersRewardAmount: + createCalculateCumulativeHoldersRewardAmountCaller(contractClient), + calculateCumulativeRewardPrices: + createCalculateCumulativeRewardPricesCaller(contractClient), + calculateRewardAmount: createCalculateRewardAmountCaller(contractClient), + cap: createCapCaller(contractClient), + depositToProperty: createDepositToPropertyCaller(contractClient, client), + depositToPosition: createDepositToPositionCaller(contractClient, client), + totalLocked: createTotalLockedCaller(contractClient), + totalLockedForProperty: + createTotalLockedForPropertyCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/lockup/totalLocked.spec.ts b/lib/l2/lockup/totalLocked.spec.ts new file mode 100644 index 000000000..ba6508a9d --- /dev/null +++ b/lib/l2/lockup/totalLocked.spec.ts @@ -0,0 +1,50 @@ +import { createTotalLockedCaller } from './totalLocked' + +describe('totalLocked.spec.ts', () => { + describe('createTotalLockedCaller', () => { + it('call success', async () => { + const value = 'value' + + const lockupContract = { + methods: { + totalLocked: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalLockedCaller(lockupContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + totalLocked: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalLockedCaller(lockupContract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/totalLocked.ts b/lib/l2/lockup/totalLocked.ts new file mode 100644 index 000000000..eb0ee47d3 --- /dev/null +++ b/lib/l2/lockup/totalLocked.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateTotalLockedCaller = ( + contract: Contract +) => () => Promise + +export const createTotalLockedCaller: CreateTotalLockedCaller = ( + contract: Contract +) => always(execute({ contract, method: 'totalLocked' })) diff --git a/lib/l2/lockup/totalLockedForProperty.spec.ts b/lib/l2/lockup/totalLockedForProperty.spec.ts new file mode 100644 index 000000000..9da74aa6c --- /dev/null +++ b/lib/l2/lockup/totalLockedForProperty.spec.ts @@ -0,0 +1,53 @@ +import { createTotalLockedForPropertyCaller } from './totalLockedForProperty' + +describe('totalLockedForProperty.spec.ts', () => { + describe('createTotalLockedForPropertyCaller', () => { + it('call success', async () => { + const value = 'value' + + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + totalLockedForProperty: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalLockedForPropertyCaller(lockupContract as any) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + totalLockedForProperty: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTotalLockedForPropertyCaller(lockupContract as any) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/lockup/totalLockedForProperty.ts b/lib/l2/lockup/totalLockedForProperty.ts new file mode 100644 index 000000000..bad4abb2b --- /dev/null +++ b/lib/l2/lockup/totalLockedForProperty.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateTotalLockedForPropertyCaller = ( + contract: Contract +) => (address: string) => Promise + +export const createTotalLockedForPropertyCaller: CreateTotalLockedForPropertyCaller = + (contract: Contract) => async (address: string) => + execute({ contract, method: 'totalLockedForProperty', args: [address] }) diff --git a/lib/l2/lockup/withdrawByPosition.spec.ts b/lib/l2/lockup/withdrawByPosition.spec.ts new file mode 100644 index 000000000..f84839be3 --- /dev/null +++ b/lib/l2/lockup/withdrawByPosition.spec.ts @@ -0,0 +1,51 @@ +import { createWithdrawByPositionCaller } from './withdrawByPosition' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('withdrawByPosition.spec.ts', () => { + describe('createWithdrawByPositionCaller', () => { + it('call success', async () => { + const expected = true + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + withdrawByPosition: (tokenId: string, amount: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createWithdrawByPositionCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller('32', '100') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const lockupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + withdrawByPosition: (tokenId: string, amount: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createWithdrawByPositionCaller( + lockupContract as any, + stubbedWeb3 + ) + + const result = await caller('32', '100').catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/lockup/withdrawByPosition.ts b/lib/l2/lockup/withdrawByPosition.ts new file mode 100644 index 000000000..21c1b38a2 --- /dev/null +++ b/lib/l2/lockup/withdrawByPosition.ts @@ -0,0 +1,21 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateWithdrawByPositionCaller = ( + contract: Contract, + client: Web3 +) => (positionTokenId: string, amount: string) => Promise + +export const createWithdrawByPositionCaller: CreateWithdrawByPositionCaller = + (contract: Contract, client: Web3) => + async (positionTokenId: string, amount: string) => + execute({ + contract, + method: 'withdrawByPosition', + mutation: true, + client, + args: [positionTokenId, amount], + }).then(T) diff --git a/lib/l2/market-factory/abi.ts b/lib/l2/market-factory/abi.ts new file mode 100644 index 000000000..0085bee6a --- /dev/null +++ b/lib/l2/market-factory/abi.ts @@ -0,0 +1,184 @@ +import { AbiItem } from 'web3-utils' + +export const marketFactoryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_market', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_from', + type: 'address', + }, + ], + name: 'Create', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'isMarket', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'isPotentialMarket', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'marketsCount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_addr', + type: 'address', + }, + ], + name: 'create', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_addr', + type: 'address', + }, + ], + name: 'enable', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/market-factory/create.spec.ts b/lib/l2/market-factory/create.spec.ts new file mode 100644 index 000000000..6b36a5ef5 --- /dev/null +++ b/lib/l2/market-factory/create.spec.ts @@ -0,0 +1,53 @@ +import { createCreateCaller } from './create' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('create.spec.ts', () => { + describe('createCreateCaller', () => { + it('call success', async () => { + const expected = true + const marketFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (marketBehaviorAddress: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreateCaller( + marketFactoryContract as any, + stubbedWeb3 + ) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const marketFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (marketBehaviorAddress: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreateCaller( + marketFactoryContract as any, + stubbedWeb3 + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/market-factory/create.ts b/lib/l2/market-factory/create.ts new file mode 100644 index 000000000..2f20c6669 --- /dev/null +++ b/lib/l2/market-factory/create.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateCreateCaller = ( + contract: Contract, + client: Web3 +) => (marketBehaviorAddress: string) => Promise + +export const createCreateCaller: CreateCreateCaller = + (contract: Contract, client: Web3) => async (marketBehaviorAddress: string) => + execute({ + contract, + method: 'create', + mutation: true, + client, + args: [marketBehaviorAddress], + }).then(T) diff --git a/lib/l2/market-factory/index.spec.ts b/lib/l2/market-factory/index.spec.ts new file mode 100644 index 000000000..e83ba6421 --- /dev/null +++ b/lib/l2/market-factory/index.spec.ts @@ -0,0 +1,44 @@ +import Web3 from 'web3' +import { createMarketFactoryContract, MarketFactoryContract } from '.' +import { marketFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCreateCaller } from './create' + +describe('market-factory/index.ts', () => { + describe('createMarketFactoryContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => MarketFactoryContract = ( + address?: string, + options?: CustomOptions + ) => { + const marketFactoryContract = new client.eth.Contract( + [...marketFactoryAbi], + address, + { + ...options, + } + ) + return { + create: createCreateCaller(marketFactoryContract, client), + contract: () => marketFactoryContract, + } + } + + const result = createMarketFactoryContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/market-factory/index.ts b/lib/l2/market-factory/index.ts new file mode 100644 index 000000000..0a70bd2d3 --- /dev/null +++ b/lib/l2/market-factory/index.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { marketFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCreateCaller } from './create' +import { always } from 'ramda' + +export type MarketFactoryContract = { + readonly create: (marketBehaviorAddress: string) => Promise + readonly contract: () => Contract +} + +export type CreateMarketFactoryContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => MarketFactoryContract + +export const createMarketFactoryContract: CreateMarketFactoryContract = + (client: Web3) => + (address?: string, options?: CustomOptions): MarketFactoryContract => { + const contractClient: Contract = new client.eth.Contract( + [...marketFactoryAbi], + address, + { + ...options, + } + ) + + return { + create: createCreateCaller(contractClient, client), + contract: always(contractClient), + } + } diff --git a/lib/l2/market/abi.ts b/lib/l2/market/abi.ts new file mode 100644 index 000000000..1420c4cb5 --- /dev/null +++ b/lib/l2/market/abi.ts @@ -0,0 +1,208 @@ +import { AbiItem } from 'web3-utils' + +export const marketAbi = [ + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + { + internalType: 'address', + name: '_behavior', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'behavior', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'enabled', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'issuedMetrics', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'votingEndTimestamp', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'toEnable', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_prop', + type: 'address', + }, + { + internalType: 'string[]', + name: '_args', + type: 'string[]', + }, + ], + name: 'authenticate', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_prop', + type: 'address', + }, + { + internalType: 'address', + name: '_author', + type: 'address', + }, + { + internalType: 'string[]', + name: '_args', + type: 'string[]', + }, + ], + name: 'authenticateFromPropertyFactory', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + { + internalType: 'bytes32', + name: '_idHash', + type: 'bytes32', + }, + ], + name: 'authenticatedCallback', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_metrics', + type: 'address', + }, + ], + name: 'deauthenticate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'schema', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/market/authenticate.spec.ts b/lib/l2/market/authenticate.spec.ts new file mode 100644 index 000000000..7f52840cd --- /dev/null +++ b/lib/l2/market/authenticate.spec.ts @@ -0,0 +1,157 @@ +/* eslint-disable functional/no-this-expression */ +/* eslint-disable functional/no-conditional-statement */ +/* eslint-disable functional/no-class */ +/* eslint-disable @typescript-eslint/promise-function-async */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { createAuthenticateCaller } from './authenticate' +import { stubbedWeb3 } from '../../common/utils/for-test' +import { Event } from '../../common/utils/web3-txs' +import Web3 from 'web3' +import { marketAbi } from './abi' + +describe('authenticate.ts', () => { + describe('createAuthenticateCaller', () => { + it('call success', async () => { + const value = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const args = ['aaa', 'bbbb', 'ccccc'] + + const client = { + eth: { + ...{ + Contract: class { + public readonly abi: any + public readonly address: string + public readonly methods: any + public readonly events = { + allEvents( + opts: any, + callback: (err: Error | null, e: Event) => void + ) { + setTimeout(() => { + callback(null, { + event: 'Create', + returnValues: { _metrics: value }, + } as unknown as Event) + }, 800) + }, + } + + constructor(abi: string, address: string) { + this.abi = abi + this.address = address + + if (this.abi.some(({ name = '' }) => name === 'authenticate')) { + // Market Contract + this.methods = { + authenticate: (...args: readonly any[]) => ({ + send: async () => { + // eslint-disable-next-line no-extend-native + ;(Promise.prototype as any).on = function () { + return this + } + + return new Promise(() => true) + }, + }), + } + } else { + // Metrics Contract + this.methods = { + property: (...args: readonly any[]) => ({ + call: async () => Promise.resolve(propertyAddress), + }), + } + } + } + }, + getBlockNumber: () => Promise.resolve(123), + }, + ...stubbedWeb3.eth, + }, + } as unknown as Web3 + + const expected = value + + const caller = createAuthenticateCaller( + new client.eth.Contract([...marketAbi], '0x...'), + client + ) + + const result = await caller(propertyAddress, args, { + metricsFactory: '0x...', + }) + + expect(result).toEqual(expected) + }) + + it('method call failure', async () => { + const error = 'error' + + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const args = ['aaa', 'bbbb', 'ccccc'] + + const client = { + eth: { + ...{ + Contract: class { + public readonly abi: any + public readonly address: string + public readonly methods: any + public readonly events = { + allEvents() { + // Nothing + }, + } + + constructor(abi: string, address: string) { + this.abi = abi + this.address = address + + if (this.abi.some(({ name = '' }) => name === 'authenticate')) { + // Market Contract + this.methods = { + authenticate: (...args: readonly any[]) => ({ + send: async () => { + // eslint-disable-next-line no-extend-native + ;(Promise.prototype as any).on = function () { + return this + } + + return Promise.reject(error) + }, + }), + } + } else { + // Metrics Contract + this.methods = { + property: (...args: readonly any[]) => ({ + call: async () => Promise.resolve(propertyAddress), + }), + } + } + } + }, + getBlockNumber: () => Promise.resolve(123), + }, + ...stubbedWeb3.eth, + }, + } as unknown as Web3 + + const caller = createAuthenticateCaller( + new client.eth.Contract([...marketAbi], '0x...'), + client + ) + + const result = await caller(propertyAddress, args, { + metricsFactory: '0x..', + }).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/market/authenticate.ts b/lib/l2/market/authenticate.ts new file mode 100644 index 000000000..f51ed7ff5 --- /dev/null +++ b/lib/l2/market/authenticate.ts @@ -0,0 +1,42 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { waitForCreateMetrics } from '../../common/utils/waitForCreateMetrics' + +export type WaitForEventOptions = { + readonly metricsFactory: string +} + +export type CreateAuthenticateCaller = ( + contract: Contract, + client: Web3 +) => ( + propertyAddress: string, + args: readonly string[], + options: WaitForEventOptions +) => Promise + +export const createAuthenticateCaller: CreateAuthenticateCaller = + (contract: Contract, client: Web3) => + async ( + propertyAddress: string, + args: readonly string[], + { metricsFactory }: WaitForEventOptions + ): Promise => + new Promise((resolve, reject) => { + // eslint-disable-next-line functional/no-expression-statement + execute({ + contract, + method: 'authenticate', + mutation: true, + client, + args: [propertyAddress, ...args], + padEnd: 6, + }).catch(reject) + + // eslint-disable-next-line functional/no-expression-statement + waitForCreateMetrics(client, propertyAddress, metricsFactory) + .then(resolve) + .catch(reject) + }) diff --git a/lib/l2/market/behavior.spec.ts b/lib/l2/market/behavior.spec.ts new file mode 100644 index 000000000..289b74618 --- /dev/null +++ b/lib/l2/market/behavior.spec.ts @@ -0,0 +1,49 @@ +import { createBehaviorCaller } from './behavior' + +describe('behavior.spec.ts', () => { + describe('createBehaviorCaller', () => { + it('call success', async () => { + const value = '0x0000.........' + + const contract = { + methods: { + behavior: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createBehaviorCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + behavior: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createBehaviorCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/market/behavior.ts b/lib/l2/market/behavior.ts new file mode 100644 index 000000000..f4c88ff34 --- /dev/null +++ b/lib/l2/market/behavior.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateBehaviorCaller = (contract: Contract) => () => Promise + +export const createBehaviorCaller: CreateBehaviorCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'behavior', + }) + ) diff --git a/lib/l2/market/index.spec.ts b/lib/l2/market/index.spec.ts new file mode 100644 index 000000000..e20aae569 --- /dev/null +++ b/lib/l2/market/index.spec.ts @@ -0,0 +1,50 @@ +import Web3 from 'web3' +import { createMarketContract, CreateMarketContract } from '.' +import { createSchemaCaller } from './schema' +import { createVoteCaller } from './vote' +import { CustomOptions } from '../../common/option' +import { marketAbi } from './abi' +import { createAuthenticateCaller } from './authenticate' +import { createBehaviorCaller } from './behavior' + +describe('market.ts', () => { + describe('createMarketContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => CreateMarketContract = ( + address?: string, + options?: CustomOptions + ) => { + const marketContract = new client.eth.Contract( + [...marketAbi], + address, + { + ...options, + } + ) + return { + behavior: createBehaviorCaller(marketContract), + schema: createSchemaCaller(marketContract), + vote: createVoteCaller(marketContract, client), + authenticate: createAuthenticateCaller(marketContract, client), + contract: () => marketContract, + } + } + + const result = createMarketContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/market/index.ts b/lib/l2/market/index.ts new file mode 100644 index 000000000..9ee6bfa63 --- /dev/null +++ b/lib/l2/market/index.ts @@ -0,0 +1,45 @@ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { marketAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createSchemaCaller } from './schema' +import { createVoteCaller } from './vote' +import { createBehaviorCaller } from './behavior' +import { createAuthenticateCaller } from './authenticate' +import { TxReceipt } from '../../common/utils/web3-txs' +import { always } from 'ramda' + +export type CreateMarketContract = { + readonly schema: () => Promise + readonly behavior: () => Promise + readonly vote: (propertyAddress: string, agree: boolean) => Promise + readonly authenticate: ( + address: string, + args: readonly string[], + options: { + readonly metricsFactory: string + } + ) => Promise + readonly contract: () => Contract +} + +// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types +export const createMarketContract = + (client: Web3) => + (address?: string, options?: CustomOptions): CreateMarketContract => { + const contractClient: Contract = new client.eth.Contract( + [...marketAbi], + address, + { + ...options, + } + ) + + return { + behavior: createBehaviorCaller(contractClient), + schema: createSchemaCaller(contractClient), + vote: createVoteCaller(contractClient, client), + authenticate: createAuthenticateCaller(contractClient, client), + contract: always(contractClient), + } + } diff --git a/lib/l2/market/schema.spec.ts b/lib/l2/market/schema.spec.ts new file mode 100644 index 000000000..374d6ce0c --- /dev/null +++ b/lib/l2/market/schema.spec.ts @@ -0,0 +1,70 @@ +import { createSchemaCaller } from './schema' + +describe('schema.ts', () => { + describe('createSchemaCaller', () => { + it('call success', async () => { + const value = `["aaa","bbbb","cccc"]` + const expected = ['aaa', 'bbbb', 'cccc'] + + const marketContract = { + methods: { + schema: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createSchemaCaller(marketContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('returns a correct array even if the value is using a single quoted string array', async () => { + const value = `['aaa',"bbbb",'cccc']` + const expected = ['aaa', 'bbbb', 'cccc'] + + const marketContract = { + methods: { + schema: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createSchemaCaller(marketContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const marketContract = { + methods: { + schema: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createSchemaCaller(marketContract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/market/schema.ts b/lib/l2/market/schema.ts new file mode 100644 index 000000000..6ecebcbcd --- /dev/null +++ b/lib/l2/market/schema.ts @@ -0,0 +1,27 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateSchemaCaller = ( + contract: Contract +) => () => Promise +type ParsedValue = { + readonly v: string + readonly s: boolean +} + +export const createSchemaCaller: CreateSchemaCaller = ( + contract: Contract +): (() => Promise) => + always( + execute({ contract, method: 'schema' }).then( + (result) => + JSON.parse( + result + .split(`'`) + .map((v) => ({ v, s: /[[\],:]/.test(v) })) + .reduce((a, c) => `${a}${c.s ? c.v : `"${c.v}"`}`, '') + ) as readonly string[] + ) + ) diff --git a/lib/l2/market/vote.spec.ts b/lib/l2/market/vote.spec.ts new file mode 100644 index 000000000..26b58f16b --- /dev/null +++ b/lib/l2/market/vote.spec.ts @@ -0,0 +1,51 @@ +import { createVoteCaller } from './vote' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' +import { txPromisify } from '../../common/utils/txPromisify' + +describe('vote.ts', () => { + describe('createVoteCaller', () => { + it('call success', async () => { + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const marketContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + vote: (propertyAddress: string, agree: boolean) => ({ + /* eslint-disable */ + send: jest.fn().mockImplementation(async () => stubbedSendTx()), + /* eslint-enable */ + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createVoteCaller(marketContract as any, stubbedWeb3) + + const result = await caller(propertyAddress, true) + + expect(result).toEqual(await txPromisify(stubbedSendTx())) + }) + + it('call failure', async () => { + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const marketContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + vote: (propertyAddress: string, agree: boolean) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createVoteCaller(marketContract as any, stubbedWeb3) + + const result = await caller(propertyAddress, true).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/market/vote.ts b/lib/l2/market/vote.ts new file mode 100644 index 000000000..5e35d7f8e --- /dev/null +++ b/lib/l2/market/vote.ts @@ -0,0 +1,24 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { TxReceipt } from '../../common/utils/web3-txs' + +export type CreateVoteCaller = ( + contract: Contract, + client: Web3 +) => (propertyAddress: string, agree: boolean) => Promise + +export const createVoteCaller: CreateVoteCaller = + ( + contract: Contract, + client: Web3 + ): ((propertyAddress: string, agree: boolean) => Promise) => + async (propertyAddress: string, agree: boolean): Promise => + execute({ + contract, + method: 'vote', + mutation: true, + client, + args: [propertyAddress, agree], + }) diff --git a/lib/l2/metrics-factory/abi.ts b/lib/l2/metrics-factory/abi.ts new file mode 100644 index 000000000..08d56f00c --- /dev/null +++ b/lib/l2/metrics-factory/abi.ts @@ -0,0 +1,195 @@ +import { AbiItem } from 'web3-utils' + +export const metricsFactoryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_market', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_metrics', + type: 'address', + }, + ], + name: 'Create', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_market', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_metrics', + type: 'address', + }, + ], + name: 'Destroy', + type: 'event', + }, + { + inputs: [], + name: 'authenticatedPropertiesCount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'isMetrics', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'metricsCount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'metricsCountPerProperty', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'create', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_metrics', + type: 'address', + }, + ], + name: 'destroy', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'hasAssets', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/metrics-factory/authenticatedPropertiesCount.spec.ts b/lib/l2/metrics-factory/authenticatedPropertiesCount.spec.ts new file mode 100644 index 000000000..463465149 --- /dev/null +++ b/lib/l2/metrics-factory/authenticatedPropertiesCount.spec.ts @@ -0,0 +1,54 @@ +import { createAuthenticatedPropertiesCountCaller } from './authenticatedPropertiesCount' + +describe('authenticatedPropertiesCount.spec.ts', () => { + describe('createAuthenticatedPropertiesCountCaller', () => { + it('call success', async () => { + const value = 'value' + + const metricsFactoryContract = { + methods: { + authenticatedPropertiesCount: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthenticatedPropertiesCountCaller( + metricsFactoryContract as any + ) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const metricsGroupContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + authenticatedPropertiesCount: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthenticatedPropertiesCountCaller( + metricsGroupContract as any + ) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/metrics-factory/authenticatedPropertiesCount.ts b/lib/l2/metrics-factory/authenticatedPropertiesCount.ts new file mode 100644 index 000000000..f751bb6b5 --- /dev/null +++ b/lib/l2/metrics-factory/authenticatedPropertiesCount.ts @@ -0,0 +1,12 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateAuthenticatedPropertiesCountCaller = ( + contract: Contract +) => () => Promise + +export const createAuthenticatedPropertiesCountCaller: CreateAuthenticatedPropertiesCountCaller = + (contract: Contract) => + always(execute({ contract, method: 'authenticatedPropertiesCount' })) diff --git a/lib/l2/metrics-factory/index.spec.ts b/lib/l2/metrics-factory/index.spec.ts new file mode 100644 index 000000000..8eeea8c94 --- /dev/null +++ b/lib/l2/metrics-factory/index.spec.ts @@ -0,0 +1,45 @@ +import Web3 from 'web3' +import { createMetricsFactoryContract, CreateMetricsFactoryContract } from '.' +import { CustomOptions } from '../../common/option' +import { metricsFactoryAbi } from './abi' +import { createAuthenticatedPropertiesCountCaller } from './authenticatedPropertiesCount' + +describe('metrics-factory.ts', () => { + describe('createMetricsFactoryContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => CreateMetricsFactoryContract = ( + address?: string, + options?: CustomOptions + ) => { + const metricsFactoryContract = new client.eth.Contract( + [...metricsFactoryAbi], + address, + { + ...options, + } + ) + return { + authenticatedPropertiesCount: + createAuthenticatedPropertiesCountCaller(metricsFactoryContract), + contract: () => metricsFactoryContract, + } + } + + const result = createMetricsFactoryContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/metrics-factory/index.ts b/lib/l2/metrics-factory/index.ts new file mode 100644 index 000000000..b44a0f1d0 --- /dev/null +++ b/lib/l2/metrics-factory/index.ts @@ -0,0 +1,30 @@ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { metricsFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createAuthenticatedPropertiesCountCaller } from './authenticatedPropertiesCount' +import { always } from 'ramda' + +export type CreateMetricsFactoryContract = { + readonly authenticatedPropertiesCount: () => Promise + readonly contract: () => Contract +} + +// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types +export const createMetricsFactoryContract = + (client: Web3) => + (address?: string, options?: CustomOptions): CreateMetricsFactoryContract => { + const contractClient: Contract = new client.eth.Contract( + [...metricsFactoryAbi], + address, + { + ...options, + } + ) + + return { + authenticatedPropertiesCount: + createAuthenticatedPropertiesCountCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/metrics/abi.ts b/lib/l2/metrics/abi.ts new file mode 100644 index 000000000..e740a320a --- /dev/null +++ b/lib/l2/metrics/abi.ts @@ -0,0 +1,46 @@ +import { AbiItem } from 'web3-utils' + +export const metricsAbi = [ + { + inputs: [ + { + internalType: 'address', + name: '_market', + type: 'address', + }, + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'market', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'property', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/metrics/index.spec.ts b/lib/l2/metrics/index.spec.ts new file mode 100644 index 000000000..baca64eec --- /dev/null +++ b/lib/l2/metrics/index.spec.ts @@ -0,0 +1,46 @@ +import Web3 from 'web3' +import { CustomOptions } from '../../common/option' +import { createMetricsContract, CreateMetricsContract } from '.' +import { createPropertyCaller } from './property' +import { createMarketCaller } from './market' +import { metricsAbi } from './abi' + +describe('allocator/index.ts', () => { + describe('createAllocatorContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => CreateMetricsContract = ( + address?: string, + options?: CustomOptions + ) => { + const metricsContract = new client.eth.Contract( + [...metricsAbi], + address, + { + ...options, + } + ) + return { + property: createPropertyCaller(metricsContract), + market: createMarketCaller(metricsContract), + contract: () => metricsContract, + } + } + + const result = createMetricsContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/metrics/index.ts b/lib/l2/metrics/index.ts new file mode 100644 index 000000000..9aa236967 --- /dev/null +++ b/lib/l2/metrics/index.ts @@ -0,0 +1,32 @@ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { metricsAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createPropertyCaller } from './property' +import { createMarketCaller } from './market' +import { always } from 'ramda' + +export type CreateMetricsContract = { + readonly property: () => Promise + readonly market: () => Promise + readonly contract: () => Contract +} + +// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types +export const createMetricsContract = + (client: Web3) => + (address?: string, options?: CustomOptions): CreateMetricsContract => { + const contractClient: Contract = new client.eth.Contract( + [...metricsAbi], + address, + { + ...options, + } + ) + + return { + property: createPropertyCaller(contractClient), + market: createMarketCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/metrics/market.spec.ts b/lib/l2/metrics/market.spec.ts new file mode 100644 index 000000000..4c3cc9a10 --- /dev/null +++ b/lib/l2/metrics/market.spec.ts @@ -0,0 +1,49 @@ +import { createMarketCaller } from './market' + +describe('market.spec.ts', () => { + describe('createMarketCaller', () => { + it('call success', async () => { + const value = '0x0000.........' + + const contract = { + methods: { + market: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createMarketCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + market: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createMarketCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/metrics/market.ts b/lib/l2/metrics/market.ts new file mode 100644 index 000000000..58474e652 --- /dev/null +++ b/lib/l2/metrics/market.ts @@ -0,0 +1,14 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateMarketCaller = (contract: Contract) => () => Promise + +export const createMarketCaller: CreateMarketCaller = (contract: Contract) => + always( + execute({ + contract, + method: 'market', + }) + ) diff --git a/lib/l2/metrics/property.spec.ts b/lib/l2/metrics/property.spec.ts new file mode 100644 index 000000000..57c07bae5 --- /dev/null +++ b/lib/l2/metrics/property.spec.ts @@ -0,0 +1,49 @@ +import { createPropertyCaller } from './property' + +describe('property.spec.ts', () => { + describe('createPropertyCaller', () => { + it('call success', async () => { + const value = '0x0000.........' + + const contract = { + methods: { + property: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPropertyCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + property: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPropertyCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/metrics/property.ts b/lib/l2/metrics/property.ts new file mode 100644 index 000000000..08699c226 --- /dev/null +++ b/lib/l2/metrics/property.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreatePropertyCaller = (contract: Contract) => () => Promise + +export const createPropertyCaller: CreatePropertyCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'property', + }) + ) diff --git a/lib/l2/policy-factory/abi.ts b/lib/l2/policy-factory/abi.ts new file mode 100644 index 000000000..b3cfd5a0f --- /dev/null +++ b/lib/l2/policy-factory/abi.ts @@ -0,0 +1,184 @@ +import { AbiItem } from 'web3-utils' + +export const policyFactoryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_from', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_policy', + type: 'address', + }, + ], + name: 'Create', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'closeVoteAt', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'isPotentialPolicy', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_newPolicyAddress', + type: 'address', + }, + ], + name: 'create', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_policy', + type: 'address', + }, + ], + name: 'forceAttach', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_policy', + type: 'address', + }, + ], + name: 'isDuringVotingPeriod', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/policy-factory/create.spec.ts b/lib/l2/policy-factory/create.spec.ts new file mode 100644 index 000000000..fde629424 --- /dev/null +++ b/lib/l2/policy-factory/create.spec.ts @@ -0,0 +1,51 @@ +import { createCreateCaller } from './create' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('deposit.spec.ts', () => { + describe('createDepositCaller', () => { + it('call success', async () => { + const success = true + const policy = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const devContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (newPolicyAddress: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = success + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreateCaller(devContract as any, stubbedWeb3) + + const result = await caller(policy) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const policy = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const devContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (newPolicyAddress: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreateCaller(devContract as any, stubbedWeb3) + + const result = await caller(policy).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/policy-factory/create.ts b/lib/l2/policy-factory/create.ts new file mode 100644 index 000000000..1719b921c --- /dev/null +++ b/lib/l2/policy-factory/create.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateCreateCaller = ( + contract: Contract, + client: Web3 +) => (newPolicyAddress: string) => Promise + +export const createCreateCaller: CreateCreateCaller = + (contract: Contract, client: Web3) => async (newPolicyAddress: string) => + execute({ + contract, + method: 'create', + mutation: true, + client, + args: [newPolicyAddress], + }).then(T) diff --git a/lib/l2/policy-factory/forceAttach.spec.ts b/lib/l2/policy-factory/forceAttach.spec.ts new file mode 100644 index 000000000..e85ed749c --- /dev/null +++ b/lib/l2/policy-factory/forceAttach.spec.ts @@ -0,0 +1,51 @@ +import { createForceAttachCaller } from './forceAttach' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('forceAttach.spec.ts', () => { + describe('createForceAttachCaller', () => { + it('call success', async () => { + const success = true + const policy = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const devContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + forceAttach: (policy: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = success + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createForceAttachCaller(devContract as any, stubbedWeb3) + + const result = await caller(policy) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const policy = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const devContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + forceAttach: (policy: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createForceAttachCaller(devContract as any, stubbedWeb3) + + const result = await caller(policy).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/policy-factory/forceAttach.ts b/lib/l2/policy-factory/forceAttach.ts new file mode 100644 index 000000000..56d31e81c --- /dev/null +++ b/lib/l2/policy-factory/forceAttach.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateForceAttachCaller = ( + contract: Contract, + client: Web3 +) => (policy: string) => Promise + +export const createForceAttachCaller: CreateForceAttachCaller = + (contract: Contract, client: Web3) => async (policy: string) => + execute({ + contract, + method: 'forceAttach', + mutation: true, + client, + args: [policy], + }).then(T) diff --git a/lib/l2/policy-factory/index.spec.ts b/lib/l2/policy-factory/index.spec.ts new file mode 100644 index 000000000..32ef2f070 --- /dev/null +++ b/lib/l2/policy-factory/index.spec.ts @@ -0,0 +1,47 @@ +import Web3 from 'web3' +import { createPolicyFactoryContract, PolicyFactoryContract } from '.' +import { policyFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCreateCaller } from './create' +import { createForceAttachCaller } from './forceAttach' + +describe('policy/index.ts', () => { + describe('createPolicyContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => PolicyFactoryContract = ( + address?: string, + options?: CustomOptions + ) => { + const policyContract = new client.eth.Contract( + [...policyFactoryAbi], + address, + { + ...options, + } + ) + + return { + create: createCreateCaller(policyContract, client), + forceAttach: createForceAttachCaller(policyContract, client), + contract: () => policyContract, + } + } + + const result = createPolicyFactoryContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/policy-factory/index.ts b/lib/l2/policy-factory/index.ts new file mode 100644 index 000000000..9583fafb0 --- /dev/null +++ b/lib/l2/policy-factory/index.ts @@ -0,0 +1,35 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { policyFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { always } from 'ramda' +import { createCreateCaller } from './create' +import { createForceAttachCaller } from './forceAttach' + +export type PolicyFactoryContract = { + readonly create: (newPolicyAddress: string) => Promise + readonly forceAttach: (policy: string) => Promise + readonly contract: () => Contract +} + +export type CreatePolicyFactoryContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => PolicyFactoryContract + +export const createPolicyFactoryContract: CreatePolicyFactoryContract = + (client: Web3) => (address?: string, options?: CustomOptions) => { + const contractClient: Contract = new client.eth.Contract( + [...policyFactoryAbi], + address, + { + ...options, + } + ) + + return { + create: createCreateCaller(contractClient, client), + forceAttach: createForceAttachCaller(contractClient, client), + contract: always(contractClient), + } + } diff --git a/lib/l2/policy/abi.ts b/lib/l2/policy/abi.ts new file mode 100644 index 000000000..6a54ed517 --- /dev/null +++ b/lib/l2/policy/abi.ts @@ -0,0 +1,121 @@ +import { AbiItem } from 'web3-utils' + +export const policyAbi = [ + { + inputs: [ + { + internalType: 'uint256', + name: '_lockups', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_assets', + type: 'uint256', + }, + ], + name: 'rewards', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_lockups', + type: 'uint256', + }, + ], + name: 'holdersShare', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_assets', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_propertyAssets', + type: 'uint256', + }, + ], + name: 'authenticationFee', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'marketVotingSeconds', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'policyVotingSeconds', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_supply', + type: 'uint256', + }, + ], + name: 'shareOfTreasury', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/policy/authenticationFee.spec.ts b/lib/l2/policy/authenticationFee.spec.ts new file mode 100644 index 000000000..c5bb5e8df --- /dev/null +++ b/lib/l2/policy/authenticationFee.spec.ts @@ -0,0 +1,51 @@ +import { createAuthenticationFeeCaller } from './authenticationFee' + +describe('authenticationFee.spec.ts', () => { + describe('createAuthenticationFeeCaller', () => { + it('call success', async () => { + const value = '12345' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + authenticationFee: (assets: string, propertyAssets: string) => ({ + call: jest.fn().mockImplementation(async () => value), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthenticationFeeCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + authenticationFee: (assets: string, propertyAssets: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthenticationFeeCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222').catch( + (err) => err + ) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/authenticationFee.ts b/lib/l2/policy/authenticationFee.ts new file mode 100644 index 000000000..d8a333c81 --- /dev/null +++ b/lib/l2/policy/authenticationFee.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateAuthenticationFeeCaller = ( + contract: Contract +) => (assets: string, propertyAssets: string) => Promise + +export const createAuthenticationFeeCaller: CreateAuthenticationFeeCaller = + (contract: Contract) => + async (assets: string, propertyAssets: string): Promise => + execute({ + contract, + method: 'authenticationFee', + args: [assets, propertyAssets], + }) diff --git a/lib/l2/policy/capSetter.spec.ts b/lib/l2/policy/capSetter.spec.ts new file mode 100644 index 000000000..590948b56 --- /dev/null +++ b/lib/l2/policy/capSetter.spec.ts @@ -0,0 +1,49 @@ +import { createCapSetterCaller } from './capSetter' + +describe('capSetter.spec.ts', () => { + describe('createCapSetterCaller', () => { + it('call success', async () => { + const value = '1111' + + const contract = { + methods: { + capSetter: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCapSetterCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + capSetter: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCapSetterCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/capSetter.ts b/lib/l2/policy/capSetter.ts new file mode 100644 index 000000000..e71e255e9 --- /dev/null +++ b/lib/l2/policy/capSetter.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateCapSetterCaller = ( + contract: Contract +) => () => Promise + +export const createCapSetterCaller: CreateCapSetterCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'capSetter', + }) + ) diff --git a/lib/l2/policy/holdersShare.spec.ts b/lib/l2/policy/holdersShare.spec.ts new file mode 100644 index 000000000..7361f3497 --- /dev/null +++ b/lib/l2/policy/holdersShare.spec.ts @@ -0,0 +1,51 @@ +import { createHoldersShareCaller } from './holdersShare' + +describe('holdersShare.spec.ts', () => { + describe('createHoldersShareCaller', () => { + it('call success', async () => { + const value = '12345' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + holdersShare: (amount: string, lockups: string) => ({ + call: jest.fn().mockImplementation(async () => value), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createHoldersShareCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + holdersShare: (amount: string, lockups: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createHoldersShareCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222').catch( + (err) => err + ) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/holdersShare.ts b/lib/l2/policy/holdersShare.ts new file mode 100644 index 000000000..f7d7a0026 --- /dev/null +++ b/lib/l2/policy/holdersShare.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateHoldersShareCaller = ( + contract: Contract +) => (amount: string, lockups: string) => Promise + +export const createHoldersShareCaller: CreateHoldersShareCaller = + (contract: Contract) => + async (amount: string, lockups: string): Promise => + execute({ + contract, + method: 'holdersShare', + args: [amount, lockups], + }) diff --git a/lib/l2/policy/index.spec.ts b/lib/l2/policy/index.spec.ts new file mode 100644 index 000000000..b27556e40 --- /dev/null +++ b/lib/l2/policy/index.spec.ts @@ -0,0 +1,56 @@ +import Web3 from 'web3' +import { createPolicyContract, PolicyContract } from '.' +import { policyAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createHoldersShareCaller } from './holdersShare' +import { createRewardsCaller } from './rewards' +import { createAuthenticationFeeCaller } from './authenticationFee' +import { createMarketVotingBlocksCaller } from './marketVotingBlocks' +import { createPolicyVotingBlocksCaller } from './policyVotingBlocks' +import { createShareOfTreasuryCaller } from './shareOfTreasury' +import { createTreasuryCaller } from './treasury' +import { createCapSetterCaller } from './capSetter' + +describe('policy/index.ts', () => { + describe('createPolicyContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => PolicyContract = (address?: string, options?: CustomOptions) => { + const policyContract = new client.eth.Contract( + [...policyAbi], + address, + { + ...options, + } + ) + + return { + holdersShare: createHoldersShareCaller(policyContract), + rewards: createRewardsCaller(policyContract), + authenticationFee: createAuthenticationFeeCaller(policyContract), + marketVotingBlocks: createMarketVotingBlocksCaller(policyContract), + policyVotingBlocks: createPolicyVotingBlocksCaller(policyContract), + shareOfTreasury: createShareOfTreasuryCaller(policyContract), + treasury: createTreasuryCaller(policyContract), + capSetter: createCapSetterCaller(policyContract), + contract: () => policyContract, + } + } + + const result = createPolicyContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/policy/index.ts b/lib/l2/policy/index.ts new file mode 100644 index 000000000..b3092c493 --- /dev/null +++ b/lib/l2/policy/index.ts @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { policyAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { always } from 'ramda' +import { createHoldersShareCaller } from './holdersShare' +import { createRewardsCaller } from './rewards' +import { createAuthenticationFeeCaller } from './authenticationFee' +import { createMarketVotingBlocksCaller } from './marketVotingBlocks' +import { createPolicyVotingBlocksCaller } from './policyVotingBlocks' +import { createShareOfTreasuryCaller } from './shareOfTreasury' +import { createTreasuryCaller } from './treasury' +import { createCapSetterCaller } from './capSetter' + +export type PolicyContract = { + readonly holdersShare: (amount: string, lockups: string) => Promise + readonly rewards: (lockups: string, assets: string) => Promise + readonly authenticationFee: ( + assets: string, + propertyAssets: string + ) => Promise + readonly marketVotingBlocks: () => Promise + readonly policyVotingBlocks: () => Promise + readonly shareOfTreasury: (supply: string) => Promise + readonly treasury: () => Promise + readonly capSetter: () => Promise + readonly contract: () => Contract +} + +export type CreatePolicyContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => PolicyContract + +export const createPolicyContract: CreatePolicyContract = + (client: Web3) => (address?: string, options?: CustomOptions) => { + const contractClient: Contract = new client.eth.Contract( + [...policyAbi], + address, + { + ...options, + } + ) + + return { + holdersShare: createHoldersShareCaller(contractClient), + rewards: createRewardsCaller(contractClient), + authenticationFee: createAuthenticationFeeCaller(contractClient), + marketVotingBlocks: createMarketVotingBlocksCaller(contractClient), + policyVotingBlocks: createPolicyVotingBlocksCaller(contractClient), + shareOfTreasury: createShareOfTreasuryCaller(contractClient), + treasury: createTreasuryCaller(contractClient), + capSetter: createCapSetterCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/policy/marketVotingBlocks.spec.ts b/lib/l2/policy/marketVotingBlocks.spec.ts new file mode 100644 index 000000000..3713baee9 --- /dev/null +++ b/lib/l2/policy/marketVotingBlocks.spec.ts @@ -0,0 +1,49 @@ +import { createMarketVotingBlocksCaller } from './marketVotingBlocks' + +describe('marketVotingBlocks.spec.ts', () => { + describe('createMarketVotingCaller', () => { + it('call success', async () => { + const value = '1111' + + const contract = { + methods: { + marketVotingBlocks: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createMarketVotingBlocksCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + marketVotingBlocks: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createMarketVotingBlocksCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/marketVotingBlocks.ts b/lib/l2/policy/marketVotingBlocks.ts new file mode 100644 index 000000000..86474a082 --- /dev/null +++ b/lib/l2/policy/marketVotingBlocks.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateMarketVotingBlocksCaller = ( + contract: Contract +) => () => Promise + +export const createMarketVotingBlocksCaller: CreateMarketVotingBlocksCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'marketVotingBlocks', + }) + ) diff --git a/lib/l2/policy/policyVotingBlocks.spec.ts b/lib/l2/policy/policyVotingBlocks.spec.ts new file mode 100644 index 000000000..7117f5b92 --- /dev/null +++ b/lib/l2/policy/policyVotingBlocks.spec.ts @@ -0,0 +1,49 @@ +import { createPolicyVotingBlocksCaller } from './policyVotingBlocks' + +describe('policyVotingBlocks.spec.ts', () => { + describe('createPolicyVotingBlocksCaller', () => { + it('call success', async () => { + const value = '1111' + + const contract = { + methods: { + policyVotingBlocks: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPolicyVotingBlocksCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + policyVotingBlocks: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPolicyVotingBlocksCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/policyVotingBlocks.ts b/lib/l2/policy/policyVotingBlocks.ts new file mode 100644 index 000000000..bec2efb40 --- /dev/null +++ b/lib/l2/policy/policyVotingBlocks.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreatePolicyVotingBlocksCaller = ( + contract: Contract +) => () => Promise + +export const createPolicyVotingBlocksCaller: CreatePolicyVotingBlocksCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'policyVotingBlocks', + }) + ) diff --git a/lib/l2/policy/rewards.spec.ts b/lib/l2/policy/rewards.spec.ts new file mode 100644 index 000000000..958f5aced --- /dev/null +++ b/lib/l2/policy/rewards.spec.ts @@ -0,0 +1,51 @@ +import { createRewardsCaller } from './rewards' + +describe('rewards.spec.ts', () => { + describe('createRewardsCaller', () => { + it('call success', async () => { + const value = '12345' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + rewards: (lockups: string, assets: string) => ({ + call: jest.fn().mockImplementation(async () => value), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createRewardsCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + rewards: (lockups: string, assets: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createRewardsCaller(policyContract as any) + + const result = await caller('111111111111', '2222222222').catch( + (err) => err + ) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/rewards.ts b/lib/l2/policy/rewards.ts new file mode 100644 index 000000000..431bce969 --- /dev/null +++ b/lib/l2/policy/rewards.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateRewardsCaller = ( + contract: Contract +) => (lockups: string, assets: string) => Promise + +export const createRewardsCaller: CreateRewardsCaller = + (contract: Contract) => + async (lockups: string, assets: string): Promise => + execute({ + contract, + method: 'rewards', + args: [lockups, assets], + }) diff --git a/lib/l2/policy/shareOfTreasury.spec.ts b/lib/l2/policy/shareOfTreasury.spec.ts new file mode 100644 index 000000000..c96db7aa9 --- /dev/null +++ b/lib/l2/policy/shareOfTreasury.spec.ts @@ -0,0 +1,49 @@ +import { createShareOfTreasuryCaller } from './shareOfTreasury' + +describe('shareOfTreasury.spec.ts', () => { + describe('createShareOfTreasuryCaller', () => { + it('call success', async () => { + const value = '12345' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + shareOfTreasury: (supply: string) => ({ + call: jest.fn().mockImplementation(async () => value), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createShareOfTreasuryCaller(policyContract as any) + + const result = await caller('111111111111') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const policyContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + shareOfTreasury: (supply: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createShareOfTreasuryCaller(policyContract as any) + + const result = await caller('111111111111').catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/shareOfTreasury.ts b/lib/l2/policy/shareOfTreasury.ts new file mode 100644 index 000000000..2a7b2b2f5 --- /dev/null +++ b/lib/l2/policy/shareOfTreasury.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateShareOfTreasuryCaller = ( + contract: Contract +) => (supply: string) => Promise + +export const createShareOfTreasuryCaller: CreateShareOfTreasuryCaller = + (contract: Contract) => + async (supply: string): Promise => + execute({ + contract, + method: 'shareOfTreasury', + args: [supply], + }) diff --git a/lib/l2/policy/treasury.spec.ts b/lib/l2/policy/treasury.spec.ts new file mode 100644 index 000000000..1463a504f --- /dev/null +++ b/lib/l2/policy/treasury.spec.ts @@ -0,0 +1,49 @@ +import { createTreasuryCaller } from './treasury' + +describe('treasury.spec.ts', () => { + describe('createTreasuryCaller', () => { + it('call success', async () => { + const value = '1111' + + const contract = { + methods: { + treasury: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTreasuryCaller(contract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + treasury: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTreasuryCaller(contract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/policy/treasury.ts b/lib/l2/policy/treasury.ts new file mode 100644 index 000000000..ffe73d8d3 --- /dev/null +++ b/lib/l2/policy/treasury.ts @@ -0,0 +1,16 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateTreasuryCaller = (contract: Contract) => () => Promise + +export const createTreasuryCaller: CreateTreasuryCaller = ( + contract: Contract +) => + always( + execute({ + contract, + method: 'treasury', + }) + ) diff --git a/lib/l2/property-factory/abi.ts b/lib/l2/property-factory/abi.ts new file mode 100644 index 000000000..fa4c2342e --- /dev/null +++ b/lib/l2/property-factory/abi.ts @@ -0,0 +1,131 @@ +import { AbiItem } from 'web3-utils' + +export const propertyFactoryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_from', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'Create', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'isProperty', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_name', + type: 'string', + }, + { + internalType: 'string', + name: '_symbol', + type: 'string', + }, + { + internalType: 'address', + name: '_author', + type: 'address', + }, + ], + name: 'create', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_name', + type: 'string', + }, + { + internalType: 'string', + name: '_symbol', + type: 'string', + }, + { + internalType: 'address', + name: '_market', + type: 'address', + }, + { + internalType: 'string[]', + name: '_args', + type: 'string[]', + }, + ], + name: 'createAndAuthenticate', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/property-factory/create.spec.ts b/lib/l2/property-factory/create.spec.ts new file mode 100644 index 000000000..3e1f49a53 --- /dev/null +++ b/lib/l2/property-factory/create.spec.ts @@ -0,0 +1,70 @@ +import { createCreatePropertyCaller } from './create' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('createProperty.spec.ts', () => { + describe('createCreatePropertyCaller', () => { + it('call success', async () => { + const value = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const name = 'hoge' + const symbol = 'symbol' + const author = '0xD3E15c84c1eb38B530EC628145B73c90308645a2' + + const propertyFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (name: string, symbol: string, author: string) => ({ + send: jest + .fn() + .mockImplementation(async () => + stubbedSendTx({ name: 'Create', property: '_property', value }) + ), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreatePropertyCaller( + propertyFactoryContract as any, + stubbedWeb3 + ) + + const result = await caller(name, symbol, author) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const name = 'hoge' + const symbol = 'symbol' + const author = '0xD3E15c84c1eb38B530EC628145B73c90308645a2' + + const propertyFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + create: (name: string, symbol: string, author: string) => ({ + send: jest + .fn() + .mockImplementation(async () => + stubbedSendTx( + { name: 'Create', property: '_property', value: '' }, + true + ) + ), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCreatePropertyCaller( + propertyFactoryContract as any, + stubbedWeb3 + ) + + const result = await caller(name, symbol, author).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/property-factory/create.ts b/lib/l2/property-factory/create.ts new file mode 100644 index 000000000..1fe53bf05 --- /dev/null +++ b/lib/l2/property-factory/create.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' + +export type CreateCreatePropertyCaller = ( + contract: Contract, + client: Web3 +) => (name: string, symbol: string, author: string) => Promise + +export const createCreatePropertyCaller: CreateCreatePropertyCaller = + (contract: Contract, client: Web3) => + async (name: string, symbol: string, author: string): Promise => + execute({ + contract, + method: 'create', + args: [name, symbol, author], + mutation: true, + client, + }).then(({ events }) => events.Create.returnValues._property as string) diff --git a/lib/l2/property-factory/createAndAuthenticate.spec.ts b/lib/l2/property-factory/createAndAuthenticate.spec.ts new file mode 100644 index 000000000..17233ffb0 --- /dev/null +++ b/lib/l2/property-factory/createAndAuthenticate.spec.ts @@ -0,0 +1,171 @@ +/* eslint-disable functional/no-this-expression */ +/* eslint-disable functional/no-conditional-statement */ +/* eslint-disable functional/no-class */ +/* eslint-disable @typescript-eslint/promise-function-async */ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' +import { Event } from '../../common/utils/web3-txs' +import Web3 from 'web3' +import { propertyFactoryAbi } from './abi' + +describe('createAndAuthenticateCaller.ts', () => { + describe('createCreateAndAuthenticateCaller', () => { + it('call success', async () => { + const value = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const args = ['aaa', 'bbbb', 'ccccc'] + + const propertyFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + createAndAuthenticate: ( + name: string, + symbol: string, + author: string + ) => ({ + send: jest + .fn() + .mockImplementation(async () => + stubbedSendTx({ name: 'Create', property: '_property', value }) + ), + }), + }, + } + const client = { + eth: { + ...{ + Contract: class { + public readonly abi: any + public readonly address: string + public readonly methods: any + public readonly events = { + allEvents( + opts: any, + callback: (err: Error | null, e: Event) => void + ) { + setTimeout(() => { + callback(null, { + event: 'Create', + returnValues: { _metrics: value }, + } as unknown as Event) + }, 800) + }, + } + + constructor(abi: string, address: string) { + this.abi = abi + this.address = address + + this.methods = { + property: (...args: readonly any[]) => ({ + call: async () => Promise.resolve(propertyAddress), + }), + } + } + }, + getBlockNumber: () => Promise.resolve(123), + }, + ...stubbedWeb3.eth, + }, + } as unknown as Web3 + + const expected = value + + const caller = createCreateAndAuthenticateCaller( + propertyFactoryContract as any, + client + ) + + const result = await caller('name', 'SYMBOL', '0x0', args, { + metricsFactory: '0x...', + }) + + expect(result.property).toEqual(propertyAddress) + expect(result.transaction).toEqual({ + status: true, + events: { + Create: { + event: 'Create', + returnValues: { + _property: propertyAddress, + }, + }, + }, + }) + + const result2 = await result.waitForAuthentication() + + expect(result2).toEqual(value) + }) + + it('method call failure', async () => { + const propertyAddress = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + const args = ['aaa', 'bbbb', 'ccccc'] + + const propertyFactoryContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + createAndAuthenticate: ( + name: string, + symbol: string, + author: string + ) => ({ + send: jest + .fn() + .mockImplementation(async () => + stubbedSendTx( + { name: 'Create', property: '_property', value: '' }, + true + ) + ), + }), + }, + } + const client = { + eth: { + ...{ + Contract: class { + public readonly abi: any + public readonly address: string + public readonly methods: any + public readonly events = { + allEvents() { + // Nothing + }, + } + + constructor(abi: string, address: string) { + this.abi = abi + this.address = address + + this.methods = { + property: (...args: readonly any[]) => ({ + call: async () => Promise.resolve(propertyAddress), + }), + } + } + }, + getBlockNumber: () => Promise.resolve(123), + }, + ...stubbedWeb3.eth, + }, + } as unknown as Web3 + + const caller = createCreateAndAuthenticateCaller( + propertyFactoryContract as any, + client + ) + + const result = await caller('name', 'SYMBOL', '0x0', args, { + metricsFactory: '0x..', + }).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/property-factory/createAndAuthenticate.ts b/lib/l2/property-factory/createAndAuthenticate.ts new file mode 100644 index 000000000..3620f47e4 --- /dev/null +++ b/lib/l2/property-factory/createAndAuthenticate.ts @@ -0,0 +1,56 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { WaitForEventOptions } from '../market/authenticate' +import { waitForCreateMetrics } from '../../common/utils/waitForCreateMetrics' +import { TxReceipt } from '../../common/utils/web3-txs' +import { always } from 'ramda' + +export type CreateCreateAndAuthenticateCaller = ( + contract: Contract, + client: Web3 +) => ( + name: string, + symbol: string, + marketAddress: string, + args: readonly string[], + options: WaitForEventOptions +) => Promise<{ + readonly property: string + readonly transaction: TxReceipt + readonly waitForAuthentication: () => Promise +}> + +export const createCreateAndAuthenticateCaller: CreateCreateAndAuthenticateCaller = + + (contract: Contract, client: Web3) => + async ( + name: string, + symbol: string, + marketAddress: string, + args: readonly string[], + { metricsFactory }: WaitForEventOptions + ): Promise<{ + readonly property: string + readonly transaction: TxReceipt + readonly waitForAuthentication: () => Promise + }> => { + const transaction = await execute({ + contract, + method: 'createAndAuthenticate', + args: [name, symbol, marketAddress, ...args], + mutation: true, + padEnd: 6, + client, + }) + const property = transaction.events.Create.returnValues + ._property as string + return { + property, + transaction, + waitForAuthentication: always( + waitForCreateMetrics(client, property, metricsFactory) + ), + } + } diff --git a/lib/l2/property-factory/index.spec.ts b/lib/l2/property-factory/index.spec.ts new file mode 100644 index 000000000..058baf73d --- /dev/null +++ b/lib/l2/property-factory/index.spec.ts @@ -0,0 +1,50 @@ +import Web3 from 'web3' +import { createPropertyFactoryContract, PropertyFactoryContract } from '.' +import { createCreatePropertyCaller } from './create' +import { propertyFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' + +describe('property/index.ts', () => { + describe('createPropertyFactoryContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => PropertyFactoryContract = ( + address?: string, + options?: CustomOptions + ) => { + const propertyFactoryContract = new client.eth.Contract( + [...propertyFactoryAbi], + address, + { + ...options, + } + ) + + return { + create: createCreatePropertyCaller(propertyFactoryContract, client), + createAndAuthenticate: createCreateAndAuthenticateCaller( + propertyFactoryContract, + client + ), + contract: () => propertyFactoryContract, + } + } + + const result = createPropertyFactoryContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/property-factory/index.ts b/lib/l2/property-factory/index.ts new file mode 100644 index 000000000..a8f1a0d25 --- /dev/null +++ b/lib/l2/property-factory/index.ts @@ -0,0 +1,54 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { propertyFactoryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createCreatePropertyCaller } from './create' +import { WaitForEventOptions } from '../market/authenticate' +import { createCreateAndAuthenticateCaller } from './createAndAuthenticate' +import { always } from 'ramda' +import { TxReceipt } from '../../common/utils/web3-txs' + +export type PropertyFactoryContract = { + readonly create: ( + name: string, + symbol: string, + author: string + ) => Promise + readonly createAndAuthenticate: ( + name: string, + symbol: string, + marketAddress: string, + args: readonly string[], + options: WaitForEventOptions + ) => Promise<{ + readonly property: string + readonly transaction: TxReceipt + readonly waitForAuthentication: () => Promise + }> + readonly contract: () => Contract +} + +export type CreatePropertyFactoryContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => PropertyFactoryContract + +export const createPropertyFactoryContract: CreatePropertyFactoryContract = + (client: Web3) => (address?: string, options?: CustomOptions) => { + const contractClient: Contract = new client.eth.Contract( + [...propertyFactoryAbi], + address, + { + ...options, + } + ) + + return { + create: createCreatePropertyCaller(contractClient, client), + createAndAuthenticate: createCreateAndAuthenticateCaller( + contractClient, + client + ), + contract: always(contractClient), + } + } diff --git a/lib/l2/property/abi.ts b/lib/l2/property/abi.ts new file mode 100644 index 000000000..add1bb1c0 --- /dev/null +++ b/lib/l2/property/abi.ts @@ -0,0 +1,440 @@ +import { AbiItem } from 'web3-utils' + +export const propertyAbi = [ + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + { + internalType: 'address', + name: '_own', + type: 'address', + }, + { + internalType: 'string', + name: '_name', + type: 'string', + }, + { + internalType: 'string', + name: '_symbol', + type: 'string', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'address', + name: '_old', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_new', + type: 'address', + }, + ], + name: 'ChangeAuthor', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'string', + name: '_old', + type: 'string', + }, + { + indexed: false, + internalType: 'string', + name: '_new', + type: 'string', + }, + ], + name: 'ChangeName', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'string', + name: '_old', + type: 'string', + }, + { + indexed: false, + internalType: 'string', + name: '_new', + type: 'string', + }, + ], + name: 'ChangeSymbol', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'value', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + ], + name: 'allowance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'subtractedValue', + type: 'uint256', + }, + ], + name: 'decreaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'spender', + type: 'address', + }, + { + internalType: 'uint256', + name: 'addedValue', + type: 'uint256', + }, + ], + name: 'increaseAllowance', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'author', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'decimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_nextAuthor', + type: 'address', + }, + ], + name: 'changeAuthor', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_name', + type: 'string', + }, + ], + name: 'changeName', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_symbol', + type: 'string', + }, + ], + name: 'changeSymbol', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_to', + type: 'address', + }, + { + internalType: 'uint256', + name: '_value', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_from', + type: 'address', + }, + { + internalType: 'address', + name: '_to', + type: 'address', + }, + { + internalType: 'uint256', + name: '_value', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_sender', + type: 'address', + }, + { + internalType: 'uint256', + name: '_value', + type: 'uint256', + }, + ], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/property/author.spec.ts b/lib/l2/property/author.spec.ts new file mode 100644 index 000000000..3f95a79f3 --- /dev/null +++ b/lib/l2/property/author.spec.ts @@ -0,0 +1,49 @@ +import { createAuthorCaller } from './author' + +describe('author.spec.ts', () => { + describe('createAuthorCaller', () => { + it('call success', async () => { + const value = 'value' + + const propertyContract = { + methods: { + author: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthorCaller(propertyContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const propertyContract = { + methods: { + author: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createAuthorCaller(propertyContract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/property/author.ts b/lib/l2/property/author.ts new file mode 100644 index 000000000..5e3017517 --- /dev/null +++ b/lib/l2/property/author.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreateAuthorCaller = (contract: Contract) => () => Promise + +export const createAuthorCaller: CreateAuthorCaller = (contract: Contract) => + always(execute({ contract, method: 'author' })) diff --git a/lib/l2/property/changeAuthor.spec.ts b/lib/l2/property/changeAuthor.spec.ts new file mode 100644 index 000000000..4762b3a15 --- /dev/null +++ b/lib/l2/property/changeAuthor.spec.ts @@ -0,0 +1,49 @@ +import { createChangeAuthorCaller } from './changeAuthor' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('changeAuthor.spec.ts', () => { + describe('createChangeAuthorCaller', () => { + it('call success', async () => { + const expected = true + const nextAuther = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeAuthor: (nextAuther: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeAuthorCaller(contract as any, stubbedWeb3) + + const result = await caller(nextAuther) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const nextAuther = '0x0472ec0185ebb8202f3d4ddb0226998889663cf2' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeAuthor: (nextAuther: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeAuthorCaller(contract as any, stubbedWeb3) + + const result = await caller(nextAuther).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/property/changeAuthor.ts b/lib/l2/property/changeAuthor.ts new file mode 100644 index 000000000..32cdaf648 --- /dev/null +++ b/lib/l2/property/changeAuthor.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateChangeAuthorCaller = ( + contract: Contract, + client: Web3 +) => (nextAuther: string) => Promise + +export const createChangeAuthorCaller: CreateChangeAuthorCaller = + (contract: Contract, client: Web3) => async (nextAuther: string) => + execute({ + contract, + method: 'changeAuthor', + mutation: true, + client, + args: [nextAuther], + }).then(T) diff --git a/lib/l2/property/changeName.spec.ts b/lib/l2/property/changeName.spec.ts new file mode 100644 index 000000000..91d50d6d8 --- /dev/null +++ b/lib/l2/property/changeName.spec.ts @@ -0,0 +1,49 @@ +import { createChangeNameCaller } from './changeName' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('changeName.spec.ts', () => { + describe('createChangeNameCaller', () => { + it('call success', async () => { + const expected = true + const nextName = 'next' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeName: (nextName: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeNameCaller(contract as any, stubbedWeb3) + + const result = await caller(nextName) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const nextName = 'next' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeName: (nextName: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeNameCaller(contract as any, stubbedWeb3) + + const result = await caller(nextName).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/property/changeName.ts b/lib/l2/property/changeName.ts new file mode 100644 index 000000000..f7d8e6bce --- /dev/null +++ b/lib/l2/property/changeName.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateChangeNameCaller = ( + contract: Contract, + client: Web3 +) => (nextAuther: string) => Promise + +export const createChangeNameCaller: CreateChangeNameCaller = + (contract: Contract, client: Web3) => async (nextName: string) => + execute({ + contract, + method: 'changeName', + mutation: true, + client, + args: [nextName], + }).then(T) diff --git a/lib/l2/property/changeSymbol.spec.ts b/lib/l2/property/changeSymbol.spec.ts new file mode 100644 index 000000000..c67373a33 --- /dev/null +++ b/lib/l2/property/changeSymbol.spec.ts @@ -0,0 +1,49 @@ +import { createChangeSymbolCaller } from './changeSymbol' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('changeSymbol.spec.ts', () => { + describe('createChangeSymbolCaller', () => { + it('call success', async () => { + const expected = true + const nextSymbol = 'next' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeSymbol: (nextSymbol: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeSymbolCaller(contract as any, stubbedWeb3) + + const result = await caller(nextSymbol) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const nextSymbol = 'next' + + const contract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + changeSymbol: (nextSymbol: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createChangeSymbolCaller(contract as any, stubbedWeb3) + + const result = await caller(nextSymbol).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/property/changeSymbol.ts b/lib/l2/property/changeSymbol.ts new file mode 100644 index 000000000..e33c3343d --- /dev/null +++ b/lib/l2/property/changeSymbol.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateChangeSymbolCaller = ( + contract: Contract, + client: Web3 +) => (nextAuther: string) => Promise + +export const createChangeSymbolCaller: CreateChangeSymbolCaller = + (contract: Contract, client: Web3) => async (nextSymbol: string) => + execute({ + contract, + method: 'changeSymbol', + mutation: true, + client, + args: [nextSymbol], + }).then(T) diff --git a/lib/l2/property/index.spec.ts b/lib/l2/property/index.spec.ts new file mode 100644 index 000000000..22166b279 --- /dev/null +++ b/lib/l2/property/index.spec.ts @@ -0,0 +1,65 @@ +import Web3 from 'web3' +import { createPropertyContract, PropertyContract } from '.' +import { propertyAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createAuthorCaller } from './author' +import { createChangeNameCaller } from './changeName' +import { createChangeSymbolCaller } from './changeSymbol' +import { createChangeAuthorCaller } from './changeAuthor' +import { createTransferCaller } from './../erc20/transfer' +import { createNameCaller } from './../erc20/name' +import { createSymbolCaller } from './../erc20/symbol' +import { createTotalSupplyCaller } from './../erc20/totalSupply' +import { createDecimalsCaller } from './../erc20/decimals' +import { createTransferFromCaller } from '../erc20/transferFrom' +import { createBalanceOfCaller } from './../erc20/balanceOf' +import { createApproveCaller } from './../erc20/approve' +import { createAllowanceCaller } from './../erc20/allowance' + +describe('property/index.ts', () => { + describe('createPropertyContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => PropertyContract = (address?: string, options?: CustomOptions) => { + const propertyContract = new client.eth.Contract( + [...propertyAbi], + address, + { + ...options, + } + ) + return { + totalSupply: createTotalSupplyCaller(propertyContract), + balanceOf: createBalanceOfCaller(propertyContract), + transfer: createTransferCaller(propertyContract, client), + allowance: createAllowanceCaller(propertyContract), + approve: createApproveCaller(propertyContract, client), + transferFrom: createTransferFromCaller(propertyContract, client), + name: createNameCaller(propertyContract), + symbol: createSymbolCaller(propertyContract), + decimals: createDecimalsCaller(propertyContract), + author: createAuthorCaller(propertyContract), + changeAuthor: createChangeAuthorCaller(propertyContract, client), + changeName: createChangeNameCaller(propertyContract, client), + changeSymbol: createChangeSymbolCaller(propertyContract, client), + contract: () => propertyContract, + } + } + + const result = createPropertyContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/property/index.ts b/lib/l2/property/index.ts new file mode 100644 index 000000000..0793ddfa2 --- /dev/null +++ b/lib/l2/property/index.ts @@ -0,0 +1,73 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { always } from 'ramda' +import { propertyAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createAuthorCaller } from './author' +import { createChangeAuthorCaller } from './changeAuthor' +import { createChangeNameCaller } from './changeName' +import { createChangeSymbolCaller } from './changeSymbol' +import { createTransferCaller } from '../erc20/transfer' +import { createNameCaller } from '../erc20/name' +import { createSymbolCaller } from '../erc20/symbol' +import { createTotalSupplyCaller } from '../erc20/totalSupply' +import { createDecimalsCaller } from '../erc20/decimals' +import { createTransferFromCaller } from '../erc20/transferFrom' +import { createBalanceOfCaller } from '../erc20/balanceOf' +import { createApproveCaller } from '../erc20/approve' +import { createAllowanceCaller } from '../erc20/allowance' + +export type PropertyContract = { + readonly totalSupply: () => Promise + readonly balanceOf: (address: string) => Promise + readonly transfer: (to: string, value: string) => Promise + readonly allowance: (from: string, to: string) => Promise + readonly approve: (to: string, value: string) => Promise + readonly transferFrom: ( + from: string, + to: string, + value: string + ) => Promise + readonly name: () => Promise + readonly symbol: () => Promise + readonly decimals: () => Promise + readonly author: () => Promise + readonly changeAuthor: (nextAuthor: string) => Promise + readonly changeName: (nextName: string) => Promise + readonly changeSymbol: (nextSymbol: string) => Promise + readonly contract: () => Contract +} + +export type CreatePropertyContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => PropertyContract + +export const createPropertyContract: CreatePropertyContract = + (client: Web3) => + (address?: string, options?: CustomOptions): PropertyContract => { + const contractClient: Contract = new client.eth.Contract( + [...propertyAbi], + address, + { + ...options, + } + ) + + return { + totalSupply: createTotalSupplyCaller(contractClient), + balanceOf: createBalanceOfCaller(contractClient), + transfer: createTransferCaller(contractClient, client), + allowance: createAllowanceCaller(contractClient), + approve: createApproveCaller(contractClient, client), + transferFrom: createTransferFromCaller(contractClient, client), + name: createNameCaller(contractClient), + symbol: createSymbolCaller(contractClient), + decimals: createDecimalsCaller(contractClient), + author: createAuthorCaller(contractClient), + changeAuthor: createChangeAuthorCaller(contractClient, client), + changeName: createChangeNameCaller(contractClient, client), + changeSymbol: createChangeSymbolCaller(contractClient, client), + contract: always(contractClient), + } + } diff --git a/lib/l2/registry/abi.ts b/lib/l2/registry/abi.ts new file mode 100644 index 000000000..d76927626 --- /dev/null +++ b/lib/l2/registry/abi.ts @@ -0,0 +1,100 @@ +import { AbiItem } from 'web3-utils' + +export const addressRegistryAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_key', + type: 'string', + }, + { + internalType: 'address', + name: '_addr', + type: 'address', + }, + ], + name: 'setRegistry', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'string', + name: '_key', + type: 'string', + }, + ], + name: 'registries', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/registry/index.spec.ts b/lib/l2/registry/index.spec.ts new file mode 100644 index 000000000..72b4995e0 --- /dev/null +++ b/lib/l2/registry/index.spec.ts @@ -0,0 +1,41 @@ +import Web3 from 'web3' +import { createRegistryContract, RegistryContract } from '.' +import { addressRegistryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createPolicyCaller } from './policy' + +describe('registry/index.ts', () => { + describe('createRegistryContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => RegistryContract = (address?: string, options?: CustomOptions) => { + const registryContract = new client.eth.Contract( + [...addressRegistryAbi], + address, + { + ...options, + } + ) + return { + policy: createPolicyCaller(registryContract), + contract: () => registryContract, + } + } + + const result = createRegistryContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/registry/index.ts b/lib/l2/registry/index.ts new file mode 100644 index 000000000..ca65a8ab9 --- /dev/null +++ b/lib/l2/registry/index.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { addressRegistryAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createPolicyCaller } from './policy' +import { always } from 'ramda' + +export type RegistryContract = { + readonly policy: () => Promise + readonly contract: () => Contract +} + +export type CreateRegistryContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => RegistryContract + +export const createRegistryContract: CreateRegistryContract = + (client: Web3) => + (address?: string, options?: CustomOptions): RegistryContract => { + const contractClient: Contract = new client.eth.Contract( + [...addressRegistryAbi], + address, + { + ...options, + } + ) + + return { + policy: createPolicyCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/registry/policy.spec.ts b/lib/l2/registry/policy.spec.ts new file mode 100644 index 000000000..11aa7b4ca --- /dev/null +++ b/lib/l2/registry/policy.spec.ts @@ -0,0 +1,51 @@ +import { createPolicyCaller } from './policy' + +describe('createPolicyCaller.spec.ts', () => { + describe('createPolicyCaller', () => { + it('call success', async () => { + const value = 'value' + + const addressConfigContract = { + methods: { + registries: (name: string) => ({ + call: jest + .fn() + .mockImplementation(async () => + Promise.resolve(name === 'policy' ? value : undefined) + ), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPolicyCaller(addressConfigContract as any) + + const result = await caller() + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const addressConfigContract = { + methods: { + registries: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPolicyCaller(addressConfigContract as any) + + const result = await caller().catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/registry/policy.ts b/lib/l2/registry/policy.ts new file mode 100644 index 000000000..0584d9db4 --- /dev/null +++ b/lib/l2/registry/policy.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' +import { always } from 'ramda' + +export type CreatePolicyCaller = (contract: Contract) => () => Promise + +export const createPolicyCaller: CreatePolicyCaller = (contract: Contract) => + always(execute({ contract, method: 'registries', args: ['policy'] })) diff --git a/lib/l2/s-tokens/abi.ts b/lib/l2/s-tokens/abi.ts new file mode 100644 index 000000000..89a0d31a1 --- /dev/null +++ b/lib/l2/s-tokens/abi.ts @@ -0,0 +1,640 @@ +import { AbiItem } from 'web3-utils' + +export const sTokensAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'approved', + type: 'address', + }, + { + indexed: true, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'ApprovalForAll', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: 'property', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'price', + type: 'uint256', + }, + ], + name: 'Minted', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: true, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'price', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'cumulativeReward', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'pendingReward', + type: 'uint256', + }, + ], + name: 'Updated', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'getApproved', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + ], + name: 'isApprovedForAll', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'ownerOf', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'safeTransferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + internalType: 'bytes', + name: '_data', + type: 'bytes', + }, + ], + name: 'safeTransferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'setApprovalForAll', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4', + }, + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'tokenIdCounter', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'tokenURI', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_owner', + type: 'address', + }, + { + internalType: 'address', + name: '_property', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_price', + type: 'uint256', + }, + ], + name: 'mint', + outputs: [ + { + internalType: 'uint256', + name: 'tokenId_', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_price', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_cumulativeReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_pendingReward', + type: 'uint256', + }, + ], + name: 'update', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'positions', + outputs: [ + { + components: [ + { + internalType: 'address', + name: 'property', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'price', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'cumulativeReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'pendingReward', + type: 'uint256', + }, + ], + internalType: 'struct ISTokensManager.StakingPositions', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_tokenId', + type: 'uint256', + }, + ], + name: 'rewards', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'entireReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'cumulativeReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'withdrawableReward', + type: 'uint256', + }, + ], + internalType: 'struct ISTokensManager.Rewards', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'positionsOfProperty', + outputs: [ + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_owner', + type: 'address', + }, + ], + name: 'positionsOfOwner', + outputs: [ + { + internalType: 'uint256[]', + name: '', + type: 'uint256[]', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/s-tokens/index.spec.ts b/lib/l2/s-tokens/index.spec.ts new file mode 100644 index 000000000..2a65aa3cf --- /dev/null +++ b/lib/l2/s-tokens/index.spec.ts @@ -0,0 +1,49 @@ +import Web3 from 'web3' +import { CustomOptions } from '../../common/option' +import { createSTokensContract, STokensContract } from '.' +import { createPositionsCaller } from './positions' +import { createRewardsCaller } from './rewards' +import { createTokenURICaller } from './tokenURI' +import { sTokensAbi } from './abi' +import { createPositionsOfPropertyCaller } from './positionsOfProperty' +import { createPositionsOfOwnerCaller } from './positionsOfOwner' + +describe('s-tokens/index.ts', () => { + describe('createSTokensContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => STokensContract = (address?: string, options?: CustomOptions) => { + const sTokensContract = new client.eth.Contract( + [...sTokensAbi], + address, + { + ...options, + } + ) + return { + positions: createPositionsCaller(sTokensContract), + rewards: createRewardsCaller(sTokensContract), + tokenURI: createTokenURICaller(sTokensContract), + positionsOfProperty: createPositionsOfPropertyCaller(sTokensContract), + positionsOfOwner: createPositionsOfOwnerCaller(sTokensContract), + contract: () => sTokensContract, + } + } + + const result = createSTokensContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/s-tokens/index.ts b/lib/l2/s-tokens/index.ts new file mode 100644 index 000000000..a7cb9fdb6 --- /dev/null +++ b/lib/l2/s-tokens/index.ts @@ -0,0 +1,45 @@ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { sTokensAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createPositionsCaller, Positions } from './positions' +import { createRewardsCaller, Rewards } from './rewards' +import { always } from 'ramda' +import { createTokenURICaller, TokenURI } from './tokenURI' +import { createPositionsOfPropertyCaller } from './positionsOfProperty' +import { createPositionsOfOwnerCaller } from './positionsOfOwner' + +export type STokensContract = { + readonly positions: (tokenId: number) => Promise + readonly rewards: (tokenId: number) => Promise + readonly tokenURI: (tokenId: number) => Promise + readonly positionsOfProperty: ( + propertyAddress: string + ) => Promise + readonly positionsOfOwner: ( + accountAddress: string + ) => Promise + readonly contract: () => Contract +} + +// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types +export const createSTokensContract = + (client: Web3) => + (address?: string, options?: CustomOptions): STokensContract => { + const contractClient: Contract = new client.eth.Contract( + [...sTokensAbi], + address, + { + ...options, + } + ) + + return { + positions: createPositionsCaller(contractClient), + rewards: createRewardsCaller(contractClient), + tokenURI: createTokenURICaller(contractClient), + positionsOfProperty: createPositionsOfPropertyCaller(contractClient), + positionsOfOwner: createPositionsOfOwnerCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/s-tokens/positions.spec.ts b/lib/l2/s-tokens/positions.spec.ts new file mode 100644 index 000000000..ff82288f7 --- /dev/null +++ b/lib/l2/s-tokens/positions.spec.ts @@ -0,0 +1,66 @@ +import { createPositionsCaller } from './positions' + +describe('positions.spec.ts', () => { + describe('createPositionsCaller', () => { + it('call success', async () => { + const value = { + 0: '0x00', + 1: '10000000000', + 3: '20000000000', + 4: '30000000000', + 5: '40000000000', + property_: '0x00', + amount_: '10000000000', + price_: '20000000000', + cumulativeReward_: '30000000000', + pendingReward_: '40000000000', + } + + const contract = { + methods: { + positions: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = { + property: '0x00', + amount: '10000000000', + price: '20000000000', + cumulativeReward: '30000000000', + pendingReward: '40000000000', + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsCaller(contract as any) + + const result = await caller(1) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + positions: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsCaller(contract as any) + + const result = await caller(1).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/s-tokens/positions.ts b/lib/l2/s-tokens/positions.ts new file mode 100644 index 000000000..0f5e84d1b --- /dev/null +++ b/lib/l2/s-tokens/positions.ts @@ -0,0 +1,39 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' + +export type Positions = { + readonly property: string + readonly amount: string + readonly price: string + readonly cumulativeReward: string + readonly pendingReward: string +} + +export type CreatePositionsCaller = ( + contract: Contract +) => (tokenId: number) => Promise + +export const createPositionsCaller: CreatePositionsCaller = + (contract: Contract) => async (tokenId: number) => { + const res = await execute<{ + readonly property_: string + readonly amount_: string + readonly price_: string + readonly cumulativeReward_: string + readonly pendingReward_: string + }>({ + contract, + method: 'positions', + args: [String(tokenId)], + }) + const arrayified = arrayify(res) + return { + property: arrayified[0], + amount: arrayified[1], + price: arrayified[2], + cumulativeReward: arrayified[3], + pendingReward: arrayified[4], + } + } diff --git a/lib/l2/s-tokens/positionsOfOwner.spec.ts b/lib/l2/s-tokens/positionsOfOwner.spec.ts new file mode 100644 index 000000000..f75a383d8 --- /dev/null +++ b/lib/l2/s-tokens/positionsOfOwner.spec.ts @@ -0,0 +1,47 @@ +import { createPositionsOfOwnerCaller } from './positionsOfOwner' + +describe('positionsOfOwner.spec.ts', () => { + describe('createPositionsOfOwnerCaller', () => { + it('call success', async () => { + const value = ['1', '2', '3', '4', '5', '6'] + + const contract = { + methods: { + positionsOfOwner: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsOfOwnerCaller(contract as any) + + const result = await caller('0xAddress') + + expect(result).toEqual([1, 2, 3, 4, 5, 6]) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + positionsOfOwner: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsOfOwnerCaller(contract as any) + + const result = await caller('0xAddress').catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/s-tokens/positionsOfOwner.ts b/lib/l2/s-tokens/positionsOfOwner.ts new file mode 100644 index 000000000..27790a5bb --- /dev/null +++ b/lib/l2/s-tokens/positionsOfOwner.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreatePositionsOfOwnerCaller = ( + contract: Contract +) => (accountAddress: string) => Promise + +export const createPositionsOfOwnerCaller: CreatePositionsOfOwnerCaller = + (contract: Contract) => async (accountAddress: string) => { + const res = await execute({ + contract, + method: 'positionsOfOwner', + args: [accountAddress], + }) + return res.map(Number) + } diff --git a/lib/l2/s-tokens/positionsOfProperty.spec.ts b/lib/l2/s-tokens/positionsOfProperty.spec.ts new file mode 100644 index 000000000..eab929a7d --- /dev/null +++ b/lib/l2/s-tokens/positionsOfProperty.spec.ts @@ -0,0 +1,47 @@ +import { createPositionsOfPropertyCaller } from './positionsOfProperty' + +describe('positionsOfProperty.spec.ts', () => { + describe('createPositionsOfPropertyCaller', () => { + it('call success', async () => { + const value = ['1', '2', '3', '4', '5', '6'] + + const contract = { + methods: { + positionsOfProperty: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsOfPropertyCaller(contract as any) + + const result = await caller('0xAddress') + + expect(result).toEqual([1, 2, 3, 4, 5, 6]) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + positionsOfProperty: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createPositionsOfPropertyCaller(contract as any) + + const result = await caller('0xAddress').catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/s-tokens/positionsOfProperty.ts b/lib/l2/s-tokens/positionsOfProperty.ts new file mode 100644 index 000000000..7ca17f0e4 --- /dev/null +++ b/lib/l2/s-tokens/positionsOfProperty.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreatePositionsOfPropertyCaller = ( + contract: Contract +) => (propertyAddress: string) => Promise + +export const createPositionsOfPropertyCaller: CreatePositionsOfPropertyCaller = + (contract: Contract) => async (propertyAddress: string) => { + const res = await execute({ + contract, + method: 'positionsOfProperty', + args: [propertyAddress], + }) + return res.map(Number) + } diff --git a/lib/l2/s-tokens/rewards.spec.ts b/lib/l2/s-tokens/rewards.spec.ts new file mode 100644 index 000000000..593d31124 --- /dev/null +++ b/lib/l2/s-tokens/rewards.spec.ts @@ -0,0 +1,60 @@ +import { createRewardsCaller } from './rewards' + +describe('rewards.spec.ts', () => { + describe('createRewardsCaller', () => { + it('call success', async () => { + const value = { + 0: '10000000000', + 1: '20000000000', + 2: '30000000000', + entireReward_: '10000000000', + cumulativeReward_: '20000000000', + withdrawableReward_: '30000000000', + } + + const contract = { + methods: { + rewards: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = { + entireReward: '10000000000', + cumulativeReward: '20000000000', + withdrawableReward: '30000000000', + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createRewardsCaller(contract as any) + + const result = await caller(1) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + rewards: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createRewardsCaller(contract as any) + + const result = await caller(1).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/s-tokens/rewards.ts b/lib/l2/s-tokens/rewards.ts new file mode 100644 index 000000000..4579227e1 --- /dev/null +++ b/lib/l2/s-tokens/rewards.ts @@ -0,0 +1,33 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' + +export type Rewards = { + readonly entireReward: string + readonly cumulativeReward: string + readonly withdrawableReward: string +} + +export type CreateRewardsCaller = ( + contract: Contract +) => (tokenId: number) => Promise + +export const createRewardsCaller: CreateRewardsCaller = + (contract: Contract) => async (tokenId: number) => { + const res = await execute<{ + readonly entireReward_: string + readonly cumulativeReward_: string + readonly withdrawableReward_: string + }>({ + contract, + method: 'rewards', + args: [String(tokenId)], + }) + const arrayified = arrayify(res) + return { + entireReward: arrayified[0], + cumulativeReward: arrayified[1], + withdrawableReward: arrayified[2], + } + } diff --git a/lib/l2/s-tokens/tokenURI.spec.ts b/lib/l2/s-tokens/tokenURI.spec.ts new file mode 100644 index 000000000..7a0868615 --- /dev/null +++ b/lib/l2/s-tokens/tokenURI.spec.ts @@ -0,0 +1,54 @@ +import { createTokenURICaller } from './tokenURI' + +describe('tokenURI.spec.ts', () => { + describe('createTokenURICaller', () => { + it('call success', async () => { + const data = { + name: 'test-name', + description: 'test-description', + image: 'test-image', + } + const value = JSON.stringify(data) + + const contract = { + methods: { + tokenURI: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = data + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTokenURICaller(contract as any) + + const result = await caller(1) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const contract = { + methods: { + tokenURI: () => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createTokenURICaller(contract as any) + + const result = await caller(1).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/s-tokens/tokenURI.ts b/lib/l2/s-tokens/tokenURI.ts new file mode 100644 index 000000000..fd461040c --- /dev/null +++ b/lib/l2/s-tokens/tokenURI.ts @@ -0,0 +1,23 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type TokenURI = { + readonly name: string + readonly description: string + readonly image: string +} + +export type CreateTokenURICaller = ( + contract: Contract +) => (tokenId: number) => Promise + +export const createTokenURICaller: CreateTokenURICaller = + (contract: Contract) => async (tokenId: number) => { + const res = await execute({ + contract, + method: 'tokenURI', + args: [String(tokenId)], + }) + return JSON.parse(res) + } diff --git a/lib/l2/withdraw/abi.ts b/lib/l2/withdraw/abi.ts new file mode 100644 index 000000000..0aacb4d98 --- /dev/null +++ b/lib/l2/withdraw/abi.ts @@ -0,0 +1,216 @@ +import { AbiItem } from 'web3-utils' + +export const withdrawAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: '_property', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_from', + type: 'address', + }, + { + indexed: false, + internalType: 'address', + name: '_to', + type: 'address', + }, + ], + name: 'PropertyTransfer', + type: 'event', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'cumulativeWithdrawnReward', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'lastWithdrawnRewardCapPrice', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'lastWithdrawnRewardPrice', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'pendingWithdrawal', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'registryAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_registry', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + ], + name: 'withdraw', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_from', + type: 'address', + }, + { + internalType: 'address', + name: '_to', + type: 'address', + }, + ], + name: 'beforeBalanceChange', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_property', + type: 'address', + }, + { + internalType: 'address', + name: '_user', + type: 'address', + }, + ], + name: 'calculateRewardAmount', + outputs: [ + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_price', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_cap', + type: 'uint256', + }, + { + internalType: 'uint256', + name: '_allReward', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as readonly AbiItem[] diff --git a/lib/l2/withdraw/calculateRewardAmount.spec.ts b/lib/l2/withdraw/calculateRewardAmount.spec.ts new file mode 100644 index 000000000..2d1c5de82 --- /dev/null +++ b/lib/l2/withdraw/calculateRewardAmount.spec.ts @@ -0,0 +1,57 @@ +import { calculateRewardAmountCaller } from './calculateRewardAmount' + +describe('calculateRewardAmount.spec.ts', () => { + describe('createCalculateRewardAmountCaller', () => { + it('call success', async () => { + const value = ['value1', 'value2', 'value3', 'value4'] + + const rewardContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + calculateRewardAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = calculateRewardAmountCaller(rewardContract as any) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '0xC7b8B28E498233113b270B1E1e0f91049a31467a' + ) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const rewardContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + calculateRewardAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = calculateRewardAmountCaller(rewardContract as any) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '0xC7b8B28E498233113b270B1E1e0f91049a31467a' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/withdraw/calculateRewardAmount.ts b/lib/l2/withdraw/calculateRewardAmount.ts new file mode 100644 index 000000000..4dac1158d --- /dev/null +++ b/lib/l2/withdraw/calculateRewardAmount.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract' +import { arrayify } from '../../common/utils/arrayify' +import { execute } from '../../common/utils/execute' + +export type calculateRewardAmountCaller = ( + contract: Contract +) => ( + propertyAddress: string, + accountAddress: string +) => Promise + +export const calculateRewardAmountCaller: calculateRewardAmountCaller = + (contract: Contract) => + async (propertyAddress: string, accountAddress: string) => + execute>({ + contract, + method: 'calculateRewardAmount', + args: [propertyAddress, accountAddress], + }).then((r) => arrayify(r) as readonly [string, string, string, string]) diff --git a/lib/l2/withdraw/calculateWithdrawableAmount.spec.ts b/lib/l2/withdraw/calculateWithdrawableAmount.spec.ts new file mode 100644 index 000000000..7bbfafc70 --- /dev/null +++ b/lib/l2/withdraw/calculateWithdrawableAmount.spec.ts @@ -0,0 +1,61 @@ +import { createCalculateWithdrawableAmountCaller } from './calculateWithdrawableAmount' + +describe('calculateWithdrawableAmount.spec.ts', () => { + describe('createCalculateWithdrawableAmountCaller', () => { + it('call success', async () => { + const value = 'value' + + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + calculateWithdrawableAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateWithdrawableAmountCaller( + withdrawContract as any + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '0xC7b8B28E498233113b270B1E1e0f91049a31467a' + ) + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + calculateWithdrawableAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createCalculateWithdrawableAmountCaller( + withdrawContract as any + ) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5', + '0xC7b8B28E498233113b270B1E1e0f91049a31467a' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/withdraw/calculateWithdrawableAmount.ts b/lib/l2/withdraw/calculateWithdrawableAmount.ts new file mode 100644 index 000000000..940874a83 --- /dev/null +++ b/lib/l2/withdraw/calculateWithdrawableAmount.ts @@ -0,0 +1,17 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateCalculateWithdrawableAmountCaller = ( + contract: Contract +) => (propertyAddress: string, accountAddress: string) => Promise + +export const createCalculateWithdrawableAmountCaller: CreateCalculateWithdrawableAmountCaller = + + (contract: Contract) => + async (propertyAddress: string, accountAddress: string) => + execute({ + contract, + method: 'calculateWithdrawableAmount', + args: [propertyAddress, accountAddress], + }) diff --git a/lib/l2/withdraw/getRewardsAmount.spec.ts b/lib/l2/withdraw/getRewardsAmount.spec.ts new file mode 100644 index 000000000..48a1b2f9f --- /dev/null +++ b/lib/l2/withdraw/getRewardsAmount.spec.ts @@ -0,0 +1,53 @@ +import { createGetRewardsAmountCaller } from './getRewardsAmount' + +describe('getRewardsAmount.spec.ts', () => { + describe('createGetRewardsAmountCaller', () => { + it('call success', async () => { + const value = 'value' + + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + getRewardsAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.resolve(value)), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createGetRewardsAmountCaller(withdrawContract as any) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const error = 'error' + + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + getRewardsAmount: (address: string) => ({ + call: jest + .fn() + .mockImplementation(async () => Promise.reject(error)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createGetRewardsAmountCaller(withdrawContract as any) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toEqual(error) + }) + }) +}) diff --git a/lib/l2/withdraw/getRewardsAmount.ts b/lib/l2/withdraw/getRewardsAmount.ts new file mode 100644 index 000000000..5ff431f96 --- /dev/null +++ b/lib/l2/withdraw/getRewardsAmount.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import { execute } from '../../common/utils/execute' + +export type CreateGetRewardsAmountCaller = ( + contract: Contract +) => (address: string) => Promise + +export const createGetRewardsAmountCaller: CreateGetRewardsAmountCaller = + (contract: Contract) => async (address: string) => + execute({ contract, method: 'getRewardsAmount', args: [address] }) diff --git a/lib/l2/withdraw/index.spec.ts b/lib/l2/withdraw/index.spec.ts new file mode 100644 index 000000000..fa360eb08 --- /dev/null +++ b/lib/l2/withdraw/index.spec.ts @@ -0,0 +1,48 @@ +import Web3 from 'web3' +import { createWithdrawContract, WithdrawContract } from '.' +import { withdrawAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createWithdrawCaller } from './withdraw' +import { createGetRewardsAmountCaller } from './getRewardsAmount' +import { createCalculateWithdrawableAmountCaller } from './calculateWithdrawableAmount' +import { calculateRewardAmountCaller } from './calculateRewardAmount' + +describe('lockup/index.ts', () => { + describe('createLockupContract', () => { + it('check return object', () => { + const host = 'localhost' + const client = new Web3() + client.setProvider(new Web3.providers.HttpProvider(host)) + + const expected: ( + address?: string, + options?: CustomOptions + ) => WithdrawContract = (address?: string, options?: CustomOptions) => { + const withdrawContract = new client.eth.Contract( + [...withdrawAbi], + address, + { + ...options, + } + ) + return { + withdraw: createWithdrawCaller(withdrawContract, client), + getRewardsAmount: createGetRewardsAmountCaller(withdrawContract), + calculateWithdrawableAmount: + createCalculateWithdrawableAmountCaller(withdrawContract), + calculateRewardAmount: calculateRewardAmountCaller(withdrawContract), + contract: () => withdrawContract, + } + } + + const result = createWithdrawContract(client) + + expect(JSON.stringify(result)).toEqual(JSON.stringify(expected)) + expect( + JSON.stringify(result('0x0000000000000000000000000000000000000000')) + ).toEqual( + JSON.stringify(expected('0x0000000000000000000000000000000000000000')) + ) + }) + }) +}) diff --git a/lib/l2/withdraw/index.ts b/lib/l2/withdraw/index.ts new file mode 100644 index 000000000..0bb6a31aa --- /dev/null +++ b/lib/l2/withdraw/index.ts @@ -0,0 +1,49 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import Web3 from 'web3' +import { Contract } from 'web3-eth-contract/types' +import { withdrawAbi } from './abi' +import { CustomOptions } from '../../common/option' +import { createWithdrawCaller } from './withdraw' +import { createGetRewardsAmountCaller } from './getRewardsAmount' +import { createCalculateWithdrawableAmountCaller } from './calculateWithdrawableAmount' +import { always } from 'ramda' +import { calculateRewardAmountCaller } from './calculateRewardAmount' + +export type WithdrawContract = { + readonly withdraw: (propertyAddress: string) => Promise + readonly getRewardsAmount: (propertyAddress: string) => Promise + readonly calculateWithdrawableAmount: ( + propertyAddress: string, + accountAddress: string + ) => Promise + readonly calculateRewardAmount: ( + propertyAddress: string, + accountAddress: string + ) => Promise + readonly contract: () => Contract +} + +export type CreateWithdrawContract = ( + client: Web3 +) => (address?: string, options?: CustomOptions) => WithdrawContract + +export const createWithdrawContract: CreateWithdrawContract = + (client: Web3) => + (address?: string, options?: CustomOptions): WithdrawContract => { + const contractClient: Contract = new client.eth.Contract( + [...withdrawAbi], + address, + { + ...options, + } + ) + + return { + withdraw: createWithdrawCaller(contractClient, client), + getRewardsAmount: createGetRewardsAmountCaller(contractClient), + calculateWithdrawableAmount: + createCalculateWithdrawableAmountCaller(contractClient), + calculateRewardAmount: calculateRewardAmountCaller(contractClient), + contract: always(contractClient), + } + } diff --git a/lib/l2/withdraw/withdraw.spec.ts b/lib/l2/withdraw/withdraw.spec.ts new file mode 100644 index 000000000..8b409fdfd --- /dev/null +++ b/lib/l2/withdraw/withdraw.spec.ts @@ -0,0 +1,50 @@ +import { createWithdrawCaller } from './withdraw' +import { stubbedWeb3, stubbedSendTx } from '../../common/utils/for-test' + +describe('withdraw.spec.ts', () => { + describe('createwithdrawCaller', () => { + it('call success', async () => { + const value = true + + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + withdraw: (property: string) => ({ + send: jest.fn().mockImplementation(stubbedSendTx), + }), + }, + } + + const expected = value + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createWithdrawCaller(withdrawContract as any, stubbedWeb3) + + const result = await caller('0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5') + + expect(result).toEqual(expected) + }) + + it('call failure', async () => { + const withdrawContract = { + methods: { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + withdraw: (property: string) => ({ + send: jest + .fn() + .mockImplementation(async () => stubbedSendTx(undefined, true)), + }), + }, + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const caller = createWithdrawCaller(withdrawContract as any, stubbedWeb3) + + const result = await caller( + '0x80a25ACDD0797dfCe02dA25e4a55A4a334EE51c5' + ).catch((err) => err) + + expect(result).toBeInstanceOf(Error) + }) + }) +}) diff --git a/lib/l2/withdraw/withdraw.ts b/lib/l2/withdraw/withdraw.ts new file mode 100644 index 000000000..e12f7b064 --- /dev/null +++ b/lib/l2/withdraw/withdraw.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */ +import { Contract } from 'web3-eth-contract/types' +import Web3 from 'web3' +import { execute } from '../../common/utils/execute' +import { T } from 'ramda' + +export type CreateWithdrawCaller = ( + contract: Contract, + client: Web3 +) => (propertyAddress: string) => Promise + +export const createWithdrawCaller: CreateWithdrawCaller = + (contract: Contract, client: Web3) => async (propertyAddress) => + execute({ + contract, + method: 'withdraw', + mutation: true, + client, + args: [propertyAddress], + }).then(T) diff --git a/package.json b/package.json index f175bbcf2..1c92313c0 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "dist/*.js", "dist/*.ts", "lib/**/*.ts", + "l2", "bundled", "!**/*.spec.*" ], @@ -29,7 +30,7 @@ "test": "jest", "test:coverage": "jest --coverage", "prepack": "yarn test && yarn build", - "clean": "rimraf dist bundled", + "clean": "rimraf dist bundled l2", "prepare": "husky install" }, "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js index dc63fbabd..8b77e82b8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,7 +3,17 @@ import multi from '@rollup/plugin-multi-entry' import { getBabelOutputPlugin } from '@rollup/plugin-babel' import dts from 'rollup-plugin-dts' -const input = ['dist/lib/*.js', 'dist/lib/**/index.js', '!**/*.spec.*'] +const input = [ + 'dist/lib/**/*.js', + 'dist/lib/**/index.js', + '!**/*.spec.*', + '!dist/lib/l2/**/*', +] +const inputL2 = [ + 'dist/lib/l2/**/*.js', + 'dist/lib/l2/**/index.js', + '!**/*.spec.*', +] const plugins = [multi(), nodeResolve({ modulesOnly: true })] export default [ @@ -42,8 +52,52 @@ export default [ ], }, { - input: ['dist/lib/*.d.ts', 'dist/lib/**/index.d.ts', '!**/*.spec.*'], - output: [{ file: 'dist/dev-kit.d.ts', format: 'es' }], + input: [ + 'dist/lib/*.d.ts', + 'dist/lib/**/index.d.ts', + '!**/*.spec.*', + '!dist/lib/l2/**/*', + ], + output: [{ file: 'dist/index.d.ts', format: 'es' }], + plugins: [multi(), dts()], + }, + { + input: inputL2, + output: [ + { + file: './l2/index.mjs', + format: 'es', + }, + ], + plugins, + }, + { + input: inputL2, + output: [ + { + file: './l2/index.js', + format: 'cjs', + }, + ], + plugins: [ + ...plugins, + getBabelOutputPlugin({ + presets: [ + [ + '@babel/preset-env', + { + targets: { + node: '12', + }, + }, + ], + ], + }), + ], + }, + { + input: ['dist/lib/l2/*.d.ts', 'dist/lib/l2/**/index.d.ts', '!**/*.spec.*'], + output: [{ file: './l2/index.d.ts', format: 'es' }], plugins: [multi(), dts()], }, ]