mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add interface for PoolLogs & Actions
This commit is contained in:
parent
43dee2fca7
commit
ee53e5f41a
@ -8,6 +8,22 @@ export interface PoolDetails {
|
|||||||
tokens: string[]
|
tokens: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PoolAction {
|
||||||
|
poolAddress: string
|
||||||
|
caller: string
|
||||||
|
transactionHash: string
|
||||||
|
blockNumber: number
|
||||||
|
tokenIn?: string
|
||||||
|
tokenOut?: string
|
||||||
|
tokenAmountIn?: string
|
||||||
|
tokenAmountOut?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PoolLogs {
|
||||||
|
joins?: PoolAction[]
|
||||||
|
exists?: PoolAction[]
|
||||||
|
swaps?: PoolAction[]
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Ocean Pools submodule exposed under ocean.pool
|
* Ocean Pools submodule exposed under ocean.pool
|
||||||
*/
|
*/
|
||||||
@ -423,7 +439,7 @@ export class OceanPool extends Pool {
|
|||||||
* @param {Boolean} swaps Include swaps
|
* @param {Boolean} swaps Include swaps
|
||||||
* @param {Boolean} joins Include joins
|
* @param {Boolean} joins Include joins
|
||||||
* @param {Boolean} exists Include exits
|
* @param {Boolean} exists Include exits
|
||||||
* @return {String[]}
|
* @return {PoolLogs[]}
|
||||||
*/
|
*/
|
||||||
public async getPoolLogs(
|
public async getPoolLogs(
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
@ -431,8 +447,8 @@ export class OceanPool extends Pool {
|
|||||||
swaps?: boolean,
|
swaps?: boolean,
|
||||||
joins?: boolean,
|
joins?: boolean,
|
||||||
exits?: boolean
|
exits?: boolean
|
||||||
): Promise<string[]> {
|
): Promise<PoolLogs> {
|
||||||
const results = []
|
const results: PoolLogs = { joins: [], exists: [], swaps: [] }
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
|
||||||
from: account
|
from: account
|
||||||
})
|
})
|
||||||
@ -449,10 +465,10 @@ export class OceanPool extends Pool {
|
|||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[0] === account) {
|
if (events[i].returnValues[0] === account) {
|
||||||
results.push(this.getEventData('swap', poolAddress, events[i]))
|
results.swaps.push(this.getEventData('swap', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
results.push(this.getEventData('swap', poolAddress, events[i]))
|
results.swaps.push(this.getEventData('swap', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -465,10 +481,10 @@ export class OceanPool extends Pool {
|
|||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[0] === account) {
|
if (events[i].returnValues[0] === account) {
|
||||||
results.push(this.getEventData('join', poolAddress, events[i]))
|
results.joins.push(this.getEventData('join', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
results.push(this.getEventData('join', poolAddress, events[i]))
|
results.joins.push(this.getEventData('join', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -481,10 +497,10 @@ export class OceanPool extends Pool {
|
|||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[0] === account) {
|
if (events[i].returnValues[0] === account) {
|
||||||
results.push(this.getEventData('exit', poolAddress, events[i]))
|
results.exists.push(this.getEventData('exit', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
results.push(this.getEventData('exit', poolAddress, events[i]))
|
results.exists.push(this.getEventData('exit', poolAddress, events[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -497,15 +513,15 @@ export class OceanPool extends Pool {
|
|||||||
* @param {Boolean} swaps Include swaps
|
* @param {Boolean} swaps Include swaps
|
||||||
* @param {Boolean} joins Include joins
|
* @param {Boolean} joins Include joins
|
||||||
* @param {Boolean} exists Include exits
|
* @param {Boolean} exists Include exits
|
||||||
* @return {String[]}
|
* @return {PoolLogs}
|
||||||
*/
|
*/
|
||||||
public async getAllPoolLogs(
|
public async getAllPoolLogs(
|
||||||
account: string,
|
account: string,
|
||||||
swaps?: boolean,
|
swaps?: boolean,
|
||||||
joins?: boolean,
|
joins?: boolean,
|
||||||
exits?: boolean
|
exits?: boolean
|
||||||
): Promise<any> {
|
): Promise<PoolLogs> {
|
||||||
const results = []
|
const results: PoolLogs = { joins: [], exists: [], swaps: [] }
|
||||||
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
|
||||||
from: account
|
from: account
|
||||||
})
|
})
|
||||||
@ -515,14 +531,27 @@ export class OceanPool extends Pool {
|
|||||||
toBlock: 'latest'
|
toBlock: 'latest'
|
||||||
})
|
})
|
||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
results.push(
|
const logs = await this.getPoolLogs(
|
||||||
await this.getPoolLogs(events[i].returnValues[0], account, swaps, joins, exits)
|
events[i].returnValues[0],
|
||||||
|
account,
|
||||||
|
swaps,
|
||||||
|
joins,
|
||||||
|
exits
|
||||||
)
|
)
|
||||||
|
logs.joins.forEach((log) => {
|
||||||
|
results.joins.push(log)
|
||||||
|
})
|
||||||
|
logs.exists.forEach((log) => {
|
||||||
|
results.exists.push(log)
|
||||||
|
})
|
||||||
|
logs.swaps.forEach((log) => {
|
||||||
|
results.swaps.push(log)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEventData(action: string, poolAddress: string, data: any) {
|
private getEventData(action: string, poolAddress: string, data: any): PoolAction {
|
||||||
const result = Object()
|
const result = Object()
|
||||||
result.action = action
|
result.action = action
|
||||||
result.poolAddress = poolAddress
|
result.poolAddress = poolAddress
|
||||||
|
@ -429,8 +429,8 @@ export class OceanFixedRateExchange {
|
|||||||
)
|
)
|
||||||
swaps.forEach((swap) => {
|
swaps.forEach((swap) => {
|
||||||
result.push(swap)
|
result.push(swap)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,10 +278,10 @@ describe('Balancer flow', () => {
|
|||||||
|
|
||||||
it('ALice should get the logs for her pool', async () => {
|
it('ALice should get the logs for her pool', async () => {
|
||||||
const poolLogs = await Pool.getPoolLogs(greatPool, null, true, true, true)
|
const poolLogs = await Pool.getPoolLogs(greatPool, null, true, true, true)
|
||||||
assert(poolLogs.length > 0)
|
assert(poolLogs.joins.length > 0)
|
||||||
})
|
})
|
||||||
it('Bob should get the logs for all his activities', async () => {
|
it('Bob should get the logs for all his activities', async () => {
|
||||||
const poolLogs = await Pool.getAllPoolLogs(bob, true, true, true)
|
const poolLogs = await Pool.getAllPoolLogs(bob, true, true, true)
|
||||||
assert(poolLogs.length > 0)
|
assert(poolLogs.swaps.length > 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user