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
@ -29,6 +29,7 @@ export class OceanPool extends Pool {
|
|||||||
* @param {String} token DataToken address
|
* @param {String} token DataToken address
|
||||||
* @param {String} amount DataToken amount
|
* @param {String} amount DataToken amount
|
||||||
* @param {String} weight DataToken weight
|
* @param {String} weight DataToken weight
|
||||||
|
* @param {String} fee Swap fee in Wei
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
public async createDTPool(
|
public async createDTPool(
|
||||||
@ -37,7 +38,6 @@ export class OceanPool extends Pool {
|
|||||||
amount: string,
|
amount: string,
|
||||||
weight: string,
|
weight: string,
|
||||||
fee: string,
|
fee: string,
|
||||||
finalize = true
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('oceanAddress is not defined')
|
console.error('oceanAddress is not defined')
|
||||||
@ -50,22 +50,28 @@ export class OceanPool extends Pool {
|
|||||||
const address = await super.createPool(account)
|
const address = await super.createPool(account)
|
||||||
const oceanWeight = 10 - parseFloat(weight)
|
const oceanWeight = 10 - parseFloat(weight)
|
||||||
const oceanAmount = (parseFloat(amount) * oceanWeight) / 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
|
this.dtAddress = token
|
||||||
await super.addToPool(account, address, tokens)
|
|
||||||
await super.setSwapFee(account, address, fee)
|
await this.approve(
|
||||||
if (finalize) await super.finalize(account, address)
|
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
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,50 @@ export class Pool extends PoolFactory {
|
|||||||
* Creates a new pool
|
* Creates a new pool
|
||||||
*/
|
*/
|
||||||
async createPool(account: string): Promise<string> {
|
async createPool(account: string): Promise<string> {
|
||||||
const pooladdress = await super.createPool(account)
|
return await super.createPool(account)
|
||||||
return pooladdress
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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