mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
use solidity setup pool function when creating new pool.
This commit is contained in:
parent
0968638f9c
commit
d47a9f02a6
@ -26,9 +26,10 @@ export class OceanPool extends Pool {
|
||||
/**
|
||||
* Create DataToken pool
|
||||
@param {String} account
|
||||
* @param {String} token Data Token address
|
||||
* @param {String} amount Data Token amount
|
||||
* @param {String} weight Data Token weight
|
||||
* @param {String} token DataToken address
|
||||
* @param {String} amount DataToken amount
|
||||
* @param {String} weight DataToken weight
|
||||
* @param {String} fee Swap fee in Wei
|
||||
* @return {String}
|
||||
*/
|
||||
public async createDTPool(
|
||||
@ -37,7 +38,6 @@ export class OceanPool extends Pool {
|
||||
amount: string,
|
||||
weight: string,
|
||||
fee: string,
|
||||
finalize = true
|
||||
): Promise<string> {
|
||||
if (this.oceanAddress == null) {
|
||||
console.error('oceanAddress is not defined')
|
||||
@ -50,22 +50,28 @@ export class OceanPool extends Pool {
|
||||
const address = await super.createPool(account)
|
||||
const oceanWeight = 10 - parseFloat(weight)
|
||||
const oceanAmount = (parseFloat(amount) * oceanWeight) / parseFloat(weight)
|
||||
const tokens = [
|
||||
{
|
||||
address: token,
|
||||
amount: String(amount),
|
||||
weight: String(weight)
|
||||
},
|
||||
{
|
||||
address: this.oceanAddress,
|
||||
amount: String(oceanAmount),
|
||||
weight: String(oceanWeight)
|
||||
}
|
||||
]
|
||||
this.dtAddress = token
|
||||
await super.addToPool(account, address, tokens)
|
||||
await super.setSwapFee(account, address, fee)
|
||||
if (finalize) await super.finalize(account, address)
|
||||
|
||||
await this.approve(
|
||||
account,
|
||||
token,
|
||||
address,
|
||||
this.web3.utils.toWei(String(amount)) as any
|
||||
)
|
||||
await this.approve(
|
||||
account,
|
||||
this.oceanAddress,
|
||||
address,
|
||||
this.web3.utils.toWei(String(oceanAmount)) as any
|
||||
)
|
||||
|
||||
super.setup(
|
||||
account, address,
|
||||
token, String(amount), String(weight),
|
||||
this.oceanAddress, String(oceanAmount), String(oceanWeight),
|
||||
this.web3.utils.toWei(fee)
|
||||
)
|
||||
|
||||
return address
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,50 @@ export class Pool extends PoolFactory {
|
||||
* Creates a new pool
|
||||
*/
|
||||
async createPool(account: string): Promise<string> {
|
||||
const pooladdress = await super.createPool(account)
|
||||
return pooladdress
|
||||
return await super.createPool(account)
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup a new pool by setting datatoken, base token, swap fee and
|
||||
* finalizing the pool to make it public.
|
||||
*
|
||||
* @param account
|
||||
* @param poolAddress
|
||||
* @param dataToken
|
||||
* @param dataTokenAmount
|
||||
* @param dataTokenWeight
|
||||
* @param baseToken
|
||||
* @param baseTokenAmount
|
||||
* @param baseTokenWeight
|
||||
* @param swapFee
|
||||
*/
|
||||
async setup(
|
||||
account: string,
|
||||
poolAddress: string,
|
||||
dataToken: string,
|
||||
dataTokenAmount: string,
|
||||
dataTokenWeight: string,
|
||||
baseToken: string,
|
||||
baseTokenAmount: string,
|
||||
baseTokenWeight: string,
|
||||
swapFee: string,
|
||||
): Promise<string> {
|
||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
|
||||
from: account
|
||||
})
|
||||
let result = null
|
||||
try {
|
||||
result = await pool.methods
|
||||
.setup(
|
||||
dataToken, dataTokenAmount, dataTokenWeight,
|
||||
baseToken, baseTokenAmount, baseTokenWeight,
|
||||
swapFee
|
||||
).send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user