mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Pull from origin v4main
This commit is contained in:
commit
5716a904e0
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -58,8 +58,6 @@ jobs:
|
|||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
||||||
env:
|
|
||||||
CONTRACTS_VERSION: v1.0.0-alpha.31
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Wait for contracts deployment
|
- name: Wait for contracts deployment
|
||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
@ -117,8 +115,6 @@ jobs:
|
|||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
||||||
env:
|
|
||||||
CONTRACTS_VERSION: v1.0.0-alpha.31
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build:metadata
|
- run: npm run build:metadata
|
||||||
|
|
||||||
|
2860
CHANGELOG.md
2860
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
32
package-lock.json
generated
32
package-lock.json
generated
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@oceanprotocol/lib",
|
"name": "@oceanprotocol/lib",
|
||||||
"version": "1.0.0-next.41",
|
"version": "1.0.0-next.44",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@oceanprotocol/lib",
|
"name": "@oceanprotocol/lib",
|
||||||
"version": "1.0.0-next.40",
|
"version": "1.0.0-next.44",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^1.0.0-alpha.31",
|
"@oceanprotocol/contracts": "^1.0.0-alpha.34",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
@ -24,7 +24,7 @@
|
|||||||
"@types/chai-spies": "^1.0.3",
|
"@types/chai-spies": "^1.0.3",
|
||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/mocha": "^9.1.1",
|
"@types/mocha": "^9.1.1",
|
||||||
"@types/node": "^17.0.31",
|
"@types/node": "^17.0.34",
|
||||||
"@types/node-fetch": "^3.0.3",
|
"@types/node-fetch": "^3.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
||||||
"@typescript-eslint/parser": "^4.33.0",
|
"@typescript-eslint/parser": "^4.33.0",
|
||||||
@ -2471,9 +2471,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@oceanprotocol/contracts": {
|
"node_modules/@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.31",
|
"version": "1.0.0-alpha.34",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.31.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz",
|
||||||
"integrity": "sha512-WqrhjO0Qu8Bxdr2dAkdUL1Q/rHEkTuhx8OT4J/uJltnlxykCo6F8raNQAlhdh+84hm2Bv1irXE+PdpizNLwntQ=="
|
"integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w=="
|
||||||
},
|
},
|
||||||
"node_modules/@octokit/auth-token": {
|
"node_modules/@octokit/auth-token": {
|
||||||
"version": "2.5.0",
|
"version": "2.5.0",
|
||||||
@ -3021,9 +3021,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "17.0.31",
|
"version": "17.0.34",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.31.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.34.tgz",
|
||||||
"integrity": "sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q=="
|
"integrity": "sha512-XImEz7XwTvDBtzlTnm8YvMqGW/ErMWBsKZ+hMTvnDIjGCKxwK5Xpc+c/oQjOauwq8M4OS11hEkpjX8rrI/eEgA=="
|
||||||
},
|
},
|
||||||
"node_modules/@types/node-fetch": {
|
"node_modules/@types/node-fetch": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
@ -19610,9 +19610,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@oceanprotocol/contracts": {
|
"@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.31",
|
"version": "1.0.0-alpha.34",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.31.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz",
|
||||||
"integrity": "sha512-WqrhjO0Qu8Bxdr2dAkdUL1Q/rHEkTuhx8OT4J/uJltnlxykCo6F8raNQAlhdh+84hm2Bv1irXE+PdpizNLwntQ=="
|
"integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w=="
|
||||||
},
|
},
|
||||||
"@octokit/auth-token": {
|
"@octokit/auth-token": {
|
||||||
"version": "2.5.0",
|
"version": "2.5.0",
|
||||||
@ -20079,9 +20079,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "17.0.31",
|
"version": "17.0.34",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.31.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.34.tgz",
|
||||||
"integrity": "sha512-AR0x5HbXGqkEx9CadRH3EBYx/VkiUgZIhP4wvPn/+5KIsgpNoyFaRlVe0Zlx9gRtg8fA06a9tskE2MSN7TcG4Q=="
|
"integrity": "sha512-XImEz7XwTvDBtzlTnm8YvMqGW/ErMWBsKZ+hMTvnDIjGCKxwK5Xpc+c/oQjOauwq8M4OS11hEkpjX8rrI/eEgA=="
|
||||||
},
|
},
|
||||||
"@types/node-fetch": {
|
"@types/node-fetch": {
|
||||||
"version": "3.0.3",
|
"version": "3.0.3",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@oceanprotocol/lib",
|
"name": "@oceanprotocol/lib",
|
||||||
"source": "./src/index.ts",
|
"source": "./src/index.ts",
|
||||||
"version": "1.0.0-next.41",
|
"version": "1.0.0-next.44",
|
||||||
"description": "JavaScript client library for Ocean Protocol",
|
"description": "JavaScript client library for Ocean Protocol",
|
||||||
"main": "./dist/lib.js",
|
"main": "./dist/lib.js",
|
||||||
"umd:main": "dist/lib.umd.js",
|
"umd:main": "dist/lib.umd.js",
|
||||||
@ -61,7 +61,7 @@
|
|||||||
"web3": "^1.7.3"
|
"web3": "^1.7.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^1.0.0-alpha.31",
|
"@oceanprotocol/contracts": "^1.0.0-alpha.34",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
@ -76,7 +76,7 @@
|
|||||||
"@types/chai-spies": "^1.0.3",
|
"@types/chai-spies": "^1.0.3",
|
||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/mocha": "^9.1.1",
|
"@types/mocha": "^9.1.1",
|
||||||
"@types/node": "^17.0.31",
|
"@types/node": "^17.0.34",
|
||||||
"@types/node-fetch": "^3.0.3",
|
"@types/node-fetch": "^3.0.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
||||||
"@typescript-eslint/parser": "^4.33.0",
|
"@typescript-eslint/parser": "^4.33.0",
|
||||||
|
@ -15,3 +15,14 @@ export interface ProviderInitialize {
|
|||||||
computeAddress: string
|
computeAddress: string
|
||||||
providerFee: ProviderFees
|
providerFee: ProviderFees
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProviderComputeInitialize {
|
||||||
|
datatoken?: string
|
||||||
|
validOrder?: string
|
||||||
|
providerFee?: ProviderFees
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProviderComputeInitializeResults {
|
||||||
|
algorithm?: ProviderComputeInitialize
|
||||||
|
datasets?: ProviderComputeInitialize[]
|
||||||
|
}
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
getErcCreationParams,
|
getErcCreationParams,
|
||||||
getPoolCreationParams,
|
getPoolCreationParams,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
|
estimateGas,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
@ -50,7 +51,6 @@ export interface NftCreateData {
|
|||||||
* Provides an interface for NFT Factory contract
|
* Provides an interface for NFT Factory contract
|
||||||
*/
|
*/
|
||||||
export class NftFactory {
|
export class NftFactory {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public factory721Address: string
|
public factory721Address: string
|
||||||
public factory721Abi: AbiItem | AbiItem[]
|
public factory721Abi: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
@ -87,11 +87,9 @@ export class NftFactory {
|
|||||||
* @return {Promise<string>} NFT datatoken address
|
* @return {Promise<string>} NFT datatoken address
|
||||||
*/
|
*/
|
||||||
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
|
public async estGasCreateNFT(address: string, nftData: NftCreateData): Promise<string> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.deployERC721Contract,
|
||||||
estGas = await this.factory721.methods
|
|
||||||
.deployERC721Contract(
|
|
||||||
nftData.name,
|
nftData.name,
|
||||||
nftData.symbol,
|
nftData.symbol,
|
||||||
nftData.templateIndex,
|
nftData.templateIndex,
|
||||||
@ -101,11 +99,6 @@ export class NftFactory {
|
|||||||
nftData.transferable,
|
nftData.transferable,
|
||||||
nftData.owner
|
nftData.owner
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +125,18 @@ export class NftFactory {
|
|||||||
if ((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
|
if ((await this.getNFTTemplate(nftData.templateIndex)).isActive === false) {
|
||||||
throw new Error(`Template is not active`)
|
throw new Error(`Template is not active`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasCreateNFT(address, nftData)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.deployERC721Contract,
|
||||||
|
nftData.name,
|
||||||
|
nftData.symbol,
|
||||||
|
nftData.templateIndex,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
nftData.tokenURI,
|
||||||
|
nftData.transferable,
|
||||||
|
nftData.owner
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -254,16 +258,11 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.add721TokenTemplate,
|
||||||
estGas = await this.factory721.methods
|
templateAddress
|
||||||
.add721TokenTemplate(templateAddress)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -283,7 +282,11 @@ export class NftFactory {
|
|||||||
throw new Error(`Template cannot be ZERO address`)
|
throw new Error(`Template cannot be ZERO address`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddNFTTemplate(address, templateAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.add721TokenTemplate,
|
||||||
|
templateAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke add721TokenTemplate function of the contract
|
// Invoke add721TokenTemplate function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -307,16 +310,11 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.disable721TokenTemplate,
|
||||||
estGas = await this.factory721.methods
|
templateIndex
|
||||||
.disable721TokenTemplate(templateIndex)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -339,7 +337,11 @@ export class NftFactory {
|
|||||||
if (templateIndex === 0) {
|
if (templateIndex === 0) {
|
||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasDisableNFTTemplate(address, templateIndex)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.disable721TokenTemplate,
|
||||||
|
templateIndex
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -363,16 +365,11 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.reactivate721TokenTemplate,
|
||||||
estGas = await this.factory721.methods
|
templateIndex
|
||||||
.reactivate721TokenTemplate(templateIndex)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -396,7 +393,11 @@ export class NftFactory {
|
|||||||
throw new Error(`Template index cannot be ZERO`)
|
throw new Error(`Template index cannot be ZERO`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasReactivateNFTTemplate(address, templateIndex)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.reactivate721TokenTemplate,
|
||||||
|
templateIndex
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -420,17 +421,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.factory721.methods.addTokenTemplate, templateAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.factory721.methods
|
|
||||||
.addTokenTemplate(templateAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -450,7 +441,11 @@ export class NftFactory {
|
|||||||
throw new Error(`Template cannot be address ZERO`)
|
throw new Error(`Template cannot be address ZERO`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddTokenTemplate(address, templateAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.addTokenTemplate,
|
||||||
|
templateAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -474,16 +469,11 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.disableTokenTemplate,
|
||||||
estGas = await this.factory721.methods
|
templateIndex
|
||||||
.disableTokenTemplate(templateIndex)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -509,7 +499,11 @@ export class NftFactory {
|
|||||||
if ((await this.getTokenTemplate(templateIndex)).isActive === false) {
|
if ((await this.getTokenTemplate(templateIndex)).isActive === false) {
|
||||||
throw new Error(`Template is already disabled`)
|
throw new Error(`Template is already disabled`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasDisableTokenTemplate(address, templateIndex)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.disableTokenTemplate,
|
||||||
|
templateIndex
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -533,16 +527,11 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
templateIndex: number
|
templateIndex: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.factory721.methods.reactivateTokenTemplate,
|
||||||
estGas = await this.factory721.methods
|
templateIndex
|
||||||
.reactivateTokenTemplate(templateIndex)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -569,7 +558,11 @@ export class NftFactory {
|
|||||||
throw new Error(`Template is already active`)
|
throw new Error(`Template is already active`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasReactivateTokenTemplate(address, templateIndex)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.reactivateTokenTemplate,
|
||||||
|
templateIndex
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -592,16 +585,7 @@ export class NftFactory {
|
|||||||
address: string,
|
address: string,
|
||||||
orders: TokenOrder[]
|
orders: TokenOrder[]
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.factory721.methods.startMultipleTokenOrder, orders)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.factory721.methods
|
|
||||||
.startMultipleTokenOrder(orders)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -624,7 +608,11 @@ export class NftFactory {
|
|||||||
throw new Error(`Too many orders`)
|
throw new Error(`Too many orders`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasStartMultipleTokenOrder(address, orders)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.startMultipleTokenOrder,
|
||||||
|
orders
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
@ -651,18 +639,13 @@ export class NftFactory {
|
|||||||
nftCreateData: NftCreateData,
|
nftCreateData: NftCreateData,
|
||||||
ercParams: Erc20CreateParams
|
ercParams: Erc20CreateParams
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
// Get estimated gas value
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
estGas = await this.factory721.methods
|
return estimateGas(
|
||||||
.createNftWithErc20(nftCreateData, ercCreateData)
|
address,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
this.factory721.methods.createNftWithErc20,
|
||||||
} catch (e) {
|
nftCreateData,
|
||||||
estGas = gasLimitDefault
|
ercCreateData
|
||||||
}
|
)
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -681,7 +664,13 @@ export class NftFactory {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
|
|
||||||
const estGas = await this.estGasCreateNftWithErc20(address, nftCreateData, ercParams)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.createNftWithErc20,
|
||||||
|
nftCreateData,
|
||||||
|
ercCreateData
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
.createNftWithErc20(nftCreateData, ercCreateData)
|
.createNftWithErc20(nftCreateData, ercCreateData)
|
||||||
@ -708,18 +697,15 @@ export class NftFactory {
|
|||||||
ercParams: Erc20CreateParams,
|
ercParams: Erc20CreateParams,
|
||||||
poolParams: PoolCreationParams
|
poolParams: PoolCreationParams
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
||||||
estGas = await this.factory721.methods
|
return estimateGas(
|
||||||
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
|
address,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
this.factory721.methods.createNftWithErc20WithPool,
|
||||||
} catch (e) {
|
nftCreateData,
|
||||||
estGas = gasLimitDefault
|
ercCreateData,
|
||||||
}
|
poolData
|
||||||
return estGas
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -738,15 +724,17 @@ export class NftFactory {
|
|||||||
ercParams: Erc20CreateParams,
|
ercParams: Erc20CreateParams,
|
||||||
poolParams: PoolCreationParams
|
poolParams: PoolCreationParams
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estGasCreateNftErc20WithPool(
|
|
||||||
address,
|
|
||||||
nftCreateData,
|
|
||||||
ercParams,
|
|
||||||
poolParams
|
|
||||||
)
|
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
const poolData = await getPoolCreationParams(this.web3, poolParams)
|
||||||
|
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.factory721.methods.createNftWithErc20WithPool,
|
||||||
|
nftCreateData,
|
||||||
|
ercCreateData,
|
||||||
|
poolData
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.factory721.methods
|
const trxReceipt = await this.factory721.methods
|
||||||
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
|
.createNftWithErc20WithPool(nftCreateData, ercCreateData, poolData)
|
||||||
@ -772,20 +760,15 @@ export class NftFactory {
|
|||||||
ercParams: Erc20CreateParams,
|
ercParams: Erc20CreateParams,
|
||||||
freParams: FreCreationParams
|
freParams: FreCreationParams
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
|
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
const fixedData = await getFreCreationParams(freParams)
|
const fixedData = await getFreCreationParams(freParams)
|
||||||
|
return estimateGas(
|
||||||
try {
|
address,
|
||||||
estGas = await this.factory721.methods
|
this.factory721.methods.createNftWithErc20WithFixedRate,
|
||||||
.createNftWithErc20WithFixedRate(nftCreateData, ercCreateData, fixedData)
|
nftCreateData,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
ercCreateData,
|
||||||
} catch (e) {
|
fixedData
|
||||||
estGas = gasLimitDefault
|
)
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -807,11 +790,12 @@ export class NftFactory {
|
|||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
const fixedData = getFreCreationParams(freParams)
|
const fixedData = getFreCreationParams(freParams)
|
||||||
|
|
||||||
const estGas = await this.estGasCreateNftErc20WithFixedRate(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.factory721.methods.createNftWithErc20WithFixedRate,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercParams,
|
ercCreateData,
|
||||||
freParams
|
fixedData
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
@ -839,20 +823,14 @@ export class NftFactory {
|
|||||||
ercParams: Erc20CreateParams,
|
ercParams: Erc20CreateParams,
|
||||||
dispenserParams: DispenserCreationParams
|
dispenserParams: DispenserCreationParams
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
|
|
||||||
const ercCreateData = getErcCreationParams(ercParams)
|
const ercCreateData = getErcCreationParams(ercParams)
|
||||||
|
return estimateGas(
|
||||||
try {
|
address,
|
||||||
estGas = await this.factory721.methods
|
this.factory721.methods.createNftWithErc20WithDispenser,
|
||||||
.createNftWithErc20WithDispenser(nftCreateData, ercCreateData, dispenserParams)
|
nftCreateData,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
ercCreateData,
|
||||||
} catch (e) {
|
dispenserParams
|
||||||
estGas = gasLimitDefault
|
)
|
||||||
LoggerInstance.error('Failed to estimate gas for createNftErc20WithDispenser', e)
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -876,10 +854,11 @@ export class NftFactory {
|
|||||||
dispenserParams.maxBalance = Web3.utils.toWei(dispenserParams.maxBalance)
|
dispenserParams.maxBalance = Web3.utils.toWei(dispenserParams.maxBalance)
|
||||||
dispenserParams.maxTokens = Web3.utils.toWei(dispenserParams.maxTokens)
|
dispenserParams.maxTokens = Web3.utils.toWei(dispenserParams.maxTokens)
|
||||||
|
|
||||||
const estGas = await this.estGasCreateNftErc20WithDispenser(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.factory721.methods.createNftWithErc20WithDispenser,
|
||||||
nftCreateData,
|
nftCreateData,
|
||||||
ercParams,
|
ercCreateData,
|
||||||
dispenserParams
|
dispenserParams
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import Web3 from 'web3'
|
|||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { AbiItem } from 'web3-utils'
|
import { AbiItem } from 'web3-utils'
|
||||||
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||||
import { getFairGasPrice, setContractDefaults, ConfigHelper } from '../utils'
|
import { getFairGasPrice, setContractDefaults, ConfigHelper, estimateGas } from '../utils'
|
||||||
import { Operation } from '../@types/Router'
|
import { Operation } from '../@types/Router'
|
||||||
import { Config } from '../models/index.js'
|
import { Config } from '../models/index.js'
|
||||||
|
|
||||||
@ -11,7 +11,6 @@ import { Config } from '../models/index.js'
|
|||||||
* Provides an interface for FactoryRouter contract
|
* Provides an interface for FactoryRouter contract
|
||||||
*/
|
*/
|
||||||
export class Router {
|
export class Router {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public routerAddress: string
|
public routerAddress: string
|
||||||
public RouterAbi: AbiItem | AbiItem[]
|
public RouterAbi: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
@ -48,16 +47,7 @@ export class Router {
|
|||||||
* @return {Promise<TransactionReceipt>} Transaction receipt
|
* @return {Promise<TransactionReceipt>} Transaction receipt
|
||||||
*/
|
*/
|
||||||
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
|
public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.buyDTBatch, operations)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.buyDTBatch(operations)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,7 +60,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
operations: Operation[]
|
operations: Operation[]
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estGasBuyDTBatch(address, operations)
|
const estGas = await estimateGas(address, this.router.methods.buyDTBatch, operations)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.buyDTBatch(operations).send({
|
const trxReceipt = await this.router.methods.buyDTBatch(operations).send({
|
||||||
@ -135,19 +125,8 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) {
|
): Promise<any> {
|
||||||
const routerContract = contractInstance || this.router
|
return estimateGas(address, this.router.methods.addApprovedToken, tokenAddress)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await routerContract.methods
|
|
||||||
.addApprovedToken(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,7 +143,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddApprovedToken(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.addApprovedToken,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addApprovedToken(tokenAddress).send({
|
const trxReceipt = await this.router.methods.addApprovedToken(tokenAddress).send({
|
||||||
@ -187,19 +170,8 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
) {
|
): Promise<any> {
|
||||||
const routerContract = contractInstance || this.router
|
return estimateGas(address, this.router.methods.removeApprovedToken, tokenAddress)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await routerContract.methods
|
|
||||||
.removeApprovedToken(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,7 +188,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveApprovedToken(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.removeApprovedToken,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.removeApprovedToken(tokenAddress).send({
|
const trxReceipt = await this.router.methods.removeApprovedToken(tokenAddress).send({
|
||||||
@ -235,17 +211,7 @@ export class Router {
|
|||||||
* @return {Promise<TransactionReceipt>}
|
* @return {Promise<TransactionReceipt>}
|
||||||
*/
|
*/
|
||||||
public async estGasAddSSContract(address: string, tokenAddress: string): Promise<any> {
|
public async estGasAddSSContract(address: string, tokenAddress: string): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.addSSContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.addSSContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -262,7 +228,12 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddSSContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.addSSContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addSSContract(tokenAddress).send({
|
const trxReceipt = await this.router.methods.addSSContract(tokenAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -283,17 +254,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.removeSSContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.removeSSContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,7 +271,12 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveSSContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.removeSSContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({
|
const trxReceipt = await this.router.methods.removeSSContract(tokenAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -331,17 +297,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.addFixedRateContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.addFixedRateContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -358,7 +314,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddFixedRateContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.addFixedRateContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addFixedRateContract(tokenAddress).send({
|
const trxReceipt = await this.router.methods.addFixedRateContract(tokenAddress).send({
|
||||||
@ -380,17 +340,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.removeFixedRateContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.removeFixedRateContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -407,7 +357,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveFixedRateContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.removeFixedRateContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke removeFixedRateContract function of the contract
|
// Invoke removeFixedRateContract function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.router.methods
|
||||||
@ -431,17 +385,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.addDispenserContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.addDispenserContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -458,7 +402,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddDispenserContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.addDispenserContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
|
const trxReceipt = await this.router.methods.addDispenserContract(tokenAddress).send({
|
||||||
@ -480,17 +428,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.removeDispenserContract, tokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.removeDispenserContract(tokenAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -507,7 +445,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveDispenserContract(address, tokenAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.removeDispenserContract,
|
||||||
|
tokenAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.router.methods
|
||||||
@ -548,17 +490,14 @@ export class Router {
|
|||||||
newConsumeFee: number,
|
newConsumeFee: number,
|
||||||
newProviderFee: number
|
newProviderFee: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.router.methods.updateOPCFee,
|
||||||
estGas = await this.router.methods
|
newSwapOceanFee,
|
||||||
.updateOPCFee(newSwapOceanFee, newSwapNonOceanFee, newConsumeFee, newProviderFee)
|
newSwapNonOceanFee,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
newConsumeFee,
|
||||||
} catch (e) {
|
newProviderFee
|
||||||
estGas = gasLimitDefault
|
)
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -581,8 +520,9 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasUpdateOPCFee(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.router.methods.updateOPCFee,
|
||||||
newSwapOceanFee,
|
newSwapOceanFee,
|
||||||
newSwapNonOceanFee,
|
newSwapNonOceanFee,
|
||||||
newConsumeFee,
|
newConsumeFee,
|
||||||
@ -611,17 +551,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.addPoolTemplate, templateAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.addPoolTemplate(templateAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -638,7 +568,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddPoolTemplate(address, templateAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.addPoolTemplate,
|
||||||
|
templateAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods.addPoolTemplate(templateAddress).send({
|
const trxReceipt = await this.router.methods.addPoolTemplate(templateAddress).send({
|
||||||
@ -660,16 +594,7 @@ export class Router {
|
|||||||
address: string,
|
address: string,
|
||||||
templateAddress: string
|
templateAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, this.router.methods.removePoolTemplate, templateAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await this.router.methods
|
|
||||||
.removePoolTemplate(templateAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -686,7 +611,11 @@ export class Router {
|
|||||||
throw new Error(`Caller is not Router Owner`)
|
throw new Error(`Caller is not Router Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemovePoolTemplate(address, templateAddress)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.router.methods.removePoolTemplate,
|
||||||
|
templateAddress
|
||||||
|
)
|
||||||
|
|
||||||
// Invoke createToken function of the contract
|
// Invoke createToken function of the contract
|
||||||
const trxReceipt = await this.router.methods
|
const trxReceipt = await this.router.methods
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
unitsToAmount,
|
unitsToAmount,
|
||||||
amountToUnits,
|
amountToUnits,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
|
estimateGas,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
@ -37,7 +38,6 @@ const MaxUint256 =
|
|||||||
export class Pool {
|
export class Pool {
|
||||||
public poolAbi: AbiItem | AbiItem[]
|
public poolAbi: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
private config: Config
|
private config: Config
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -112,16 +112,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(account, poolContract.methods.setSwapFee, fee)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await poolContract.methods
|
|
||||||
.setSwapFee(fee)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,7 +133,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estSetSwapFee(account, poolAddress, fee)
|
const estGas = await estimateGas(account, pool.methods.setSwapFee, fee)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.setSwapFee(this.web3.utils.toWei(fee)).send({
|
result = await pool.methods.setSwapFee(this.web3.utils.toWei(fee)).send({
|
||||||
@ -338,25 +329,6 @@ export class Pool {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get OPC Collector of this pool
|
|
||||||
* @param {String} poolAddress
|
|
||||||
* @return {String}
|
|
||||||
*/
|
|
||||||
async getOPCCollector(poolAddress: string): Promise<string> {
|
|
||||||
const pool = setContractDefaults(
|
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
|
||||||
this.config
|
|
||||||
)
|
|
||||||
let result = null
|
|
||||||
try {
|
|
||||||
result = await pool.methods._opcCollector().call()
|
|
||||||
} catch (e) {
|
|
||||||
LoggerInstance.error(`ERROR: Failed to get OPF Collector address: ${e.message}`)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get if a token is bounded to a pool
|
* Get if a token is bounded to a pool
|
||||||
* Returns true if token is bound
|
* Returns true if token is bound
|
||||||
@ -631,16 +603,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, poolContract.methods.collectOPC)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await poolContract.methods
|
|
||||||
.collectOPC()
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -655,7 +618,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estCollectOPC(address, poolAddress)
|
const estGas = await estimateGas(address, pool.methods.collectOPC)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.collectOPC().send({
|
result = await pool.methods.collectOPC().send({
|
||||||
@ -689,16 +652,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, poolContract.methods.collectMarketFee)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await poolContract.methods
|
|
||||||
.collectMarketFee()
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -720,7 +674,7 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estCollectMarketFee(address, poolAddress)
|
const estGas = await estimateGas(address, pool.methods.collectMarketFee)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.collectMarketFee().send({
|
result = await pool.methods.collectMarketFee().send({
|
||||||
@ -757,16 +711,12 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
poolContract.methods.updatePublishMarketFee,
|
||||||
estGas = await poolContract.methods
|
newPublishMarketAddress,
|
||||||
.updatePublishMarketFee(newPublishMarketAddress, newPublishMarketSwapFee)
|
this.web3.utils.toWei(newPublishMarketSwapFee)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -792,9 +742,9 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
const estGas = await this.estUpdatePublishMarketFee(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
poolAddress,
|
pool.methods.updatePublishMarketFee,
|
||||||
newPublishMarketAddress,
|
newPublishMarketAddress,
|
||||||
this.web3.utils.toWei(newPublishMarketSwapFee)
|
this.web3.utils.toWei(newPublishMarketSwapFee)
|
||||||
)
|
)
|
||||||
@ -857,11 +807,9 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
: MaxUint256
|
: MaxUint256
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
poolContract.methods.swapExactAmountIn,
|
||||||
estGas = await poolContract.methods
|
|
||||||
.swapExactAmountIn(
|
|
||||||
[
|
[
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
tokenInOutMarket.tokenOut,
|
tokenInOutMarket.tokenOut,
|
||||||
@ -874,11 +822,6 @@ export class Pool {
|
|||||||
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -910,13 +853,6 @@ export class Pool {
|
|||||||
throw new Error(`tokenAmountIn is greater than ${maxSwap.toString()}`)
|
throw new Error(`tokenAmountIn is greater than ${maxSwap.toString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estSwapExactAmountIn(
|
|
||||||
address,
|
|
||||||
poolAddress,
|
|
||||||
tokenInOutMarket,
|
|
||||||
amountsInOutMaxFee
|
|
||||||
)
|
|
||||||
|
|
||||||
const tokenAmountIn = await this.amountToUnits(
|
const tokenAmountIn = await this.amountToUnits(
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
amountsInOutMaxFee.tokenAmountIn,
|
amountsInOutMaxFee.tokenAmountIn,
|
||||||
@ -929,8 +865,6 @@ export class Pool {
|
|||||||
tokenInOutMarket.tokenOutDecimals
|
tokenInOutMarket.tokenOutDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
let result = null
|
|
||||||
|
|
||||||
const maxPrice = amountsInOutMaxFee.maxPrice
|
const maxPrice = amountsInOutMaxFee.maxPrice
|
||||||
? await this.amountToUnits(
|
? await this.amountToUnits(
|
||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
@ -938,6 +872,23 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
: MaxUint256
|
: MaxUint256
|
||||||
|
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
pool.methods.swapExactAmountIn,
|
||||||
|
[
|
||||||
|
tokenInOutMarket.tokenIn,
|
||||||
|
tokenInOutMarket.tokenOut,
|
||||||
|
tokenInOutMarket.marketFeeAddress
|
||||||
|
],
|
||||||
|
[
|
||||||
|
tokenAmountIn,
|
||||||
|
minAmountOut,
|
||||||
|
maxPrice,
|
||||||
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods
|
||||||
.swapExactAmountIn(
|
.swapExactAmountIn(
|
||||||
@ -988,8 +939,6 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
|
|
||||||
const maxAmountIn = await this.amountToUnits(
|
const maxAmountIn = await this.amountToUnits(
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
amountsInOutMaxFee.maxAmountIn,
|
amountsInOutMaxFee.maxAmountIn,
|
||||||
@ -1009,10 +958,9 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
: MaxUint256
|
: MaxUint256
|
||||||
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
address,
|
||||||
estGas = await poolContract.methods
|
poolContract.methods.swapExactAmountOut,
|
||||||
.swapExactAmountOut(
|
|
||||||
[
|
[
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
tokenInOutMarket.tokenOut,
|
tokenInOutMarket.tokenOut,
|
||||||
@ -1025,11 +973,6 @@ export class Pool {
|
|||||||
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1057,13 +1000,6 @@ export class Pool {
|
|||||||
throw new Error(`tokenAmountOut is greater than ${maxSwap.toString()}`)
|
throw new Error(`tokenAmountOut is greater than ${maxSwap.toString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estSwapExactAmountOut(
|
|
||||||
account,
|
|
||||||
poolAddress,
|
|
||||||
tokenInOutMarket,
|
|
||||||
amountsInOutMaxFee
|
|
||||||
)
|
|
||||||
|
|
||||||
const maxAmountIn = await this.amountToUnits(
|
const maxAmountIn = await this.amountToUnits(
|
||||||
tokenInOutMarket.tokenIn,
|
tokenInOutMarket.tokenIn,
|
||||||
amountsInOutMaxFee.maxAmountIn,
|
amountsInOutMaxFee.maxAmountIn,
|
||||||
@ -1083,6 +1019,22 @@ export class Pool {
|
|||||||
)
|
)
|
||||||
: MaxUint256
|
: MaxUint256
|
||||||
|
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
account,
|
||||||
|
pool.methods.swapExactAmountOut,
|
||||||
|
[
|
||||||
|
tokenInOutMarket.tokenIn,
|
||||||
|
tokenInOutMarket.tokenOut,
|
||||||
|
tokenInOutMarket.marketFeeAddress
|
||||||
|
],
|
||||||
|
[
|
||||||
|
maxAmountIn,
|
||||||
|
tokenAmountOut,
|
||||||
|
maxPrice,
|
||||||
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods
|
result = await pool.methods
|
||||||
.swapExactAmountOut(
|
.swapExactAmountOut(
|
||||||
@ -1133,16 +1085,12 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
poolContract.methods.joinswapExternAmountIn,
|
||||||
estGas = await poolContract.methods
|
tokenAmountIn,
|
||||||
.joinswapExternAmountIn(tokenAmountIn, minPoolAmountOut)
|
minPoolAmountOut
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1153,13 +1101,15 @@ export class Pool {
|
|||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenAmountIn exact number of base tokens to spend
|
* @param {String} tokenAmountIn exact number of base tokens to spend
|
||||||
* @param {String} minPoolAmountOut minimum of pool shares expectex
|
* @param {String} minPoolAmountOut minimum of pool shares expectex
|
||||||
|
* @param {number} tokenInDecimals optional number of decimals of the token
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async joinswapExternAmountIn(
|
async joinswapExternAmountIn(
|
||||||
account: string,
|
account: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
tokenAmountIn: string,
|
tokenAmountIn: string,
|
||||||
minPoolAmountOut: string
|
minPoolAmountOut: string,
|
||||||
|
tokenInDecimals?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
||||||
@ -1172,10 +1122,14 @@ export class Pool {
|
|||||||
throw new Error(`tokenAmountOut is greater than ${maxSwap.toString()}`)
|
throw new Error(`tokenAmountOut is greater than ${maxSwap.toString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountInFormatted = await this.amountToUnits(tokenIn, tokenAmountIn)
|
const amountInFormatted = await this.amountToUnits(
|
||||||
const estGas = await this.estJoinswapExternAmountIn(
|
tokenIn,
|
||||||
|
tokenAmountIn,
|
||||||
|
tokenInDecimals
|
||||||
|
)
|
||||||
|
const estGas = await estimateGas(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
pool.methods.joinswapExternAmountIn,
|
||||||
amountInFormatted,
|
amountInFormatted,
|
||||||
this.web3.utils.toWei(minPoolAmountOut)
|
this.web3.utils.toWei(minPoolAmountOut)
|
||||||
)
|
)
|
||||||
@ -1221,16 +1175,12 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
poolContract.methods.exitswapPoolAmountIn,
|
||||||
estGas = await poolContract.methods
|
poolAmountIn,
|
||||||
.exitswapPoolAmountIn(poolAmountIn, minTokenAmountOut)
|
minTokenAmountOut
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1241,13 +1191,15 @@ export class Pool {
|
|||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} poolAmountIn exact number of pool shares to spend
|
* @param {String} poolAmountIn exact number of pool shares to spend
|
||||||
* @param {String} minTokenAmountOut minimum amount of basetokens expected
|
* @param {String} minTokenAmountOut minimum amount of basetokens expected
|
||||||
|
* @param {number} poolDecimals optional number of decimals of the poool
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async exitswapPoolAmountIn(
|
async exitswapPoolAmountIn(
|
||||||
account: string,
|
account: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
poolAmountIn: string,
|
poolAmountIn: string,
|
||||||
minTokenAmountOut: string
|
minTokenAmountOut: string,
|
||||||
|
poolDecimals?: number
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = setContractDefaults(
|
const pool = setContractDefaults(
|
||||||
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
||||||
@ -1269,11 +1221,12 @@ export class Pool {
|
|||||||
|
|
||||||
const minTokenOutFormatted = await this.amountToUnits(
|
const minTokenOutFormatted = await this.amountToUnits(
|
||||||
await this.getBaseToken(poolAddress),
|
await this.getBaseToken(poolAddress),
|
||||||
minTokenAmountOut
|
minTokenAmountOut,
|
||||||
|
poolDecimals
|
||||||
)
|
)
|
||||||
const estGas = await this.estExitswapPoolAmountIn(
|
const estGas = await estimateGas(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
pool.methods.exitswapPoolAmountIn,
|
||||||
this.web3.utils.toWei(poolAmountIn),
|
this.web3.utils.toWei(poolAmountIn),
|
||||||
minTokenOutFormatted
|
minTokenOutFormatted
|
||||||
)
|
)
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
LoggerInstance as logger,
|
LoggerInstance as logger,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
|
estimateGas,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../../utils/'
|
} from '../../utils/'
|
||||||
import { Datatoken } from '../../tokens'
|
import { Datatoken } from '../../tokens'
|
||||||
@ -24,7 +25,6 @@ export interface DispenserToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Dispenser {
|
export class Dispenser {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public web3: Web3 = null
|
public web3: Web3 = null
|
||||||
public dispenserAddress: string
|
public dispenserAddress: string
|
||||||
public config: Config
|
public config: Config
|
||||||
@ -91,23 +91,15 @@ export class Dispenser {
|
|||||||
maxBalance: string,
|
maxBalance: string,
|
||||||
allowedSwapper: string
|
allowedSwapper: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
this.dispenserContract.methods.create,
|
||||||
estGas = await this.dispenserContract.methods
|
|
||||||
.create(
|
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance),
|
this.web3.utils.toWei(maxBalance),
|
||||||
address,
|
address,
|
||||||
allowedSwapper
|
allowedSwapper
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,11 +118,13 @@ export class Dispenser {
|
|||||||
maxBalance: string,
|
maxBalance: string,
|
||||||
allowedSwapper: string
|
allowedSwapper: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estGasCreate(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
address,
|
||||||
|
this.dispenserContract.methods.create,
|
||||||
|
dtAddress,
|
||||||
|
this.web3.utils.toWei(maxTokens),
|
||||||
|
this.web3.utils.toWei(maxBalance),
|
||||||
address,
|
address,
|
||||||
maxTokens,
|
|
||||||
maxBalance,
|
|
||||||
allowedSwapper
|
allowedSwapper
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,20 +159,13 @@ export class Dispenser {
|
|||||||
maxBalance: string,
|
maxBalance: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
let estGas
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
try {
|
this.dispenserContract.methods.activate,
|
||||||
estGas = await this.dispenserContract.methods
|
|
||||||
.activate(
|
|
||||||
dtAddress,
|
dtAddress,
|
||||||
this.web3.utils.toWei(maxTokens),
|
this.web3.utils.toWei(maxTokens),
|
||||||
this.web3.utils.toWei(maxBalance)
|
this.web3.utils.toWei(maxBalance)
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,7 +183,14 @@ export class Dispenser {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasActivate(dtAddress, maxTokens, maxBalance, address)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.dispenserContract.methods.activate,
|
||||||
|
dtAddress,
|
||||||
|
this.web3.utils.toWei(maxTokens),
|
||||||
|
this.web3.utils.toWei(maxBalance)
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.dispenserContract.methods
|
||||||
.activate(
|
.activate(
|
||||||
dtAddress,
|
dtAddress,
|
||||||
@ -222,16 +216,7 @@ export class Dispenser {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async estGasDeactivate(dtAddress: string, address: string): Promise<any> {
|
public async estGasDeactivate(dtAddress: string, address: string): Promise<any> {
|
||||||
let estGas
|
return estimateGas(address, this.dispenserContract.methods.deactivate, dtAddress)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
try {
|
|
||||||
estGas = await this.dispenserContract.methods
|
|
||||||
.deactivate(dtAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,7 +230,12 @@ export class Dispenser {
|
|||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasDeactivate(dtAddress, address)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.dispenserContract.methods.deactivate,
|
||||||
|
dtAddress
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods.deactivate(dtAddress).send({
|
const trxReceipt = await this.dispenserContract.methods.deactivate(dtAddress).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -270,16 +260,12 @@ export class Dispenser {
|
|||||||
address: string,
|
address: string,
|
||||||
newAllowedSwapper: string
|
newAllowedSwapper: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
let estGas
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
try {
|
this.dispenserContract.methods.setAllowedSwapper,
|
||||||
estGas = await this.dispenserContract.methods
|
dtAddress,
|
||||||
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
newAllowedSwapper
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -295,11 +281,13 @@ export class Dispenser {
|
|||||||
newAllowedSwapper: string
|
newAllowedSwapper: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasSetAllowedSwapper(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
this.dispenserContract.methods.setAllowedSwapper,
|
||||||
|
dtAddress,
|
||||||
newAllowedSwapper
|
newAllowedSwapper
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.dispenserContract.methods
|
||||||
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
.setAllowedSwapper(dtAddress, newAllowedSwapper)
|
||||||
.send({
|
.send({
|
||||||
@ -327,16 +315,13 @@ export class Dispenser {
|
|||||||
amount: string = '1',
|
amount: string = '1',
|
||||||
destination: string
|
destination: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
let estGas
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
try {
|
this.dispenserContract.methods.dispense,
|
||||||
estGas = await this.dispenserContract.methods
|
dtAddress,
|
||||||
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
this.web3.utils.toWei(amount),
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
destination
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +340,14 @@ export class Dispenser {
|
|||||||
amount: string = '1',
|
amount: string = '1',
|
||||||
destination: string
|
destination: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estGasDispense(dtAddress, address, amount, destination)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.dispenserContract.methods.dispense,
|
||||||
|
dtAddress,
|
||||||
|
this.web3.utils.toWei(amount),
|
||||||
|
destination
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.dispenserContract.methods
|
||||||
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
.dispense(dtAddress, this.web3.utils.toWei(amount), destination)
|
||||||
@ -379,16 +371,7 @@ export class Dispenser {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async estGasOwnerWithdraw(dtAddress: string, address: string): Promise<any> {
|
public async estGasOwnerWithdraw(dtAddress: string, address: string): Promise<any> {
|
||||||
let estGas
|
return estimateGas(address, this.dispenserContract.methods.ownerWithdraw, dtAddress)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
try {
|
|
||||||
estGas = await this.dispenserContract.methods
|
|
||||||
.ownerWithdraw(dtAddress)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -401,7 +384,12 @@ export class Dispenser {
|
|||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estGasOwnerWithdraw(dtAddress, address)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.dispenserContract.methods.ownerWithdraw,
|
||||||
|
dtAddress
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.dispenserContract.methods
|
const trxReceipt = await this.dispenserContract.methods
|
||||||
.ownerWithdraw(dtAddress)
|
.ownerWithdraw(dtAddress)
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
amountToUnits,
|
amountToUnits,
|
||||||
unitsToAmount,
|
unitsToAmount,
|
||||||
|
estimateGas,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
@ -55,7 +56,6 @@ export enum FixedRateCreateProgressStep {
|
|||||||
/* eslint-enable no-unused-vars */
|
/* eslint-enable no-unused-vars */
|
||||||
|
|
||||||
export class FixedRateExchange {
|
export class FixedRateExchange {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
/** Ocean related functions */
|
/** Ocean related functions */
|
||||||
public oceanAddress: string = null
|
public oceanAddress: string = null
|
||||||
public fixedRateAddress: string
|
public fixedRateAddress: string
|
||||||
@ -141,22 +141,16 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
account,
|
||||||
estGas = await fixedRate.methods
|
fixedRate.methods.buyDT,
|
||||||
.buyDT(
|
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
dtAmount,
|
dtAmount,
|
||||||
maxBaseTokenAmount,
|
maxBaseTokenAmount,
|
||||||
consumeMarketAddress,
|
consumeMarketAddress,
|
||||||
consumeMarketFee
|
consumeMarketFee
|
||||||
)
|
)
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -190,8 +184,9 @@ export class FixedRateExchange {
|
|||||||
+exchange.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estBuyDT(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.contract.methods.buyDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
maxBtFormatted,
|
maxBtFormatted,
|
||||||
@ -239,22 +234,16 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
account,
|
||||||
estGas = await fixedRate.methods
|
fixedRate.methods.sellDT,
|
||||||
.sellDT(
|
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
dtAmount,
|
dtAmount,
|
||||||
maxBaseTokenAmount,
|
maxBaseTokenAmount,
|
||||||
consumeMarketAddress,
|
consumeMarketAddress,
|
||||||
consumeMarketFee
|
consumeMarketFee
|
||||||
)
|
)
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -287,8 +276,9 @@ export class FixedRateExchange {
|
|||||||
minBaseTokenAmount,
|
minBaseTokenAmount,
|
||||||
+exchange.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
const estGas = await this.estBuyDT(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.contract.methods.sellDT,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
minBtFormatted,
|
minBtFormatted,
|
||||||
@ -342,16 +332,13 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
account,
|
||||||
estGas = await fixedRate.methods
|
fixedRate.methods.setRate,
|
||||||
.setRate(exchangeId, await this.web3.utils.toWei(newRate))
|
exchangeId,
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
await this.web3.utils.toWei(newRate)
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -366,7 +353,12 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
newRate: string
|
newRate: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estSetRate(address, exchangeId, newRate)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.setRate,
|
||||||
|
exchangeId,
|
||||||
|
this.web3.utils.toWei(newRate)
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
.setRate(exchangeId, this.web3.utils.toWei(newRate))
|
||||||
.send({
|
.send({
|
||||||
@ -392,16 +384,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.setRate, exchangeId, newAllowedSwapper)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.setRate(exchangeId, newAllowedSwapper)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -416,7 +400,12 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
newAllowedSwapper: string
|
newAllowedSwapper: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estSetAllowedSwapper(address, exchangeId, newAllowedSwapper)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.setAllowedSwapper,
|
||||||
|
exchangeId,
|
||||||
|
newAllowedSwapper
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
.setAllowedSwapper(exchangeId, newAllowedSwapper)
|
||||||
.send({
|
.send({
|
||||||
@ -440,16 +429,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.toggleExchangeState(exchangeId)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -466,7 +447,11 @@ export class FixedRateExchange {
|
|||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
if (exchange.active === true) return null
|
if (exchange.active === true) return null
|
||||||
|
|
||||||
const estGas = await this.estActivate(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.toggleExchangeState,
|
||||||
|
exchangeId
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -488,16 +473,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.toggleExchangeState, exchangeId)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.toggleExchangeState(exchangeId)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -514,7 +491,11 @@ export class FixedRateExchange {
|
|||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
if (exchange.active === false) return null
|
if (exchange.active === false) return null
|
||||||
|
|
||||||
const estGas = await this.estDeactivate(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.toggleExchangeState,
|
||||||
|
exchangeId
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -739,16 +720,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId, true)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.toggleMintState(exchangeId, true)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -765,7 +738,12 @@ export class FixedRateExchange {
|
|||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
if (exchange.withMint === true) return null
|
if (exchange.withMint === true) return null
|
||||||
|
|
||||||
const estGas = await this.estActivateMint(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.toggleMintState,
|
||||||
|
exchangeId,
|
||||||
|
true
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, true)
|
.toggleMintState(exchangeId, true)
|
||||||
.send({
|
.send({
|
||||||
@ -789,16 +767,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.toggleMintState, exchangeId)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.toggleMintState(exchangeId)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -815,7 +785,12 @@ export class FixedRateExchange {
|
|||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
if (exchange.withMint === false) return null
|
if (exchange.withMint === false) return null
|
||||||
|
|
||||||
const estGas = await this.estDeactivate(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.toggleMintState,
|
||||||
|
exchangeId,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.toggleMintState(exchangeId, false)
|
.toggleMintState(exchangeId, false)
|
||||||
@ -843,8 +818,6 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
const fixedrate: FixedPriceExchange = await this.contract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
@ -853,14 +826,7 @@ export class FixedRateExchange {
|
|||||||
amount,
|
amount,
|
||||||
+fixedrate.btDecimals
|
+fixedrate.btDecimals
|
||||||
)
|
)
|
||||||
try {
|
return estimateGas(account, fixedRate.methods.collectBT, exchangeId, amountWei)
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.collectBT(exchangeId, amountWei)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -878,7 +844,6 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const estGas = await this.estCollectBT(address, exchangeId, amount)
|
|
||||||
const fixedrate: FixedPriceExchange = await this.contract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
@ -887,6 +852,14 @@ export class FixedRateExchange {
|
|||||||
amount,
|
amount,
|
||||||
+fixedrate.btDecimals
|
+fixedrate.btDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.collectBT,
|
||||||
|
exchangeId,
|
||||||
|
amountWei
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({
|
const trxReceipt = await this.contract.methods.collectBT(exchangeId, amountWei).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -910,24 +883,16 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
const fixedrate: FixedPriceExchange = await this.contract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
const amountWei = await this.amountToUnits(
|
const amountWei = await this.amountToUnits(
|
||||||
fixedrate.datatoken,
|
fixedrate.datatoken,
|
||||||
amount,
|
amount,
|
||||||
+fixedrate.dtDecimals
|
+fixedrate.dtDecimals
|
||||||
)
|
)
|
||||||
try {
|
return estimateGas(account, fixedRate.methods.collectDT, exchangeId, amountWei)
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.collectDT(exchangeId, amountWei)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -945,7 +910,6 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const estGas = await this.estCollectDT(address, exchangeId, amount)
|
|
||||||
const fixedrate: FixedPriceExchange = await this.contract.methods
|
const fixedrate: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
@ -954,6 +918,14 @@ export class FixedRateExchange {
|
|||||||
amount,
|
amount,
|
||||||
+fixedrate.dtDecimals
|
+fixedrate.dtDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.collectDT,
|
||||||
|
exchangeId,
|
||||||
|
amountWei
|
||||||
|
)
|
||||||
|
|
||||||
const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({
|
const trxReceipt = await this.contract.methods.collectDT(exchangeId, amountWei).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -975,16 +947,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.collectMarketFee(exchangeId)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1000,7 +964,11 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const estGas = await this.estCollectMarketFee(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.collectMarketFee,
|
||||||
|
exchangeId
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({
|
const trxReceipt = await this.contract.methods.collectMarketFee(exchangeId).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -1022,16 +990,8 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(account, fixedRate.methods.collectMarketFee, exchangeId)
|
||||||
try {
|
|
||||||
estGas = await fixedRate.methods
|
|
||||||
.collectMarketFee(exchangeId)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1047,7 +1007,11 @@ export class FixedRateExchange {
|
|||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
if (!exchange) return null
|
if (!exchange) return null
|
||||||
|
|
||||||
const estGas = await this.estCollectOceanFee(address, exchangeId)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
this.contract.methods.collectOceanFee,
|
||||||
|
exchangeId
|
||||||
|
)
|
||||||
const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({
|
const trxReceipt = await this.contract.methods.collectOceanFee(exchangeId).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -1056,20 +1020,6 @@ export class FixedRateExchange {
|
|||||||
return trxReceipt
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get OPF Collector of fixed rate contract
|
|
||||||
* @return {String}
|
|
||||||
*/
|
|
||||||
async getOPCCollector(): Promise<string> {
|
|
||||||
let result = null
|
|
||||||
try {
|
|
||||||
result = await this.contract.methods.opcCollector().call()
|
|
||||||
} catch (e) {
|
|
||||||
LoggerInstance.error(`ERROR: Failed to get OPC Collector address: ${e.message}`)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Router address set in fixed rate contract
|
* Get Router address set in fixed rate contract
|
||||||
* @return {String}
|
* @return {String}
|
||||||
@ -1114,16 +1064,13 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
account,
|
||||||
estGas = await fixedRate.methods
|
fixedRate.methods.updateMarketFee,
|
||||||
.updateMarketFee(exchangeId, newMarketFee)
|
exchangeId,
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
newMarketFee
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1138,8 +1085,9 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
newMarketFee: string
|
newMarketFee: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estSetRate(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.contract.methods.updateMarketFee,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
this.web3.utils.toWei(newMarketFee)
|
this.web3.utils.toWei(newMarketFee)
|
||||||
)
|
)
|
||||||
@ -1168,16 +1116,13 @@ export class FixedRateExchange {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
account,
|
||||||
estGas = await fixedRate.methods
|
fixedRate.methods.updateMarketFeeCollector,
|
||||||
.updateMarketFeeCollector(exchangeId, newMarketFeeCollector)
|
exchangeId,
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
newMarketFeeCollector
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1192,8 +1137,9 @@ export class FixedRateExchange {
|
|||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
newMarketFeeCollector: string
|
newMarketFeeCollector: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const estGas = await this.estUpdateMarketFeeCollector(
|
const estGas = await estimateGas(
|
||||||
address,
|
address,
|
||||||
|
this.contract.methods.updateMarketFeeCollector,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
newMarketFeeCollector
|
newMarketFeeCollector
|
||||||
)
|
)
|
||||||
|
@ -2,14 +2,19 @@ import Web3 from 'web3'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { LoggerInstance, getFairGasPrice, ConfigHelper, unitsToAmount } from '../../utils'
|
import {
|
||||||
|
LoggerInstance,
|
||||||
|
getFairGasPrice,
|
||||||
|
ConfigHelper,
|
||||||
|
estimateGas,
|
||||||
|
unitsToAmount
|
||||||
|
} from '../../utils'
|
||||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
import { Config } from '../../models'
|
import { Config } from '../../models'
|
||||||
|
|
||||||
export class SideStaking {
|
export class SideStaking {
|
||||||
public ssAbi: AbiItem | AbiItem[]
|
public ssAbi: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public config: Config
|
public config: Config
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -274,16 +279,7 @@ export class SideStaking {
|
|||||||
const sideStaking =
|
const sideStaking =
|
||||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await sideStaking.methods
|
|
||||||
.getVesting(datatokenAddress)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send vested tokens available to the publisher address, can be called by anyone
|
/** Send vested tokens available to the publisher address, can be called by anyone
|
||||||
@ -301,12 +297,12 @@ export class SideStaking {
|
|||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
const estGas = await this.estGetVesting(
|
const estGas = await estimateGas(
|
||||||
account,
|
account,
|
||||||
ssAddress,
|
sideStaking.methods.getVesting,
|
||||||
datatokenAddress,
|
datatokenAddress
|
||||||
sideStaking
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getVesting(datatokenAddress).send({
|
result = await sideStaking.methods.getVesting(datatokenAddress).send({
|
||||||
from: account,
|
from: account,
|
||||||
@ -338,16 +334,13 @@ export class SideStaking {
|
|||||||
const sideStaking =
|
const sideStaking =
|
||||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
account,
|
||||||
try {
|
sideStaking.methods.setPoolSwapFee,
|
||||||
estGas = await sideStaking.methods
|
datatokenAddress,
|
||||||
.setPoolSwapFee(datatokenAddress, poolAddress, swapFee)
|
poolAddress,
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
swapFee
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send vested tokens available to the publisher address, can be called by anyone
|
/** Send vested tokens available to the publisher address, can be called by anyone
|
||||||
@ -367,14 +360,14 @@ export class SideStaking {
|
|||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
const estGas = await this.estSetPoolSwapFee(
|
const estGas = await estimateGas(
|
||||||
account,
|
account,
|
||||||
ssAddress,
|
sideStaking.methods.setPoolSwapFee,
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
swapFee,
|
swapFee
|
||||||
sideStaking
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods
|
result = await sideStaking.methods
|
||||||
.setPoolSwapFee(datatokenAddress, poolAddress, swapFee)
|
.setPoolSwapFee(datatokenAddress, poolAddress, swapFee)
|
||||||
|
@ -7,7 +7,8 @@ import {
|
|||||||
ComputeAlgorithm,
|
ComputeAlgorithm,
|
||||||
ComputeAsset,
|
ComputeAsset,
|
||||||
ComputeEnvironment,
|
ComputeEnvironment,
|
||||||
ProviderInitialize
|
ProviderInitialize,
|
||||||
|
ProviderComputeInitializeResults
|
||||||
} from '../@types/'
|
} from '../@types/'
|
||||||
import { noZeroX } from '../utils/ConversionTypeHelper'
|
import { noZeroX } from '../utils/ConversionTypeHelper'
|
||||||
import fetch from 'cross-fetch'
|
import fetch from 'cross-fetch'
|
||||||
@ -327,6 +328,60 @@ export class Provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Initialize a compute request.
|
||||||
|
* @param {ComputeAsset} assets
|
||||||
|
* @param {ComputeAlgorithmber} algorithm
|
||||||
|
* @param {string} computeEnv
|
||||||
|
* @param {number} validUntil
|
||||||
|
* @param {string} providerUri Identifier of the asset to be registered in ocean
|
||||||
|
* @param {string} accountId
|
||||||
|
* @param {AbortSignal} signal abort signal
|
||||||
|
* @return {Promise<ProviderComputeInitialize>} ProviderComputeInitialize data
|
||||||
|
*/
|
||||||
|
public async initializeCompute(
|
||||||
|
assets: ComputeAsset[],
|
||||||
|
algorithm: ComputeAlgorithm,
|
||||||
|
computeEnv: string,
|
||||||
|
validUntil: number,
|
||||||
|
providerUri: string,
|
||||||
|
accountId: string,
|
||||||
|
signal?: AbortSignal
|
||||||
|
): Promise<ProviderComputeInitializeResults> {
|
||||||
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
|
providerUri,
|
||||||
|
providerEndpoints
|
||||||
|
)
|
||||||
|
const providerData = {
|
||||||
|
datasets: assets,
|
||||||
|
algorithm: algorithm,
|
||||||
|
compute: {
|
||||||
|
env: computeEnv,
|
||||||
|
validUntil: validUntil
|
||||||
|
},
|
||||||
|
consumerAddress: accountId
|
||||||
|
}
|
||||||
|
const initializeUrl = this.getEndpointURL(serviceEndpoints, 'initializeCompute')
|
||||||
|
? this.getEndpointURL(serviceEndpoints, 'initializeCompute').urlPath
|
||||||
|
: null
|
||||||
|
if (!initializeUrl) return null
|
||||||
|
try {
|
||||||
|
const response = await fetch(initializeUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(providerData),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
signal: signal
|
||||||
|
})
|
||||||
|
const results = await response.json()
|
||||||
|
return results
|
||||||
|
} catch (e) {
|
||||||
|
LoggerInstance.error(e)
|
||||||
|
throw new Error('ComputeJob cannot be initialized')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets fully signed URL for download
|
/** Gets fully signed URL for download
|
||||||
* @param {string} did
|
* @param {string} did
|
||||||
* @param {string} accountId
|
* @param {string} accountId
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
getFreOrderParams,
|
getFreOrderParams,
|
||||||
|
estimateGas,
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
@ -45,7 +46,6 @@ export interface DispenserParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Datatoken {
|
export class Datatoken {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public factoryAddress: string
|
public factoryAddress: string
|
||||||
public factoryABI: AbiItem | AbiItem[]
|
public factoryABI: AbiItem | AbiItem[]
|
||||||
public datatokensAbi: AbiItem | AbiItem[]
|
public datatokensAbi: AbiItem | AbiItem[]
|
||||||
@ -97,17 +97,12 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
// Estimate gas cost for mint method
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
let estGas
|
dtContract.methods.approve,
|
||||||
try {
|
spender,
|
||||||
estGas = await dtContract.methods
|
this.web3.utils.toWei(amount)
|
||||||
.approve(spender, this.web3.utils.toWei(amount))
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,12 +124,11 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estGasApprove(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
spender,
|
|
||||||
amount,
|
|
||||||
address,
|
address,
|
||||||
dtContract
|
dtContract.methods.approve,
|
||||||
|
spender,
|
||||||
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call mint contract method
|
// Call mint contract method
|
||||||
@ -171,17 +165,12 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
dtContract.methods.mint,
|
||||||
estGas = await dtContract.methods
|
toAddress || address,
|
||||||
.mint(toAddress || address, this.web3.utils.toWei(amount))
|
this.web3.utils.toWei(amount)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,15 +195,12 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
|
|
||||||
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
if (!fixedRateParams.allowedConsumer) fixedRateParams.allowedConsumer = ZERO_ADDRESS
|
||||||
const withMint = fixedRateParams.withMint ? 1 : 0
|
const withMint = fixedRateParams.withMint ? 1 : 0
|
||||||
|
|
||||||
let estGas
|
return estimateGas(
|
||||||
try {
|
address,
|
||||||
estGas = await dtContract.methods
|
dtContract.methods.createFixedRate,
|
||||||
.createFixedRate(
|
|
||||||
fixedRateParams.fixedRateAddress,
|
fixedRateParams.fixedRateAddress,
|
||||||
[
|
[
|
||||||
fixedRateParams.baseTokenAddress,
|
fixedRateParams.baseTokenAddress,
|
||||||
@ -230,12 +216,6 @@ export class Datatoken {
|
|||||||
withMint
|
withMint
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -264,11 +244,23 @@ export class Datatoken {
|
|||||||
|
|
||||||
// should check ERC20Deployer role using erc721 level ..
|
// should check ERC20Deployer role using erc721 level ..
|
||||||
|
|
||||||
const estGas = await this.estGasCreateFixedRate(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
fixedRateParams,
|
dtContract.methods.createFixedRate,
|
||||||
dtContract
|
fixedRateParams.fixedRateAddress,
|
||||||
|
[
|
||||||
|
fixedRateParams.baseTokenAddress,
|
||||||
|
fixedRateParams.owner,
|
||||||
|
fixedRateParams.marketFeeCollector,
|
||||||
|
fixedRateParams.allowedConsumer
|
||||||
|
],
|
||||||
|
[
|
||||||
|
fixedRateParams.baseTokenDecimals,
|
||||||
|
fixedRateParams.datatokenDecimals,
|
||||||
|
fixedRateParams.fixedRate,
|
||||||
|
fixedRateParams.marketFee,
|
||||||
|
withMint
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
@ -324,23 +316,15 @@ export class Datatoken {
|
|||||||
|
|
||||||
if (!dispenserParams.withMint) dispenserParams.withMint = false
|
if (!dispenserParams.withMint) dispenserParams.withMint = false
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
dtContract.methods.createDispenser,
|
||||||
estGas = await dtContract.methods
|
|
||||||
.createDispenser(
|
|
||||||
dispenserAddress,
|
dispenserAddress,
|
||||||
dispenserParams.maxTokens,
|
dispenserParams.maxTokens,
|
||||||
dispenserParams.maxBalance,
|
dispenserParams.maxBalance,
|
||||||
dispenserParams.withMint,
|
dispenserParams.withMint,
|
||||||
dispenserParams.allowedSwapper
|
dispenserParams.allowedSwapper
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -372,12 +356,14 @@ export class Datatoken {
|
|||||||
|
|
||||||
// should check ERC20Deployer role using erc721 level ..
|
// should check ERC20Deployer role using erc721 level ..
|
||||||
|
|
||||||
const estGas = await this.estGasCreateDispenser(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
dtContract.methods.createDispenser,
|
||||||
dispenserAddress,
|
dispenserAddress,
|
||||||
dispenserParams,
|
dispenserParams.maxTokens,
|
||||||
dtContract
|
dispenserParams.maxBalance,
|
||||||
|
dispenserParams.withMint,
|
||||||
|
dispenserParams.allowedSwapper
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
@ -422,12 +408,11 @@ export class Datatoken {
|
|||||||
|
|
||||||
const capAvailble = await this.getCap(dtAddress)
|
const capAvailble = await this.getCap(dtAddress)
|
||||||
if (new Decimal(capAvailble).gte(amount)) {
|
if (new Decimal(capAvailble).gte(amount)) {
|
||||||
const estGas = await this.estGasMint(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
amount,
|
dtContract.methods.mint,
|
||||||
toAddress,
|
toAddress || address,
|
||||||
dtContract
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call mint contract method
|
// Call mint contract method
|
||||||
@ -465,17 +450,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
// Estimate gas cost for addMinter method
|
return estimateGas(address, dtContract.methods.addMinter, minter)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.addMinter(minter)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -500,7 +475,7 @@ export class Datatoken {
|
|||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
// Estimate gas cost for addMinter method
|
// Estimate gas cost for addMinter method
|
||||||
const estGas = await this.estGasAddMinter(dtAddress, address, minter, dtContract)
|
const estGas = await estimateGas(address, dtContract.methods.addMinter, minter)
|
||||||
|
|
||||||
// Call addMinter function of the contract
|
// Call addMinter function of the contract
|
||||||
const trxReceipt = await dtContract.methods.addMinter(minter).send({
|
const trxReceipt = await dtContract.methods.addMinter(minter).send({
|
||||||
@ -535,18 +510,7 @@ export class Datatoken {
|
|||||||
|
|
||||||
// should check ERC20Deployer role using erc721 level ..
|
// should check ERC20Deployer role using erc721 level ..
|
||||||
|
|
||||||
// Estimate gas for removeMinter method
|
return estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.removeMinter(minter)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -572,7 +536,7 @@ export class Datatoken {
|
|||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveMinter(dtAddress, address, minter, dtContract)
|
const estGas = await estimateGas(address, dtContract.methods.removeMinter, minter)
|
||||||
|
|
||||||
// Call dtContract function of the contract
|
// Call dtContract function of the contract
|
||||||
const trxReceipt = await dtContract.methods.removeMinter(minter).send({
|
const trxReceipt = await dtContract.methods.removeMinter(minter).send({
|
||||||
@ -605,18 +569,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
// Estimate gas for addFeeManager method
|
return estimateGas(address, dtContract.methods.addPaymentManager, paymentManager)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.addPaymentManager(paymentManager)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -641,11 +594,10 @@ export class Datatoken {
|
|||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddPaymentManager(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
paymentManager,
|
dtContract.methods.addPaymentManager,
|
||||||
dtContract
|
paymentManager
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call addPaymentManager function of the contract
|
// Call addPaymentManager function of the contract
|
||||||
@ -679,16 +631,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, dtContract.methods.removePaymentManager, paymentManager)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.removePaymentManager(paymentManager)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -713,11 +656,10 @@ export class Datatoken {
|
|||||||
throw new Error(`Caller is not ERC20Deployer`)
|
throw new Error(`Caller is not ERC20Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemovePaymentManager(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
paymentManager,
|
dtContract.methods.removePaymentManager,
|
||||||
dtContract
|
paymentManager
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call removeFeeManager function of the contract
|
// Call removeFeeManager function of the contract
|
||||||
@ -753,16 +695,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, dtContract.methods.setPaymentCollector, paymentCollector)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.setPaymentCollector(paymentCollector)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -794,11 +727,10 @@ export class Datatoken {
|
|||||||
throw new Error(`Caller is not Fee Manager, owner or erc20 Deployer`)
|
throw new Error(`Caller is not Fee Manager, owner or erc20 Deployer`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasSetPaymentCollector(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
paymentCollector,
|
dtContract.methods.setPaymentCollector,
|
||||||
dtContract
|
paymentCollector
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call setFeeCollector method of the contract
|
// Call setFeeCollector method of the contract
|
||||||
@ -867,16 +799,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, dtContract.methods.transfer, toAddress, amount)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.transfer(toAddress, amount)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -898,12 +821,11 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasTransfer(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
toAddress,
|
|
||||||
amount,
|
|
||||||
address,
|
address,
|
||||||
dtContract
|
dtContract.methods.transfer,
|
||||||
|
toAddress,
|
||||||
|
amount
|
||||||
)
|
)
|
||||||
// Call transfer function of the contract
|
// Call transfer function of the contract
|
||||||
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
||||||
@ -944,17 +866,14 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
// Estimate gas for startOrder method
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
let estGas
|
dtContract.methods.startOrder,
|
||||||
try {
|
consumer,
|
||||||
estGas = await dtContract.methods
|
serviceIndex,
|
||||||
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
providerFees,
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
consumeMarketFee
|
||||||
} catch (e) {
|
)
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Start Order: called by payer or consumer prior ordering a service consume on a marketplace.
|
/** Start Order: called by payer or consumer prior ordering a service consume on a marketplace.
|
||||||
@ -986,14 +905,13 @@ export class Datatoken {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasStartOrder(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
dtContract.methods.startOrder,
|
||||||
consumer,
|
consumer,
|
||||||
serviceIndex,
|
serviceIndex,
|
||||||
providerFees,
|
providerFees,
|
||||||
consumeMarketFee,
|
consumeMarketFee
|
||||||
dtContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -1032,17 +950,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
// Estimate gas for reuseOrder method
|
return estimateGas(address, dtContract.methods.reuseOrder, orderTxId, providerFees)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.reuseOrder(orderTxId, providerFees)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reuse Order: called by payer or consumer having a valid order, but with expired provider access.
|
/** Reuse Order: called by payer or consumer having a valid order, but with expired provider access.
|
||||||
@ -1065,12 +973,11 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasReuseOrder(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
dtContract.methods.reuseOrder,
|
||||||
orderTxId,
|
orderTxId,
|
||||||
providerFees,
|
providerFees
|
||||||
dtContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -1106,17 +1013,12 @@ export class Datatoken {
|
|||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
||||||
|
|
||||||
// Estimate gas for startOrder method
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
let estGas
|
dtContract.methods.buyFromFreAndOrder,
|
||||||
try {
|
orderParams,
|
||||||
estGas = await dtContract.methods
|
freParams
|
||||||
.buyFromFreAndOrder(orderParams, freParams)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Buys 1 DT from the FRE and then startsOrder, while burning that DT
|
/** Buys 1 DT from the FRE and then startsOrder, while burning that DT
|
||||||
@ -1136,12 +1038,11 @@ export class Datatoken {
|
|||||||
try {
|
try {
|
||||||
const freContractParams = getFreOrderParams(freParams)
|
const freContractParams = getFreOrderParams(freParams)
|
||||||
|
|
||||||
const estGas = await this.estGasBuyFromFreAndOrder(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
dtContract.methods.buyFromFreAndOrder,
|
||||||
orderParams,
|
orderParams,
|
||||||
freContractParams,
|
freContractParams
|
||||||
dtContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -1177,17 +1078,12 @@ export class Datatoken {
|
|||||||
contractInstance ||
|
contractInstance ||
|
||||||
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
||||||
|
|
||||||
// Estimate gas for startOrder method
|
return estimateGas(
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
address,
|
||||||
let estGas
|
dtContract.methods.buyFromDispenserAndOrder,
|
||||||
try {
|
orderParams,
|
||||||
estGas = await dtContract.methods
|
dispenserContract
|
||||||
.buyFromDispenserAndOrder(orderParams, dispenserContract)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets DT from dispenser and then startsOrder, while burning that DT
|
/** Gets DT from dispenser and then startsOrder, while burning that DT
|
||||||
@ -1205,12 +1101,11 @@ export class Datatoken {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
|
||||||
try {
|
try {
|
||||||
const estGas = await this.estGasBuyFromDispenserAndOrder(
|
const estGas = await estimateGas(
|
||||||
dtAddress,
|
|
||||||
address,
|
address,
|
||||||
|
dtContract.methods.buyFromDispenserAndOrder,
|
||||||
orderParams,
|
orderParams,
|
||||||
dispenserContract,
|
dispenserContract
|
||||||
dtContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -1247,16 +1142,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, dtContract.methods.setData, value)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.setData(value)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** setData
|
/** setData
|
||||||
@ -1281,7 +1167,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estGasSetData(dtAddress, address, value, dtContract)
|
const estGas = await estimateGas(address, dtContract.methods.setData, value)
|
||||||
|
|
||||||
// Call setData function of the contract
|
// Call setData function of the contract
|
||||||
const trxReceipt = await dtContract.methods.setData(value).send({
|
const trxReceipt = await dtContract.methods.setData(value).send({
|
||||||
@ -1311,17 +1197,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, dtContract.methods.cleanPermissions)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await dtContract.methods
|
|
||||||
.cleanPermissions()
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1343,7 +1219,7 @@ export class Datatoken {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estGasCleanPermissions(dtAddress, address, dtContract)
|
const estGas = await estimateGas(address, dtContract.methods.cleanPermissions)
|
||||||
|
|
||||||
// Call cleanPermissions function of the contract
|
// Call cleanPermissions function of the contract
|
||||||
const trxReceipt = await dtContract.methods.cleanPermissions().send({
|
const trxReceipt = await dtContract.methods.cleanPermissions().send({
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
generateDtName,
|
generateDtName,
|
||||||
setContractDefaults,
|
setContractDefaults,
|
||||||
|
estimateGas,
|
||||||
ConfigHelper
|
ConfigHelper
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
@ -25,7 +26,6 @@ interface Roles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Nft {
|
export class Nft {
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
|
||||||
public factory721Address: string
|
public factory721Address: string
|
||||||
public factory721Abi: AbiItem | AbiItem[]
|
public factory721Abi: AbiItem | AbiItem[]
|
||||||
public nftAbi: AbiItem | AbiItem[]
|
public nftAbi: AbiItem | AbiItem[]
|
||||||
@ -80,22 +80,15 @@ export class Nft {
|
|||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
nftContract.methods.createERC20,
|
||||||
estGas = await nftContract.methods
|
|
||||||
.createERC20(
|
|
||||||
templateIndex,
|
templateIndex,
|
||||||
[name, symbol],
|
[name, symbol],
|
||||||
[minter, paymentCollector, mpFeeAddress, feeToken],
|
[minter, paymentCollector, mpFeeAddress, feeToken],
|
||||||
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
|
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
|
||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,19 +135,14 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estGasCreateErc20(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
minter,
|
nftContract.methods.createERC20,
|
||||||
paymentCollector,
|
|
||||||
mpFeeAddress,
|
|
||||||
feeToken,
|
|
||||||
feeAmount,
|
|
||||||
cap,
|
|
||||||
name,
|
|
||||||
symbol,
|
|
||||||
templateIndex,
|
templateIndex,
|
||||||
nftContract
|
[name, symbol],
|
||||||
|
[minter, paymentCollector, mpFeeAddress, feeToken],
|
||||||
|
[this.web3.utils.toWei(cap), this.web3.utils.toWei(feeAmount)],
|
||||||
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call createERC20 token function of the contract
|
// Call createERC20 token function of the contract
|
||||||
@ -202,16 +190,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.addManager, manager)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.addManager(manager)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,7 +210,7 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not NFT Owner`)
|
throw new Error(`Caller is not NFT Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddManager(nftAddress, address, manager, nftContract)
|
const estGas = await estimateGas(address, nftContract.methods.addManager, manager)
|
||||||
|
|
||||||
// Invoke addManager function of the contract
|
// Invoke addManager function of the contract
|
||||||
const trxReceipt = await nftContract.methods.addManager(manager).send({
|
const trxReceipt = await nftContract.methods.addManager(manager).send({
|
||||||
@ -263,16 +242,7 @@ export class Nft {
|
|||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.removeManager, manager)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.removeManager(manager)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,12 +262,7 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not NFT Owner`)
|
throw new Error(`Caller is not NFT Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveManager(
|
const estGas = await estimateGas(address, nftContract.methods.removeManager, manager)
|
||||||
nftAddress,
|
|
||||||
address,
|
|
||||||
manager,
|
|
||||||
nftContract
|
|
||||||
)
|
|
||||||
|
|
||||||
// Invoke removeManager function of the contract
|
// Invoke removeManager function of the contract
|
||||||
const trxReceipt = await nftContract.methods.removeManager(manager).send({
|
const trxReceipt = await nftContract.methods.removeManager(manager).send({
|
||||||
@ -329,17 +294,7 @@ export class Nft {
|
|||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.addToCreateERC20List, erc20Deployer)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.addToCreateERC20List(erc20Deployer)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,11 +319,10 @@ export class Nft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Estimate gas for addToCreateERC20List method
|
// Estimate gas for addToCreateERC20List method
|
||||||
const estGas = await this.estGasAddErc20Deployer(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
erc20Deployer,
|
nftContract.methods.addToCreateERC20List,
|
||||||
nftContract
|
erc20Deployer
|
||||||
)
|
)
|
||||||
|
|
||||||
// Invoke addToCreateERC20List function of the contract
|
// Invoke addToCreateERC20List function of the contract
|
||||||
@ -404,17 +358,11 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
nftContract.methods.removeFromCreateERC20List,
|
||||||
estGas = await nftContract.methods
|
erc20Deployer
|
||||||
.removeFromCreateErc20List(erc20Deployer)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,11 +389,10 @@ export class Nft {
|
|||||||
) {
|
) {
|
||||||
throw new Error(`Caller is not Manager nor ERC20Deployer`)
|
throw new Error(`Caller is not Manager nor ERC20Deployer`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasRemoveErc20Deployer(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
erc20Deployer,
|
nftContract.methods.removeFromCreateERC20List,
|
||||||
nftContract
|
erc20Deployer
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call removeFromCreateERC20List function of the contract
|
// Call removeFromCreateERC20List function of the contract
|
||||||
@ -481,16 +428,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.addToMetadataList, metadataUpdater)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.addToMetadataList(metadataUpdater)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -514,11 +452,10 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not Manager`)
|
throw new Error(`Caller is not Manager`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddMetadataUpdater(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
metadataUpdater,
|
nftContract.methods.addToMetadataList,
|
||||||
nftContract
|
metadataUpdater
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call addToMetadataList function of the contract
|
// Call addToMetadataList function of the contract
|
||||||
@ -552,17 +489,11 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
address,
|
||||||
try {
|
nftContract.methods.removeFromMetadataList,
|
||||||
estGas = await nftContract.methods
|
metadataUpdater
|
||||||
.removeFromMetadataList(metadataUpdater)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -630,16 +561,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.addTo725StoreList, storeUpdater)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.addTo725StoreList(storeUpdater)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -663,11 +585,10 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not Manager`)
|
throw new Error(`Caller is not Manager`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasAddStoreUpdater(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
storeUpdater,
|
nftContract.methods.addTo725StoreList,
|
||||||
nftContract
|
storeUpdater
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call addTo725StoreList function of the contract
|
// Call addTo725StoreList function of the contract
|
||||||
@ -701,16 +622,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.removeFrom725StoreList, storeUpdater)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.removeFrom725StoreList(storeUpdater)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -738,11 +650,10 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not Manager nor storeUpdater`)
|
throw new Error(`Caller is not Manager nor storeUpdater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasRemoveStoreUpdater(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
storeUpdater,
|
nftContract.methods.removeFrom725StoreList,
|
||||||
nftContract
|
storeUpdater
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call removeFrom725StoreList function of the contract
|
// Call removeFrom725StoreList function of the contract
|
||||||
@ -776,16 +687,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.cleanPermissions)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.cleanPermissions()
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -811,7 +713,7 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not NFT Owner`)
|
throw new Error(`Caller is not NFT Owner`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasCleanPermissions(nftAddress, address, nftContract)
|
const estGas = await estimateGas(address, nftContract.methods.cleanPermissions)
|
||||||
|
|
||||||
// Call cleanPermissions function of the contract
|
// Call cleanPermissions function of the contract
|
||||||
const trxReceipt = await nftContract.methods.cleanPermissions().send({
|
const trxReceipt = await nftContract.methods.cleanPermissions().send({
|
||||||
@ -846,19 +748,13 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
nftOwner,
|
||||||
try {
|
nftContract.methods.transferFrom,
|
||||||
estGas = await nftContract.methods
|
nftOwner,
|
||||||
.transferFrom(nftOwner, nftReceiver, tokenId)
|
nftReceiver,
|
||||||
.estimateGas({ from: nftOwner }, (err, estGas) =>
|
tokenId
|
||||||
err ? gasLimitDefault : estGas
|
|
||||||
)
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,12 +783,12 @@ export class Nft {
|
|||||||
|
|
||||||
const tokenIdentifier = tokenId || 1
|
const tokenIdentifier = tokenId || 1
|
||||||
|
|
||||||
const estGas = await this.estGasTransferNft(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
nftOwner,
|
||||||
|
nftContract.methods.transferFrom,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
nftReceiver,
|
nftReceiver,
|
||||||
tokenIdentifier,
|
tokenIdentifier
|
||||||
nftContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
@ -930,19 +826,13 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
nftOwner,
|
||||||
try {
|
nftContract.methods.safeTransferFrom,
|
||||||
estGas = await nftContract.methods
|
nftOwner,
|
||||||
.safeTransferFrom(nftOwner, nftReceiver, tokenId)
|
nftReceiver,
|
||||||
.estimateGas({ from: nftOwner }, (err, estGas) =>
|
tokenId
|
||||||
err ? gasLimitDefault : estGas
|
|
||||||
)
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -971,12 +861,12 @@ export class Nft {
|
|||||||
|
|
||||||
const tokenIdentifier = tokenId || 1
|
const tokenIdentifier = tokenId || 1
|
||||||
|
|
||||||
const estGas = await this.estGasSafeTransferNft(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
nftOwner,
|
||||||
|
nftContract.methods.safeTransferFrom,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
nftReceiver,
|
nftReceiver,
|
||||||
tokenIdentifier,
|
tokenIdentifier
|
||||||
nftContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
@ -1021,11 +911,9 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
if (!metadataProofs) metadataProofs = []
|
if (!metadataProofs) metadataProofs = []
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
metadataUpdater,
|
||||||
try {
|
nftContract.methods.setMetaData,
|
||||||
estGas = await nftContract.methods
|
|
||||||
.setMetaData(
|
|
||||||
metadataState,
|
metadataState,
|
||||||
metadataDecryptorUrl,
|
metadataDecryptorUrl,
|
||||||
metadataDecryptorAddress,
|
metadataDecryptorAddress,
|
||||||
@ -1034,15 +922,6 @@ export class Nft {
|
|||||||
metadataHash,
|
metadataHash,
|
||||||
metadataProofs
|
metadataProofs
|
||||||
)
|
)
|
||||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
|
||||||
err ? gasLimitDefault : estGas
|
|
||||||
)
|
|
||||||
} catch (e) {
|
|
||||||
LoggerInstance.error('estGasSetMetadata error: ', e.message)
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1071,17 +950,16 @@ export class Nft {
|
|||||||
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, address)).updateMetadata) {
|
||||||
throw new Error(`Caller is not Metadata updater`)
|
throw new Error(`Caller is not Metadata updater`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasSetMetadata(
|
const estGas = await estimateGas(
|
||||||
nftAddress,
|
|
||||||
address,
|
address,
|
||||||
|
nftContract.methods.setMetaData,
|
||||||
metadataState,
|
metadataState,
|
||||||
metadataDecryptorUrl,
|
metadataDecryptorUrl,
|
||||||
metadataDecryptorAddress,
|
metadataDecryptorAddress,
|
||||||
flags,
|
flags,
|
||||||
data,
|
data,
|
||||||
metadataHash,
|
metadataHash,
|
||||||
metadataProofs,
|
metadataProofs
|
||||||
nftContract
|
|
||||||
)
|
)
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
.setMetaData(
|
.setMetaData(
|
||||||
@ -1122,23 +1000,15 @@ export class Nft {
|
|||||||
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
new this.web3.eth.Contract(this.nftAbi, nftAddress),
|
||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
|
||||||
let estGas
|
|
||||||
const sanitizedMetadataAndTokenURI = {
|
const sanitizedMetadataAndTokenURI = {
|
||||||
...metadataAndTokenURI,
|
...metadataAndTokenURI,
|
||||||
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
||||||
}
|
}
|
||||||
try {
|
return estimateGas(
|
||||||
estGas = await nftContract.methods
|
metadataUpdater,
|
||||||
.setMetaDataAndTokenURI(sanitizedMetadataAndTokenURI)
|
nftContract.methods.setMetaDataAndTokenURI,
|
||||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
sanitizedMetadataAndTokenURI
|
||||||
err ? gasLimitDefault : estGas
|
|
||||||
)
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1160,16 +1030,15 @@ export class Nft {
|
|||||||
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
if (!(await this.getNftPermissions(nftAddress, metadataUpdater)).updateMetadata) {
|
||||||
throw new Error(`Caller is not Metadata updater`)
|
throw new Error(`Caller is not Metadata updater`)
|
||||||
}
|
}
|
||||||
const estGas = await this.estGasSetMetadataAndTokenURI(
|
|
||||||
nftAddress,
|
|
||||||
metadataUpdater,
|
|
||||||
metadataAndTokenURI,
|
|
||||||
nftContract
|
|
||||||
)
|
|
||||||
const sanitizedMetadataAndTokenURI = {
|
const sanitizedMetadataAndTokenURI = {
|
||||||
...metadataAndTokenURI,
|
...metadataAndTokenURI,
|
||||||
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
metadataProofs: metadataAndTokenURI.metadataProofs || []
|
||||||
}
|
}
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
metadataUpdater,
|
||||||
|
nftContract.methods.setMetaDataAndTokenURI,
|
||||||
|
sanitizedMetadataAndTokenURI
|
||||||
|
)
|
||||||
const trxReceipt = await nftContract.methods
|
const trxReceipt = await nftContract.methods
|
||||||
.setMetaDataAndTokenURI(sanitizedMetadataAndTokenURI)
|
.setMetaDataAndTokenURI(sanitizedMetadataAndTokenURI)
|
||||||
.send({
|
.send({
|
||||||
@ -1202,19 +1071,11 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(
|
||||||
let estGas
|
metadataUpdater,
|
||||||
try {
|
nftContract.methods.setMetaDataState,
|
||||||
estGas = await nftContract.methods
|
metadataState
|
||||||
.setMetaDataState(metadataState)
|
|
||||||
.estimateGas({ from: metadataUpdater }, (err, estGas) =>
|
|
||||||
err ? gasLimitDefault : estGas
|
|
||||||
)
|
)
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1238,7 +1099,11 @@ export class Nft {
|
|||||||
throw new Error(`Caller is not Metadata updater`)
|
throw new Error(`Caller is not Metadata updater`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const estGas = await this.estGasSetMetadataState(nftAddress, address, metadataState)
|
const estGas = await estimateGas(
|
||||||
|
address,
|
||||||
|
nftContract.methods.setMetaDataState,
|
||||||
|
metadataState
|
||||||
|
)
|
||||||
|
|
||||||
// Call transferFrom function of the contract
|
// Call transferFrom function of the contract
|
||||||
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
const trxReceipt = await nftContract.methods.setMetaDataState(metadataState).send({
|
||||||
@ -1266,17 +1131,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const gasLimitDefault = this.GASLIMIT_DEFAULT
|
return estimateGas(address, nftContract.methods.setTokenURI, '1', data)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await nftContract.methods
|
|
||||||
.setTokenURI('1', data)
|
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** set TokenURI on an nft
|
/** set TokenURI on an nft
|
||||||
@ -1295,7 +1150,7 @@ export class Nft {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
|
|
||||||
const estGas = await this.estSetTokenURI(nftAddress, address, data)
|
const estGas = await estimateGas(address, nftContract.methods.setTokenURI, '1', data)
|
||||||
const trxReceipt = await nftContract.methods.setTokenURI('1', data).send({
|
const trxReceipt = await nftContract.methods.setTokenURI('1', data).send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
import { Config } from '../models'
|
import { Config } from '../models'
|
||||||
import { minAbi } from './minAbi'
|
import { minAbi } from './minAbi'
|
||||||
import LoggerInstance from './Logger'
|
import LoggerInstance from './Logger'
|
||||||
import { ZERO_ADDRESS } from './Constants'
|
import { GASLIMIT_DEFAULT, ZERO_ADDRESS } from './Constants'
|
||||||
|
|
||||||
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
export function setContractDefaults(contract: Contract, config: Config): Contract {
|
||||||
if (config) {
|
if (config) {
|
||||||
@ -164,3 +164,29 @@ export async function amountToUnits(
|
|||||||
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18', ${e.message}`)
|
LoggerInstance.error(`ERROR: FAILED TO CALL DECIMALS(), USING 18', ${e.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimates the gas used when a function would be executed on chain
|
||||||
|
* @param {string} from account that calls the function
|
||||||
|
* @param {Function} functionToEstimateGas function that we need to estimate the gas
|
||||||
|
* @param {...any[]} args arguments of the function
|
||||||
|
* @return {Promise<number>} gas cost of the function
|
||||||
|
*/
|
||||||
|
export async function estimateGas(
|
||||||
|
from: string,
|
||||||
|
functionToEstimateGas: Function,
|
||||||
|
...args: any[]
|
||||||
|
): Promise<any> {
|
||||||
|
let estimatedGas = GASLIMIT_DEFAULT
|
||||||
|
try {
|
||||||
|
estimatedGas = await functionToEstimateGas.apply(null, args).estimateGas(
|
||||||
|
{
|
||||||
|
from: from
|
||||||
|
},
|
||||||
|
(err, estGas) => (err ? GASLIMIT_DEFAULT : estGas)
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
LoggerInstance.error(`ERROR: Estimate gas failed!`, e)
|
||||||
|
}
|
||||||
|
return estimatedGas
|
||||||
|
}
|
||||||
|
@ -2,11 +2,11 @@ import Decimal from 'decimal.js'
|
|||||||
import { Pool } from '..'
|
import { Pool } from '..'
|
||||||
|
|
||||||
export function calcMaxExactOut(balance: string): Decimal {
|
export function calcMaxExactOut(balance: string): Decimal {
|
||||||
return new Decimal(balance).div(3.01)
|
return new Decimal(balance).div(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calcMaxExactIn(balance: string): Decimal {
|
export function calcMaxExactIn(balance: string): Decimal {
|
||||||
return new Decimal(balance).div(2.01)
|
return new Decimal(balance).div(2)
|
||||||
}
|
}
|
||||||
export async function getMaxSwapExactOut(
|
export async function getMaxSwapExactOut(
|
||||||
poolInstance: Pool,
|
poolInstance: Pool,
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { amountToUnits, getFairGasPrice, unitsToAmount } from './ContractUtils'
|
import {
|
||||||
|
amountToUnits,
|
||||||
|
estimateGas,
|
||||||
|
getFairGasPrice,
|
||||||
|
unitsToAmount
|
||||||
|
} from './ContractUtils'
|
||||||
import { minAbi } from './minAbi'
|
import { minAbi } from './minAbi'
|
||||||
import LoggerInstance from './Logger'
|
import LoggerInstance from './Logger'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { GASLIMIT_DEFAULT } from './Constants'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate gas cost for approval function
|
* Estimate gas cost for approval function
|
||||||
@ -27,17 +31,7 @@ export async function estApprove(
|
|||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
const gasLimitDefault = GASLIMIT_DEFAULT
|
return estimateGas(account, tokenContract.methods.approve, spender, amount)
|
||||||
let estGas
|
|
||||||
try {
|
|
||||||
estGas = await tokenContract.methods
|
|
||||||
.approve(spender, amount)
|
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
|
||||||
} catch (e) {
|
|
||||||
estGas = gasLimitDefault
|
|
||||||
LoggerInstance.error('estimate gas failed for approve!', e)
|
|
||||||
}
|
|
||||||
return estGas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +39,7 @@ export async function estApprove(
|
|||||||
* @param {String} account
|
* @param {String} account
|
||||||
* @param {String} tokenAddress
|
* @param {String} tokenAddress
|
||||||
* @param {String} spender
|
* @param {String} spender
|
||||||
* @param {String} amount (always expressed as wei)
|
* @param {String} amount amount of ERC20 tokens (always expressed as wei)
|
||||||
* @param {boolean} force if true, will overwrite any previous allowence. Else, will check if allowence is enough and will not send a transaction if it's not needed
|
* @param {boolean} force if true, will overwrite any previous allowence. Else, will check if allowence is enough and will not send a transaction if it's not needed
|
||||||
* @param {number} tokenDecimals optional number of decimals of the token
|
* @param {number} tokenDecimals optional number of decimals of the token
|
||||||
*/
|
*/
|
||||||
@ -67,13 +61,11 @@ export async function approve(
|
|||||||
}
|
}
|
||||||
let result = null
|
let result = null
|
||||||
const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals)
|
const amountFormatted = await amountToUnits(web3, tokenAddress, amount, tokenDecimals)
|
||||||
const estGas = await estApprove(
|
const estGas = await estimateGas(
|
||||||
web3,
|
|
||||||
account,
|
account,
|
||||||
tokenAddress,
|
tokenContract.methods.approve,
|
||||||
spender,
|
spender,
|
||||||
amountFormatted,
|
amountFormatted
|
||||||
tokenContract
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -84,12 +76,73 @@ export async function approve(
|
|||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(
|
LoggerInstance.error(
|
||||||
`ERRPR: Failed to approve spender to spend tokens : ${e.message}`
|
`ERROR: Failed to approve spender to spend tokens : ${e.message}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate gas cost for transfer function
|
||||||
|
* @param {String} account
|
||||||
|
* @param {String} tokenAddress
|
||||||
|
* @param {String} recipient
|
||||||
|
* @param {String} amount
|
||||||
|
* @param {String} force
|
||||||
|
* @param {Contract} contractInstance optional contract instance
|
||||||
|
* @return {Promise<number>}
|
||||||
|
*/
|
||||||
|
export async function estTransfer(
|
||||||
|
web3: Web3,
|
||||||
|
account: string,
|
||||||
|
tokenAddress: string,
|
||||||
|
recipient: string,
|
||||||
|
amount: string,
|
||||||
|
contractInstance?: Contract
|
||||||
|
): Promise<number> {
|
||||||
|
const tokenContract = contractInstance || new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
|
return estimateGas(account, tokenContract.methods.transfer, recipient, amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves amount tokens from the caller’s account to recipient.
|
||||||
|
* @param {String} account
|
||||||
|
* @param {String} tokenAddress
|
||||||
|
* @param {String} recipient
|
||||||
|
* @param {String} amount amount of ERC20 tokens (not as wei)
|
||||||
|
* @param {String} force if true, will overwrite any previous allowence. Else, will check if allowence is enough and will not send a transaction if it's not needed
|
||||||
|
*/
|
||||||
|
export async function transfer(
|
||||||
|
web3: Web3,
|
||||||
|
account: string,
|
||||||
|
tokenAddress: string,
|
||||||
|
recipient: string,
|
||||||
|
amount: string
|
||||||
|
): Promise<TransactionReceipt | string> {
|
||||||
|
const tokenContract = new web3.eth.Contract(minAbi, tokenAddress)
|
||||||
|
|
||||||
|
let result = null
|
||||||
|
const amountFormatted = await amountToUnits(web3, tokenAddress, amount)
|
||||||
|
const estGas = await estimateGas(
|
||||||
|
account,
|
||||||
|
tokenContract.methods.transfer,
|
||||||
|
recipient,
|
||||||
|
amountFormatted
|
||||||
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = await tokenContract.methods.transfer(recipient, amountFormatted).send({
|
||||||
|
from: account,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await getFairGasPrice(web3, null)
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
LoggerInstance.error(`ERROR: Failed to transfer tokens : ${e.message}`)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Allowance for any erc20
|
* Get Allowance for any erc20
|
||||||
* @param {Web3} web3
|
* @param {Web3} web3
|
||||||
|
@ -8,11 +8,39 @@ import {
|
|||||||
NftFactory,
|
NftFactory,
|
||||||
NftCreateData,
|
NftCreateData,
|
||||||
Datatoken,
|
Datatoken,
|
||||||
getHash,
|
|
||||||
Nft,
|
Nft,
|
||||||
sleep
|
sleep,
|
||||||
|
ZERO_ADDRESS
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { ProviderFees, Erc20CreateParams, ComputeJob, Asset } from '../../src/@types'
|
import {
|
||||||
|
Erc20CreateParams,
|
||||||
|
ComputeJob,
|
||||||
|
ComputeAsset,
|
||||||
|
ComputeAlgorithm,
|
||||||
|
ProviderComputeInitialize,
|
||||||
|
ConsumeMarketFee
|
||||||
|
} from '../../src/@types'
|
||||||
|
|
||||||
|
let config: Config
|
||||||
|
|
||||||
|
let aquarius: Aquarius
|
||||||
|
let datatoken: Datatoken
|
||||||
|
let providerUrl: string
|
||||||
|
let consumerAccount: string
|
||||||
|
let publisherAccount: string
|
||||||
|
let computeJobId: string
|
||||||
|
let providerInitializeComputeResults
|
||||||
|
let computeEnvs
|
||||||
|
let addresses: any
|
||||||
|
let ddoWith1mTimeoutId
|
||||||
|
let ddoWithNoTimeoutId
|
||||||
|
let algoDdoWith1mTimeoutId
|
||||||
|
let algoDdoWithNoTimeoutId
|
||||||
|
|
||||||
|
let resolvedDdoWith1mTimeout
|
||||||
|
let resolvedDdoWithNoTimeout
|
||||||
|
let resolvedAlgoDdoWith1mTimeout
|
||||||
|
let resolvedAlgoDdoWithNoTimeout
|
||||||
|
|
||||||
const assetUrl = [
|
const assetUrl = [
|
||||||
{
|
{
|
||||||
@ -21,7 +49,7 @@ const assetUrl = [
|
|||||||
method: 'GET'
|
method: 'GET'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const ddo = {
|
const ddoWithNoTimeout = {
|
||||||
'@context': ['https://w3id.org/did/v1'],
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
||||||
version: '4.0.0',
|
version: '4.0.0',
|
||||||
@ -52,13 +80,44 @@ const ddo = {
|
|||||||
publisherTrustedAlgorithmPublishers: [],
|
publisherTrustedAlgorithmPublishers: [],
|
||||||
publisherTrustedAlgorithms: [],
|
publisherTrustedAlgorithms: [],
|
||||||
allowRawAlgorithm: true,
|
allowRawAlgorithm: true,
|
||||||
allowNetworkAccess: true,
|
allowNetworkAccess: true
|
||||||
namespace: 'ocean-compute',
|
}
|
||||||
cpus: 2,
|
}
|
||||||
gpus: 4,
|
]
|
||||||
gpuType: 'NVIDIA Tesla V100 GPU',
|
}
|
||||||
memory: '128M',
|
|
||||||
volumeSize: '2G'
|
const ddoWith1mTimeout = {
|
||||||
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
|
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
||||||
|
version: '4.0.0',
|
||||||
|
chainId: 4,
|
||||||
|
nftAddress: '0x0',
|
||||||
|
metadata: {
|
||||||
|
created: '2021-12-20T14:35:20Z',
|
||||||
|
updated: '2021-12-20T14:35:20Z',
|
||||||
|
type: 'dataset',
|
||||||
|
name: 'dfgdfgdg',
|
||||||
|
description: 'd dfgd fgd dfg dfgdfgd dfgdf',
|
||||||
|
tags: [''],
|
||||||
|
author: 'dd',
|
||||||
|
license: 'https://market.oceanprotocol.com/terms',
|
||||||
|
additionalInformation: {
|
||||||
|
termsAndConditions: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
services: [
|
||||||
|
{
|
||||||
|
id: 'notAnId',
|
||||||
|
type: 'compute',
|
||||||
|
files: '',
|
||||||
|
datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3',
|
||||||
|
serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com',
|
||||||
|
timeout: 60,
|
||||||
|
compute: {
|
||||||
|
publisherTrustedAlgorithmPublishers: [],
|
||||||
|
publisherTrustedAlgorithms: [],
|
||||||
|
allowRawAlgorithm: true,
|
||||||
|
allowNetworkAccess: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -70,7 +129,7 @@ const algoAssetUrl = [
|
|||||||
method: 'GET'
|
method: 'GET'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const algoDdo = {
|
const algoDdoWithNoTimeout = {
|
||||||
'@context': ['https://w3id.org/did/v1'],
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
||||||
version: '4.0.0',
|
version: '4.0.0',
|
||||||
@ -110,54 +169,80 @@ const algoDdo = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
let providerUrl: string
|
|
||||||
let consumerAccount: string
|
|
||||||
let computeJobId: string
|
|
||||||
let resolvedDDOAsset: Asset
|
|
||||||
|
|
||||||
describe('Simple compute tests', async () => {
|
const algoDdoWith1mTimeout = {
|
||||||
let config: Config
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
let addresses: any
|
id: 'did:op:efba17455c127a885ec7830d687a8f6e64f5ba559f8506f8723c1f10f05c049c',
|
||||||
let aquarius: Aquarius
|
version: '4.0.0',
|
||||||
|
chainId: 4,
|
||||||
|
nftAddress: '0x0',
|
||||||
|
metadata: {
|
||||||
|
created: '2021-12-20T14:35:20Z',
|
||||||
|
updated: '2021-12-20T14:35:20Z',
|
||||||
|
type: 'algorithm',
|
||||||
|
name: 'dfgdfgdg',
|
||||||
|
description: 'd dfgd fgd dfg dfgdfgd dfgdf',
|
||||||
|
tags: [''],
|
||||||
|
author: 'dd',
|
||||||
|
license: 'https://market.oceanprotocol.com/terms',
|
||||||
|
additionalInformation: {
|
||||||
|
termsAndConditions: true
|
||||||
|
},
|
||||||
|
algorithm: {
|
||||||
|
language: 'Node.js',
|
||||||
|
version: '1.0.0',
|
||||||
|
container: {
|
||||||
|
entrypoint: 'node $ALGO',
|
||||||
|
image: 'ubuntu',
|
||||||
|
tag: 'latest',
|
||||||
|
checksum: '44e10daa6637893f4276bb8d7301eb35306ece50f61ca34dcab550'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
services: [
|
||||||
|
{
|
||||||
|
id: 'notAnId',
|
||||||
|
type: 'access',
|
||||||
|
files: '',
|
||||||
|
datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3',
|
||||||
|
serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com',
|
||||||
|
timeout: 60
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
before(async () => {
|
async function createAsset(
|
||||||
config = await getTestConfig(web3)
|
name: string,
|
||||||
addresses = getAddresses()
|
symbol: string,
|
||||||
aquarius = new Aquarius(config.metadataCacheUri)
|
owner: string,
|
||||||
providerUrl = config.providerUri
|
assetUrl: any,
|
||||||
})
|
ddo: any,
|
||||||
|
providerUrl: string
|
||||||
it('should publish a dataset, algorithm and start a compute job', async () => {
|
) {
|
||||||
const nft = new Nft(web3)
|
const nft = new Nft(web3)
|
||||||
const datatoken = new Datatoken(web3)
|
|
||||||
const Factory = new NftFactory(addresses.ERC721Factory, web3)
|
const Factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||||
const accounts = await web3.eth.getAccounts()
|
|
||||||
const publisherAccount = accounts[0]
|
|
||||||
consumerAccount = accounts[1]
|
|
||||||
const chain = await web3.eth.getChainId()
|
const chain = await web3.eth.getChainId()
|
||||||
|
ddo.chainId = parseInt(chain.toString(10))
|
||||||
const nftParamsAsset: NftCreateData = {
|
const nftParamsAsset: NftCreateData = {
|
||||||
name: 'testNFT',
|
name: name,
|
||||||
symbol: 'TST',
|
symbol: symbol,
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: 'aaa',
|
tokenURI: 'aaa',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: publisherAccount
|
owner: owner
|
||||||
}
|
}
|
||||||
const erc20ParamsAsset: Erc20CreateParams = {
|
const erc20ParamsAsset: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: '0x0000000000000000000000000000000000000000',
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: publisherAccount,
|
minter: owner,
|
||||||
mpFeeAddress: '0x0000000000000000000000000000000000000000'
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await Factory.createNftWithErc20(
|
const result = await Factory.createNftWithErc20(owner, nftParamsAsset, erc20ParamsAsset)
|
||||||
publisherAccount,
|
|
||||||
nftParamsAsset,
|
|
||||||
erc20ParamsAsset
|
|
||||||
)
|
|
||||||
|
|
||||||
const erc721AddressAsset = result.events.NFTCreated.returnValues[0]
|
const erc721AddressAsset = result.events.NFTCreated.returnValues[0]
|
||||||
const datatokenAddressAsset = result.events.TokenCreated.returnValues[0]
|
const datatokenAddressAsset = result.events.TokenCreated.returnValues[0]
|
||||||
@ -165,89 +250,165 @@ describe('Simple compute tests', async () => {
|
|||||||
let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||||
ddo.services[0].files = await providerResponse
|
ddo.services[0].files = await providerResponse
|
||||||
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
ddo.services[0].datatokenAddress = datatokenAddressAsset
|
||||||
|
ddo.services[0].serviceEndpoint = providerUrl
|
||||||
// update ddo and set the right did
|
// update ddo and set the right did
|
||||||
ddo.nftAddress = erc721AddressAsset
|
ddo.nftAddress = web3.utils.toChecksumAddress(erc721AddressAsset)
|
||||||
ddo.id =
|
ddo.id =
|
||||||
'did:op:' +
|
'did:op:' +
|
||||||
SHA256(web3.utils.toChecksumAddress(erc721AddressAsset) + chain.toString(10))
|
SHA256(web3.utils.toChecksumAddress(erc721AddressAsset) + chain.toString(10))
|
||||||
|
|
||||||
providerResponse = await ProviderInstance.encrypt(ddo, providerUrl)
|
providerResponse = await ProviderInstance.encrypt(ddo, providerUrl)
|
||||||
|
const encryptedResponse = await providerResponse
|
||||||
let encryptedResponse = await providerResponse
|
const validateResult = await aquarius.validate(ddo)
|
||||||
let metadataHash = getHash(JSON.stringify(ddo))
|
assert(validateResult.valid, 'Could not validate metadata')
|
||||||
let res = await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
erc721AddressAsset,
|
erc721AddressAsset,
|
||||||
publisherAccount,
|
owner,
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
providerUrl,
|
||||||
'',
|
'',
|
||||||
'0x2',
|
'0x2',
|
||||||
encryptedResponse,
|
encryptedResponse,
|
||||||
'0x' + metadataHash
|
validateResult.hash
|
||||||
|
)
|
||||||
|
return ddo.id
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleOrder(
|
||||||
|
order: ProviderComputeInitialize,
|
||||||
|
datatokenAddress: string,
|
||||||
|
payerAccount: string,
|
||||||
|
consumerAccount: string,
|
||||||
|
serviceIndex: number,
|
||||||
|
consumeMarkerFee?: ConsumeMarketFee
|
||||||
|
) {
|
||||||
|
/* We do have 3 possible situations:
|
||||||
|
- have validOrder and no providerFees -> then order is valid, providerFees are valid, just use it in startCompute
|
||||||
|
- have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
|
||||||
|
- no validOrder -> we need to call startOrder, to pay 1 DT & providerFees
|
||||||
|
*/
|
||||||
|
if (order.providerFee && order.providerFee.providerFeeAmount) {
|
||||||
|
await datatoken.approve(
|
||||||
|
order.providerFee.providerFeeToken,
|
||||||
|
datatokenAddress,
|
||||||
|
order.providerFee.providerFeeAmount,
|
||||||
|
payerAccount
|
||||||
)
|
)
|
||||||
// let's publish the algorithm as well
|
|
||||||
const nftParamsAlgo: NftCreateData = {
|
|
||||||
name: 'testNFT',
|
|
||||||
symbol: 'TST',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: '',
|
|
||||||
transferable: true,
|
|
||||||
owner: publisherAccount
|
|
||||||
}
|
}
|
||||||
const erc20ParamsAlgo: Erc20CreateParams = {
|
if (order.validOrder) {
|
||||||
templateIndex: 1,
|
if (!order.providerFee) return order.validOrder
|
||||||
cap: '100000',
|
const tx = await datatoken.reuseOrder(
|
||||||
feeAmount: '0',
|
datatokenAddress,
|
||||||
paymentCollector: '0x0000000000000000000000000000000000000000',
|
payerAccount,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
order.validOrder,
|
||||||
minter: publisherAccount,
|
order.providerFee
|
||||||
mpFeeAddress: '0x0000000000000000000000000000000000000000'
|
)
|
||||||
|
return tx.transactionHash
|
||||||
}
|
}
|
||||||
const resultAlgo = await Factory.createNftWithErc20(
|
const tx = await datatoken.startOrder(
|
||||||
publisherAccount,
|
datatokenAddress,
|
||||||
nftParamsAlgo,
|
payerAccount,
|
||||||
erc20ParamsAlgo
|
consumerAccount,
|
||||||
|
serviceIndex,
|
||||||
|
order.providerFee,
|
||||||
|
consumeMarkerFee
|
||||||
)
|
)
|
||||||
const erc721AddressAlgo = resultAlgo.events.NFTCreated.returnValues[0]
|
return tx.transactionHash
|
||||||
const datatokenAddressAlgo = resultAlgo.events.TokenCreated.returnValues[0]
|
}
|
||||||
|
|
||||||
// create the files encrypted string
|
describe('Simple compute tests', async () => {
|
||||||
providerResponse = await ProviderInstance.encrypt(algoAssetUrl, providerUrl)
|
before(async () => {
|
||||||
algoDdo.services[0].files = await providerResponse
|
config = await getTestConfig(web3)
|
||||||
algoDdo.services[0].datatokenAddress = datatokenAddressAlgo
|
addresses = getAddresses()
|
||||||
// update ddo and set the right did
|
aquarius = new Aquarius(config.metadataCacheUri)
|
||||||
algoDdo.nftAddress = erc721AddressAlgo
|
providerUrl = config.providerUri
|
||||||
|
datatoken = new Datatoken(web3)
|
||||||
|
})
|
||||||
|
|
||||||
algoDdo.id =
|
it('should publish datasets and algorithms', async () => {
|
||||||
'did:op:' +
|
const accounts = await web3.eth.getAccounts()
|
||||||
SHA256(web3.utils.toChecksumAddress(erc721AddressAlgo) + chain.toString(10))
|
publisherAccount = accounts[0]
|
||||||
|
consumerAccount = accounts[1]
|
||||||
providerResponse = await ProviderInstance.encrypt(algoDdo, providerUrl)
|
ddoWith1mTimeoutId = await createAsset(
|
||||||
encryptedResponse = await providerResponse
|
'D1Min',
|
||||||
metadataHash = getHash(JSON.stringify(algoDdo))
|
'D1M',
|
||||||
res = await nft.setMetadata(
|
|
||||||
erc721AddressAlgo,
|
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
0,
|
assetUrl,
|
||||||
providerUrl,
|
ddoWith1mTimeout,
|
||||||
'',
|
providerUrl
|
||||||
'0x2',
|
)
|
||||||
encryptedResponse,
|
ddoWithNoTimeoutId = await createAsset(
|
||||||
'0x' + metadataHash
|
'D1Min',
|
||||||
|
'D1M',
|
||||||
|
publisherAccount,
|
||||||
|
assetUrl,
|
||||||
|
ddoWithNoTimeout,
|
||||||
|
providerUrl
|
||||||
|
)
|
||||||
|
algoDdoWith1mTimeoutId = await createAsset(
|
||||||
|
'A1Min',
|
||||||
|
'A1M',
|
||||||
|
publisherAccount,
|
||||||
|
algoAssetUrl,
|
||||||
|
algoDdoWith1mTimeout,
|
||||||
|
providerUrl
|
||||||
)
|
)
|
||||||
|
|
||||||
// let's wait
|
algoDdoWithNoTimeoutId = await createAsset(
|
||||||
resolvedDDOAsset = await aquarius.waitForAqua(ddo.id)
|
'A1Min',
|
||||||
assert(resolvedDDOAsset, 'Cannot fetch DDO from Aquarius')
|
'A1M',
|
||||||
const resolvedDDOAlgo = await aquarius.waitForAqua(algoDdo.id)
|
publisherAccount,
|
||||||
assert(resolvedDDOAlgo, 'Cannot fetch DDO from Aquarius')
|
algoAssetUrl,
|
||||||
// mint 1 ERC20 and send it to the consumer
|
algoDdoWithNoTimeout,
|
||||||
await datatoken.mint(datatokenAddressAsset, publisherAccount, '1', consumerAccount)
|
providerUrl
|
||||||
await datatoken.mint(datatokenAddressAlgo, publisherAccount, '1', consumerAccount)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should resolve published datasets and algorithms', async () => {
|
||||||
|
resolvedDdoWith1mTimeout = await aquarius.waitForAqua(ddoWith1mTimeoutId)
|
||||||
|
assert(resolvedDdoWith1mTimeout, 'Cannot fetch DDO from Aquarius')
|
||||||
|
resolvedDdoWithNoTimeout = await aquarius.waitForAqua(ddoWithNoTimeoutId)
|
||||||
|
assert(resolvedDdoWithNoTimeout, 'Cannot fetch DDO from Aquarius')
|
||||||
|
resolvedAlgoDdoWith1mTimeout = await aquarius.waitForAqua(algoDdoWith1mTimeoutId)
|
||||||
|
assert(resolvedAlgoDdoWith1mTimeout, 'Cannot fetch DDO from Aquarius')
|
||||||
|
resolvedAlgoDdoWithNoTimeout = await aquarius.waitForAqua(algoDdoWithNoTimeoutId)
|
||||||
|
assert(resolvedAlgoDdoWithNoTimeout, 'Cannot fetch DDO from Aquarius')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should send DT to consumer', async () => {
|
||||||
|
const datatoken = new Datatoken(web3)
|
||||||
|
await datatoken.mint(
|
||||||
|
resolvedDdoWith1mTimeout.services[0].datatokenAddress,
|
||||||
|
publisherAccount,
|
||||||
|
'10',
|
||||||
|
consumerAccount
|
||||||
|
)
|
||||||
|
await datatoken.mint(
|
||||||
|
resolvedDdoWithNoTimeout.services[0].datatokenAddress,
|
||||||
|
publisherAccount,
|
||||||
|
'10',
|
||||||
|
consumerAccount
|
||||||
|
)
|
||||||
|
await datatoken.mint(
|
||||||
|
resolvedAlgoDdoWith1mTimeout.services[0].datatokenAddress,
|
||||||
|
publisherAccount,
|
||||||
|
'10',
|
||||||
|
consumerAccount
|
||||||
|
)
|
||||||
|
await datatoken.mint(
|
||||||
|
resolvedAlgoDdoWithNoTimeout.services[0].datatokenAddress,
|
||||||
|
publisherAccount,
|
||||||
|
'10',
|
||||||
|
consumerAccount
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should fetch compute environments from provider', async () => {
|
||||||
// get compute environments
|
// get compute environments
|
||||||
const computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
|
||||||
assert(computeEnvs, 'No Compute environments found')
|
assert(computeEnvs, 'No Compute environments found')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should start a computeJob', async () => {
|
||||||
// we choose the first env
|
// we choose the first env
|
||||||
const computeEnv = computeEnvs[0].id
|
const computeEnv = computeEnvs[0].id
|
||||||
const computeConsumerAddress = computeEnvs[0].consumerAddress
|
const computeConsumerAddress = computeEnvs[0].consumerAddress
|
||||||
@ -255,89 +416,53 @@ describe('Simple compute tests', async () => {
|
|||||||
const mytime = new Date()
|
const mytime = new Date()
|
||||||
mytime.setMinutes(mytime.getMinutes() + 19)
|
mytime.setMinutes(mytime.getMinutes() + 19)
|
||||||
const computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
const computeValidUntil = Math.floor(mytime.getTime() / 1000)
|
||||||
// initialize provider orders for algo
|
const assets: ComputeAsset[] = [
|
||||||
const initializeDataAlgo = await ProviderInstance.initialize(
|
{
|
||||||
resolvedDDOAlgo.id,
|
documentId: resolvedDdoWith1mTimeout.id,
|
||||||
resolvedDDOAlgo.services[0].id,
|
serviceId: resolvedDdoWith1mTimeout.services[0].id
|
||||||
0,
|
}
|
||||||
consumerAccount,
|
]
|
||||||
providerUrl,
|
const dtAddressArray = [resolvedDdoWith1mTimeout.services[0].datatokenAddress]
|
||||||
null,
|
const algo: ComputeAlgorithm = {
|
||||||
null,
|
documentId: resolvedAlgoDdoWith1mTimeout.id,
|
||||||
computeEnv,
|
serviceId: resolvedAlgoDdoWith1mTimeout.services[0].id
|
||||||
computeValidUntil
|
|
||||||
)
|
|
||||||
const providerAlgoFees: ProviderFees = {
|
|
||||||
providerFeeAddress: initializeDataAlgo.providerFee.providerFeeAddress,
|
|
||||||
providerFeeToken: initializeDataAlgo.providerFee.providerFeeToken,
|
|
||||||
providerFeeAmount: initializeDataAlgo.providerFee.providerFeeAmount,
|
|
||||||
v: initializeDataAlgo.providerFee.v,
|
|
||||||
r: initializeDataAlgo.providerFee.r,
|
|
||||||
s: initializeDataAlgo.providerFee.s,
|
|
||||||
providerData: initializeDataAlgo.providerFee.providerData,
|
|
||||||
validUntil: initializeDataAlgo.providerFee.validUntil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the payment
|
providerInitializeComputeResults = await ProviderInstance.initializeCompute(
|
||||||
const txidAlgo = await datatoken.startOrder(
|
assets,
|
||||||
datatokenAddressAlgo,
|
algo,
|
||||||
consumerAccount,
|
|
||||||
computeConsumerAddress, // this is important because the c2d is the consumer, and user is the payer. Otherwise, c2d will have no access to the asset
|
|
||||||
0,
|
|
||||||
providerAlgoFees
|
|
||||||
)
|
|
||||||
assert(txidAlgo, 'Failed to order algo')
|
|
||||||
|
|
||||||
const providerValidUntil = new Date()
|
|
||||||
providerValidUntil.setHours(providerValidUntil.getHours() + 1)
|
|
||||||
|
|
||||||
// initialize provider orders for asset
|
|
||||||
const initializeData = await ProviderInstance.initialize(
|
|
||||||
resolvedDDOAsset.id,
|
|
||||||
resolvedDDOAsset.services[0].id,
|
|
||||||
0,
|
|
||||||
consumerAccount,
|
|
||||||
providerUrl,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
computeEnv,
|
computeEnv,
|
||||||
computeValidUntil
|
computeValidUntil,
|
||||||
|
providerUrl,
|
||||||
|
consumerAccount
|
||||||
)
|
)
|
||||||
const providerDatasetFees: ProviderFees = {
|
assert(
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
!('error' in providerInitializeComputeResults.algorithm),
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
'Cannot order algorithm'
|
||||||
providerFeeAmount: initializeData.providerFee.providerFeeAmount,
|
)
|
||||||
v: initializeData.providerFee.v,
|
algo.transferTxId = await handleOrder(
|
||||||
r: initializeData.providerFee.r,
|
providerInitializeComputeResults.algorithm,
|
||||||
s: initializeData.providerFee.s,
|
resolvedAlgoDdoWith1mTimeout.services[0].datatokenAddress,
|
||||||
providerData: initializeData.providerFee.providerData,
|
|
||||||
validUntil: initializeData.providerFee.validUntil
|
|
||||||
}
|
|
||||||
// make the payment
|
|
||||||
const txidAsset = await datatoken.startOrder(
|
|
||||||
datatokenAddressAsset,
|
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
computeConsumerAddress, // this is important because the c2d is the consumer, and user is the payer. Otherwise, c2d will have no access to the asset
|
computeConsumerAddress,
|
||||||
0,
|
0
|
||||||
providerDatasetFees
|
|
||||||
)
|
)
|
||||||
assert(txidAsset, 'Failed to order algo')
|
for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
|
||||||
// start the compute job
|
assets[i].transferTxId = await handleOrder(
|
||||||
|
providerInitializeComputeResults.datasets[i],
|
||||||
|
dtAddressArray[i],
|
||||||
|
consumerAccount,
|
||||||
|
computeConsumerAddress,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
}
|
||||||
const computeJobs = await ProviderInstance.computeStart(
|
const computeJobs = await ProviderInstance.computeStart(
|
||||||
providerUrl,
|
providerUrl,
|
||||||
web3,
|
web3,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
computeEnv,
|
computeEnv,
|
||||||
{
|
assets[0],
|
||||||
documentId: resolvedDDOAsset.id,
|
algo
|
||||||
serviceId: resolvedDDOAsset.services[0].id,
|
|
||||||
transferTxId: txidAsset.transactionHash
|
|
||||||
},
|
|
||||||
{
|
|
||||||
documentId: resolvedDDOAlgo.id,
|
|
||||||
serviceId: resolvedDDOAlgo.services[0].id,
|
|
||||||
transferTxId: txidAlgo.transactionHash
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
assert(computeJobs, 'Cannot start compute job')
|
assert(computeJobs, 'Cannot start compute job')
|
||||||
computeJobId = computeJobs[0].jobId
|
computeJobId = computeJobs[0].jobId
|
||||||
@ -348,7 +473,7 @@ describe('Simple compute tests', async () => {
|
|||||||
providerUrl,
|
providerUrl,
|
||||||
consumerAccount,
|
consumerAccount,
|
||||||
computeJobId,
|
computeJobId,
|
||||||
resolvedDDOAsset.id
|
resolvedDdoWith1mTimeout.id
|
||||||
)) as ComputeJob
|
)) as ComputeJob
|
||||||
assert(jobStatus, 'Cannot retrieve compute status!')
|
assert(jobStatus, 'Cannot retrieve compute status!')
|
||||||
})
|
})
|
||||||
|
@ -10,9 +10,11 @@ import {
|
|||||||
Datatoken,
|
Datatoken,
|
||||||
getHash,
|
getHash,
|
||||||
Nft,
|
Nft,
|
||||||
downloadFile
|
downloadFile,
|
||||||
|
ZERO_ADDRESS
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { ProviderFees, Erc20CreateParams, DDO } from '../../src/@types'
|
import { ProviderFees, Erc20CreateParams, DDO } from '../../src/@types'
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
const assetUrl = [
|
const assetUrl = [
|
||||||
{
|
{
|
||||||
@ -51,51 +53,93 @@ const ddo: DDO = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
>>>>>>> 620b5d3a24e3d76a7b9ac1fc78a370add76f549a
|
||||||
|
|
||||||
describe('Simple Publish & consume test', async () => {
|
describe('Simple Publish & consume test', async () => {
|
||||||
let config: Config
|
let config: Config
|
||||||
let addresses: any
|
let addresses: any
|
||||||
let aquarius: Aquarius
|
let aquarius: Aquarius
|
||||||
let providerUrl: any
|
let providerUrl: any
|
||||||
|
let publisherAccount: string
|
||||||
|
let consumerAccount: string
|
||||||
|
|
||||||
|
const assetUrl = [
|
||||||
|
{
|
||||||
|
type: 'url',
|
||||||
|
url: 'https://raw.githubusercontent.com/oceanprotocol/testdatasets/main/shs_dataset_test.txt',
|
||||||
|
method: 'GET'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const ddo: DDO = {
|
||||||
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
|
id: '',
|
||||||
|
version: '4.0.0',
|
||||||
|
chainId: 4,
|
||||||
|
nftAddress: '0x0',
|
||||||
|
metadata: {
|
||||||
|
created: '2021-12-20T14:35:20Z',
|
||||||
|
updated: '2021-12-20T14:35:20Z',
|
||||||
|
type: 'dataset',
|
||||||
|
name: 'dataset-name',
|
||||||
|
description: 'Ocean protocol test dataset description',
|
||||||
|
author: 'oceanprotocol-team',
|
||||||
|
license: 'MIT'
|
||||||
|
},
|
||||||
|
services: [
|
||||||
|
{
|
||||||
|
id: 'testFakeId',
|
||||||
|
type: 'access',
|
||||||
|
files: '',
|
||||||
|
datatokenAddress: '0x0',
|
||||||
|
serviceEndpoint: 'https://providerv4.rinkeby.oceanprotocol.com',
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
config = await getTestConfig(web3)
|
config = await getTestConfig(web3)
|
||||||
addresses = getAddresses()
|
|
||||||
aquarius = new Aquarius(config.metadataCacheUri)
|
aquarius = new Aquarius(config.metadataCacheUri)
|
||||||
providerUrl = config.providerUri
|
providerUrl = config.providerUri
|
||||||
|
|
||||||
|
addresses = getAddresses()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Initialize accounts', async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
publisherAccount = accounts[0]
|
||||||
|
consumerAccount = accounts[1]
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should publish a dataset (create NFT + ERC20)', async () => {
|
it('should publish a dataset (create NFT + ERC20)', async () => {
|
||||||
const nft = new Nft(web3)
|
const nft = new Nft(web3)
|
||||||
const datatoken = new Datatoken(web3)
|
const datatoken = new Datatoken(web3)
|
||||||
const Factory = new NftFactory(addresses.ERC721Factory, web3)
|
const Factory = new NftFactory(addresses.ERC721Factory, web3)
|
||||||
const accounts = await web3.eth.getAccounts()
|
|
||||||
const publisherAccount = accounts[0]
|
|
||||||
const consumerAccount = accounts[1]
|
|
||||||
const nftParams: NftCreateData = {
|
const nftParams: NftCreateData = {
|
||||||
name: 'testNFT',
|
name: '72120Bundle',
|
||||||
symbol: 'TST',
|
symbol: '72Bundle',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: '',
|
tokenURI: 'https://oceanprotocol.com/nft/',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: publisherAccount
|
owner: publisherAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
const erc20Params: Erc20CreateParams = {
|
const erc20Params: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
paymentCollector: '0x0000000000000000000000000000000000000000',
|
paymentCollector: ZERO_ADDRESS,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: ZERO_ADDRESS,
|
||||||
minter: publisherAccount,
|
minter: publisherAccount,
|
||||||
mpFeeAddress: '0x0000000000000000000000000000000000000000'
|
mpFeeAddress: ZERO_ADDRESS
|
||||||
}
|
}
|
||||||
const result = await Factory.createNftWithErc20(
|
|
||||||
publisherAccount,
|
const tx = await Factory.createNftWithErc20(publisherAccount, nftParams, erc20Params)
|
||||||
nftParams,
|
const erc721Address = tx.events.NFTCreated.returnValues[0]
|
||||||
erc20Params
|
const datatokenAddress = tx.events.TokenCreated.returnValues[0]
|
||||||
)
|
|
||||||
const erc721Address = result.events.NFTCreated.returnValues[0]
|
|
||||||
const datatokenAddress = result.events.TokenCreated.returnValues[0]
|
|
||||||
|
|
||||||
// create the files encrypted string
|
// create the files encrypted string
|
||||||
let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
let providerResponse = await ProviderInstance.encrypt(assetUrl, providerUrl)
|
||||||
@ -110,7 +154,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
providerResponse = await ProviderInstance.encrypt(ddo, providerUrl)
|
providerResponse = await ProviderInstance.encrypt(ddo, providerUrl)
|
||||||
const encryptedResponse = await providerResponse
|
const encryptedResponse = await providerResponse
|
||||||
const metadataHash = getHash(JSON.stringify(ddo))
|
const metadataHash = getHash(JSON.stringify(ddo))
|
||||||
const res = await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
erc721Address,
|
erc721Address,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
0,
|
0,
|
||||||
@ -120,10 +164,13 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
encryptedResponse,
|
encryptedResponse,
|
||||||
'0x' + metadataHash
|
'0x' + metadataHash
|
||||||
)
|
)
|
||||||
|
|
||||||
const resolvedDDO = await aquarius.waitForAqua(ddo.id)
|
const resolvedDDO = await aquarius.waitForAqua(ddo.id)
|
||||||
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
|
||||||
|
|
||||||
// mint 1 ERC20 and send it to the consumer
|
// mint 1 ERC20 and send it to the consumer
|
||||||
await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount)
|
await datatoken.mint(datatokenAddress, publisherAccount, '1', consumerAccount)
|
||||||
|
|
||||||
// initialize provider
|
// initialize provider
|
||||||
const initializeData = await ProviderInstance.initialize(
|
const initializeData = await ProviderInstance.initialize(
|
||||||
resolvedDDO.id,
|
resolvedDDO.id,
|
||||||
@ -132,6 +179,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
consumerAccount,
|
consumerAccount,
|
||||||
providerUrl
|
providerUrl
|
||||||
)
|
)
|
||||||
|
|
||||||
const providerFees: ProviderFees = {
|
const providerFees: ProviderFees = {
|
||||||
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
providerFeeAddress: initializeData.providerFee.providerFeeAddress,
|
||||||
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
providerFeeToken: initializeData.providerFee.providerFeeToken,
|
||||||
@ -142,6 +190,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
providerData: initializeData.providerFee.providerData,
|
providerData: initializeData.providerFee.providerData,
|
||||||
validUntil: initializeData.providerFee.validUntil
|
validUntil: initializeData.providerFee.validUntil
|
||||||
}
|
}
|
||||||
|
|
||||||
// make the payment
|
// make the payment
|
||||||
const txid = await datatoken.startOrder(
|
const txid = await datatoken.startOrder(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
@ -150,6 +199,7 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
0,
|
0,
|
||||||
providerFees
|
providerFees
|
||||||
)
|
)
|
||||||
|
|
||||||
// get the url
|
// get the url
|
||||||
const downloadURL = await ProviderInstance.getDownloadUrl(
|
const downloadURL = await ProviderInstance.getDownloadUrl(
|
||||||
ddo.id,
|
ddo.id,
|
||||||
@ -160,9 +210,10 @@ describe('Simple Publish & consume test', async () => {
|
|||||||
providerUrl,
|
providerUrl,
|
||||||
web3
|
web3
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(downloadURL, 'Provider getDownloadUrl failed')
|
assert(downloadURL, 'Provider getDownloadUrl failed')
|
||||||
try {
|
try {
|
||||||
const fileData = await downloadFile(downloadURL)
|
await downloadFile(downloadURL)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
assert.fail('Download failed')
|
assert.fail('Download failed')
|
||||||
}
|
}
|
||||||
|
@ -468,13 +468,6 @@ describe('Pool unit test', () => {
|
|||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getOPCCollector- should get market fees for each token', async () => {
|
|
||||||
assert(
|
|
||||||
(await pool.getOPCCollector(poolAddress)) ===
|
|
||||||
contracts.opfCommunityFeeCollectorAddress
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('#collectCommunityFee- should get community fees for each token', async () => {
|
it('#collectCommunityFee- should get community fees for each token', async () => {
|
||||||
const spotPriceBefore = await pool.getSpotPrice(
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -953,13 +946,6 @@ describe('Pool unit test', () => {
|
|||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
assert((await pool.getMarketFeeCollector(poolAddress)) === factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getOPCCollector- should get market fees for each token', async () => {
|
|
||||||
assert(
|
|
||||||
(await pool.getOPCCollector(poolAddress)) ===
|
|
||||||
contracts.opfCommunityFeeCollectorAddress
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('#getCurrentMarketFees- should get curent market fees for each token', async () => {
|
it('#getCurrentMarketFees- should get curent market fees for each token', async () => {
|
||||||
const currentMarketFees: CurrentFees = await pool.getCurrentMarketFees(poolAddress)
|
const currentMarketFees: CurrentFees = await pool.getCurrentMarketFees(poolAddress)
|
||||||
assert(currentMarketFees !== null)
|
assert(currentMarketFees !== null)
|
||||||
|
@ -132,11 +132,6 @@ describe('Fixed Rate unit test', () => {
|
|||||||
it('#getOwner - should get exchange owner given an id', async () => {
|
it('#getOwner - should get exchange owner given an id', async () => {
|
||||||
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
|
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
|
||||||
})
|
})
|
||||||
it('#getOPFCollector - should get OPF collector', async () => {
|
|
||||||
expect(await fixedRate.getOPCCollector()).to.equal(
|
|
||||||
contracts.opfCommunityFeeCollectorAddress
|
|
||||||
)
|
|
||||||
})
|
|
||||||
it('#getRouter - should get Router address', async () => {
|
it('#getRouter - should get Router address', async () => {
|
||||||
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
|
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
|
||||||
})
|
})
|
||||||
@ -453,11 +448,6 @@ describe('Fixed Rate unit test', () => {
|
|||||||
it('#getOwner - should get exchange owner given an id', async () => {
|
it('#getOwner - should get exchange owner given an id', async () => {
|
||||||
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
|
expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner)
|
||||||
})
|
})
|
||||||
it('#getOPFCollector - should get OPF collector', async () => {
|
|
||||||
expect(await fixedRate.getOPCCollector()).to.equal(
|
|
||||||
contracts.opfCommunityFeeCollectorAddress
|
|
||||||
)
|
|
||||||
})
|
|
||||||
it('#getRouter - should get Router address', async () => {
|
it('#getRouter - should get Router address', async () => {
|
||||||
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
|
expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user