generated from dev-protocol/khaos-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16ab9bf
commit 67e0936
Showing
18 changed files
with
721 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,6 @@ | ||
# Khaos Starter Kit | ||
# Khaos Update Cap | ||
|
||
How to start developing Khaos Functions | ||
|
||
## Environment | ||
|
||
First, fork this repository. | ||
|
||
Then clone the forked repository. | ||
|
||
```bash | ||
git clone [email protected]:your/khaos-starter-kit.git | ||
cd khaos-starter-kit | ||
``` | ||
|
||
## Development | ||
|
||
Edit the file in the `src` directory. You have to edit the following files: | ||
|
||
- src/abi.ts | ||
- src/addresses.ts | ||
- src/authorize.ts | ||
- src/event.ts | ||
- src/oraclize.ts | ||
- src/pack.ts | ||
|
||
And update the tests. | ||
|
||
You can add or remove dependencies if you want. | ||
update cap of DEV Protocol | ||
|
||
## Deployment | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { Abi } from '@devprotocol/khaos-core' | ||
import { lockupAbi } from './contract' | ||
|
||
export const abi: Abi = ['event Query()'] | ||
export const abi: Abi = lockupAbi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
/* eslint-disable functional/no-let */ | ||
/* eslint-disable functional/prefer-readonly-type */ | ||
import test from 'ava' | ||
import sinon from 'sinon' | ||
import { ethers } from 'ethers' | ||
import { addresses } from './addresses' | ||
import { getLockupAddress } from './test-utils' | ||
import * as contractModules from './contract' | ||
|
||
test('Returns mainnet address', async (t) => { | ||
let stub: sinon.SinonStub<[network: string], ethers.providers.BaseProvider> | ||
test.before(() => { | ||
const mainnetProvider = ethers.getDefaultProvider('homestead') | ||
const ropstenProvider = ethers.getDefaultProvider('ropsten') | ||
stub = sinon.stub(contractModules, 'getProvider') | ||
stub.withArgs('mainnet').returns(mainnetProvider) | ||
stub.withArgs('ropsten').returns(ropstenProvider) | ||
}) | ||
|
||
test('Returns mainnet lockup address', async (t) => { | ||
const provider = ethers.getDefaultProvider('homestead') | ||
const res = await addresses({ network: 'mainnet' }) | ||
t.is(res, '0x1510EA12a30E5c40b406660871b335feA32f29A') | ||
const lockupAddress = await getLockupAddress( | ||
'0x1D415aa39D647834786EB9B5a333A50e9935b796', | ||
provider | ||
) | ||
t.is(res, lockupAddress) | ||
}) | ||
|
||
test('Returns ropsten address', async (t) => { | ||
test('Returns ropsten lockup address', async (t) => { | ||
const provider = ethers.getDefaultProvider('ropsten') | ||
const res = await addresses({ network: 'ropsten' }) | ||
t.is(res, '0x609Fe85Dbb9487d55B5eF50451e20ba2Edc8F4B7') | ||
const lockupAddress = await getLockupAddress( | ||
'0xD6D07f1c048bDF2B3d5d9B6c25eD1FC5348D0A70', | ||
provider | ||
) | ||
t.is(res, lockupAddress) | ||
}) | ||
test.after(() => { | ||
stub.restore() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { FunctionAddresses } from '@devprotocol/khaos-core' | ||
import { getLockupContract, getProvider } from './contract' | ||
|
||
export const addresses: FunctionAddresses = async ({ network }) => | ||
network === 'mainnet' | ||
? '0x1510EA12a30E5c40b406660871b335feA32f29A' | ||
: '0x609Fe85Dbb9487d55B5eF50451e20ba2Edc8F4B7' | ||
export const addresses: FunctionAddresses = async ({ network }) => { | ||
const provider = getProvider(network) | ||
const lockup = await getLockupContract(provider) | ||
return lockup.address | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* eslint-disable functional/immutable-data */ | ||
import test from 'ava' | ||
import { ethers } from 'ethers' | ||
import { | ||
lockupAbi, | ||
getProvider, | ||
getLockupContract, | ||
getTransactionBlockNumber, | ||
} from './contract' | ||
import { getLockupAddress } from './test-utils' | ||
|
||
// lockupAbi | ||
test('lthis function can get the ABI of the Lockup contract.', (t) => { | ||
t.is(lockupAbi[0], 'event Lockedup(address, address, uint256)') | ||
t.is(lockupAbi[1], 'function updateCap(uint256) external') | ||
}) | ||
|
||
// getProvider | ||
test('get the provider of the mainnet.', async (t) => { | ||
process.env[`KHAOS_MAINNET_JSON_RPC`] = 'https://testdomain:1234' | ||
const provider = getProvider('mainnet') | ||
const converted = <ethers.providers.JsonRpcProvider>provider | ||
t.is(converted.connection.url, 'https://testdomain:1234') | ||
}) | ||
|
||
test('get the provider of the ropsten.', async (t) => { | ||
process.env[`KHAOS_ROPSTEN_JSON_RPC`] = 'https://testdomainropsten:1234' | ||
const provider = getProvider('ropsten') | ||
const converted = <ethers.providers.JsonRpcProvider>provider | ||
t.is(converted.connection.url, 'https://testdomainropsten:1234') | ||
}) | ||
|
||
// getLockupContract | ||
test('get the Lockup contract object for ropsten.', async (t) => { | ||
const provider = ethers.getDefaultProvider('ropsten') | ||
const lockup = await getLockupContract(provider) | ||
const lockupAddress = await getLockupAddress( | ||
'0xD6D07f1c048bDF2B3d5d9B6c25eD1FC5348D0A70', | ||
provider | ||
) | ||
t.is(lockupAddress, lockup.address) | ||
}) | ||
|
||
test('get the Lockup contract object for mainnet.', async (t) => { | ||
const provider = ethers.getDefaultProvider('homestead') | ||
const lockup = await getLockupContract(provider) | ||
const lockupAddress = await getLockupAddress( | ||
'0x1D415aa39D647834786EB9B5a333A50e9935b796', | ||
provider | ||
) | ||
t.is(lockupAddress, lockup.address) | ||
}) | ||
|
||
// getTransactionBlockNumber | ||
test('The block number of the transaction can be obtained.', async (t) => { | ||
const provider = ethers.getDefaultProvider('ropsten') | ||
const number = await getTransactionBlockNumber( | ||
provider, | ||
'0xfa052419311d16810602fadc56cf9bf20d4a575e0a6c08d25e17ca1ed245632a' | ||
) | ||
t.is(number, 9270014) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ethers, providers } from 'ethers' | ||
|
||
export const getLockupContract = async ( | ||
provider: providers.BaseProvider | ||
): Promise<ethers.Contract> => { | ||
const addressConfigContraCt = getAddressConfigContract(provider) | ||
const lockupAddress = await addressConfigContraCt.lockup() | ||
const lockupContract = new ethers.Contract(lockupAddress, lockupAbi, provider) | ||
return lockupContract | ||
} | ||
|
||
export const getProvider = (network: string): providers.BaseProvider => { | ||
const endpoint = process.env[`KHAOS_${network.toUpperCase()}_JSON_RPC`] | ||
return new ethers.providers.JsonRpcProvider(endpoint) | ||
} | ||
|
||
export const getTransactionBlockNumber = async ( | ||
provider: providers.BaseProvider, | ||
transactionHash: string | ||
): Promise<number> => { | ||
const transaction = await provider.getTransaction(transactionHash) | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return transaction.blockNumber! | ||
} | ||
|
||
export const lockupAbi = [ | ||
'event Lockedup(address, address, uint256)', | ||
'function updateCap(uint256) external', | ||
] | ||
|
||
const getAddressConfigContract = ( | ||
provider: providers.BaseProvider | ||
): ethers.Contract => { | ||
const addressConfigAddress = isMainNet(provider) | ||
? '0x1D415aa39D647834786EB9B5a333A50e9935b796' | ||
: '0xD6D07f1c048bDF2B3d5d9B6c25eD1FC5348D0A70' | ||
const abi = ['function lockup() external view returns (address)'] | ||
return new ethers.Contract(addressConfigAddress, abi, provider) | ||
} | ||
|
||
const isMainNet = (provider: providers.BaseProvider): boolean => { | ||
return provider.network.chainId === 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import test from 'ava' | ||
import { event } from './event' | ||
|
||
test('Returns `Query` when passed network is mainnet', async (t) => { | ||
t.is(await event({ network: 'mainnet' }), 'Query') | ||
test('Returns `Lockedup` when passed network is mainnet', async (t) => { | ||
t.is(await event({ network: 'mainnet' }), 'Lockedup') | ||
}) | ||
|
||
test('Returns `Query` when passed network is ropsten', async (t) => { | ||
t.is(await event({ network: 'ropsten' }), 'Query') | ||
test('Returns `Lockedup` when passed network is ropsten', async (t) => { | ||
t.is(await event({ network: 'ropsten' }), 'Lockedup') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { FunctionEvent } from '@devprotocol/khaos-core' | ||
import { always } from 'ramda' | ||
|
||
export const event: FunctionEvent = always(Promise.resolve('Query')) | ||
export const event: FunctionEvent = always(Promise.resolve('Lockedup')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable functional/immutable-data */ | ||
import test from 'ava' | ||
import { ethers } from 'ethers' | ||
import BigNumber from 'bignumber.js' | ||
import { | ||
createGraphQLPropertyLockupSumValuesFetcher, | ||
createGraphQLPropertyAuthenticationFetcher, | ||
graphql, | ||
GraphQLPropertyLockupSumValuesResponse, | ||
GraphQLPropertyPropertyAuthenticationResponse, | ||
} from './graphql' | ||
|
||
test('get the data for lockup sum values.', async (t) => { | ||
process.env[`KHAOS_MAINNET_GRAPHQL`] = 'https://api.devprtcl.com/v1/graphql' | ||
const fetchGraphQL = createGraphQLPropertyLockupSumValuesFetcher( | ||
graphql('mainnet') | ||
) | ||
const lockupSumValues = await (async () => | ||
new Promise< | ||
GraphQLPropertyLockupSumValuesResponse['data']['property_lockup_sum_values'] | ||
>((resolve) => { | ||
const f = async ( | ||
prev: GraphQLPropertyLockupSumValuesResponse['data']['property_lockup_sum_values'] = [] | ||
): Promise<void> => { | ||
const { data } = await fetchGraphQL() | ||
const { property_lockup_sum_values: items } = data | ||
const next = [...prev, ...items] | ||
resolve(next) | ||
} | ||
f().catch(console.error) | ||
}))() | ||
t.is(lockupSumValues.length > 0, true) | ||
lockupSumValues.map((data) => { | ||
t.is(ethers.utils.isAddress(data.property_address), true) | ||
const tmp = new BigNumber(data.sum_values) | ||
t.is(tmp.gt(new BigNumber(0)), true) | ||
}) | ||
}) | ||
|
||
test('Property_authintication data can be retrieved.', async (t) => { | ||
process.env[`KHAOS_MAINNET_GRAPHQL`] = 'https://api.devprtcl.com/v1/graphql' | ||
const fetchGraphQL = createGraphQLPropertyAuthenticationFetcher( | ||
graphql('mainnet') | ||
) | ||
const lockupSumValues = await (async () => | ||
new Promise< | ||
GraphQLPropertyPropertyAuthenticationResponse['data']['property_authentication'] | ||
>((resolve) => { | ||
const f = async ( | ||
prev: GraphQLPropertyPropertyAuthenticationResponse['data']['property_authentication'] = [] | ||
): Promise<void> => { | ||
const { data } = await fetchGraphQL() | ||
const { property_authentication: items } = data | ||
const next = [...prev, ...items] | ||
resolve(next) | ||
} | ||
f().catch(console.error) | ||
}))() | ||
t.is(lockupSumValues.length > 0, true) | ||
lockupSumValues.map((data) => { | ||
t.is(ethers.utils.isAddress(data.property), true) | ||
}) | ||
}) |
Oops, something went wrong.