mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
update transfer and approve methods
This commit is contained in:
parent
6b0a47204c
commit
470eff51ad
@ -9,6 +9,8 @@ import {
|
|||||||
minAbi,
|
minAbi,
|
||||||
sendTx
|
sendTx
|
||||||
} from '.'
|
} from '.'
|
||||||
|
import { config } from 'process'
|
||||||
|
import { Config } from '../config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approve spender to spent amount tokens
|
* Approve spender to spent amount tokens
|
||||||
@ -21,6 +23,7 @@ import {
|
|||||||
*/
|
*/
|
||||||
export async function approve<G extends boolean = false>(
|
export async function approve<G extends boolean = false>(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
config: Config,
|
||||||
account: string,
|
account: string,
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
spender: string,
|
spender: string,
|
||||||
@ -48,7 +51,8 @@ export async function approve<G extends boolean = false>(
|
|||||||
const trxReceipt = await sendTx(
|
const trxReceipt = await sendTx(
|
||||||
account,
|
account,
|
||||||
estGas + 1,
|
estGas + 1,
|
||||||
this.web3,
|
web3,
|
||||||
|
config,
|
||||||
tokenContract.methods.approve,
|
tokenContract.methods.approve,
|
||||||
spender,
|
spender,
|
||||||
amountFormatted
|
amountFormatted
|
||||||
@ -66,6 +70,7 @@ export async function approve<G extends boolean = false>(
|
|||||||
*/
|
*/
|
||||||
export async function transfer<G extends boolean = false>(
|
export async function transfer<G extends boolean = false>(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
config: Config,
|
||||||
account: string,
|
account: string,
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
recipient: string,
|
recipient: string,
|
||||||
@ -86,7 +91,8 @@ export async function transfer<G extends boolean = false>(
|
|||||||
const trxReceipt = await sendTx(
|
const trxReceipt = await sendTx(
|
||||||
account,
|
account,
|
||||||
estGas + 1,
|
estGas + 1,
|
||||||
this.web3,
|
web3,
|
||||||
|
config,
|
||||||
tokenContract.methods.transfer,
|
tokenContract.methods.transfer,
|
||||||
recipient,
|
recipient,
|
||||||
amountFormatted
|
amountFormatted
|
||||||
|
@ -230,8 +230,8 @@ describe('Marketplace flow tests', async () => {
|
|||||||
|
|
||||||
it('5.3 We send some OCEAN to consumer and staker accounts', async () => {
|
it('5.3 We send some OCEAN to consumer and staker accounts', async () => {
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
transfer(web3, publisherAccount, addresses.Ocean, consumerAccount, '100')
|
transfer(web3, config, publisherAccount, addresses.Ocean, consumerAccount, '100')
|
||||||
transfer(web3, publisherAccount, addresses.Ocean, stakerAccount, '100')
|
transfer(web3, config, publisherAccount, addresses.Ocean, stakerAccount, '100')
|
||||||
}) ///
|
}) ///
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
@ -282,6 +282,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
addresses.Ocean,
|
addresses.Ocean,
|
||||||
addresses.ERC721Factory,
|
addresses.ERC721Factory,
|
||||||
@ -313,6 +314,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
it('6.2 Set metadata in the pool NFT', async () => {
|
it('6.2 Set metadata in the pool NFT', async () => {
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
const nft = new Nft(web3)
|
const nft = new Nft(web3)
|
||||||
|
|
||||||
/// ```
|
/// ```
|
||||||
/// Now we update the ddo and set the right did
|
/// Now we update the ddo and set the right did
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
@ -355,7 +357,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```
|
/// ```
|
||||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
await approve(web3, stakerAccount, addresses.Ocean, poolAddress, '5', true)
|
await approve(web3, config, stakerAccount, addresses.Ocean, poolAddress, '5', true)
|
||||||
|
|
||||||
/// ```
|
/// ```
|
||||||
/// Now we can make the contract call
|
/// Now we can make the contract call
|
||||||
@ -404,7 +406,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```
|
/// ```
|
||||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
await approve(web3, consumerAccount, addresses.Ocean, poolAddress, '100')
|
await approve(web3, config, consumerAccount, addresses.Ocean, poolAddress, '100')
|
||||||
|
|
||||||
const pool = new Pool(web3)
|
const pool = new Pool(web3)
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
@ -646,9 +648,10 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```
|
/// ```
|
||||||
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
/// Before we call the contract we have to call `approve` so that the contract can move our tokens. This is standard when using any ERC20 Datatokens
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
await approve(web3, consumerAccount, addresses.Ocean, freAddress, '100')
|
await approve(web3, config, consumerAccount, addresses.Ocean, freAddress, '100')
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
freDatatokenAddress,
|
freDatatokenAddress,
|
||||||
freAddress,
|
freAddress,
|
||||||
|
@ -88,6 +88,7 @@ describe('Publish tests', async () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
addresses.MockDAI,
|
addresses.MockDAI,
|
||||||
addresses.ERC721Factory,
|
addresses.ERC721Factory,
|
||||||
|
@ -2,7 +2,7 @@ import { assert, expect } from 'chai'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { deployContracts, Addresses } from '../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import { web3 } from '../../config'
|
import { getTestConfig, web3 } from '../../config'
|
||||||
import {
|
import {
|
||||||
NftFactory,
|
NftFactory,
|
||||||
NftCreateData,
|
NftCreateData,
|
||||||
@ -11,7 +11,8 @@ import {
|
|||||||
signHash,
|
signHash,
|
||||||
Nft,
|
Nft,
|
||||||
transfer,
|
transfer,
|
||||||
approve
|
approve,
|
||||||
|
Config
|
||||||
} from '../../../src'
|
} from '../../../src'
|
||||||
import {
|
import {
|
||||||
ProviderFees,
|
ProviderFees,
|
||||||
@ -30,6 +31,7 @@ describe('Nft Factory test', () => {
|
|||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtAddress2: string
|
let dtAddress2: string
|
||||||
let nftAddress: string
|
let nftAddress: string
|
||||||
|
let config: Config
|
||||||
|
|
||||||
const DATA_TOKEN_AMOUNT = web3.utils.toWei('1')
|
const DATA_TOKEN_AMOUNT = web3.utils.toWei('1')
|
||||||
const FEE = '0.001'
|
const FEE = '0.001'
|
||||||
@ -66,6 +68,8 @@ describe('Nft Factory test', () => {
|
|||||||
dtParams.minter = nftOwner
|
dtParams.minter = nftOwner
|
||||||
dtParams.paymentCollector = user2
|
dtParams.paymentCollector = user2
|
||||||
dtParams.mpFeeAddress = user1
|
dtParams.mpFeeAddress = user1
|
||||||
|
|
||||||
|
config = await getTestConfig(web3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
@ -146,6 +150,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
await transfer(
|
await transfer(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
@ -154,6 +159,7 @@ describe('Nft Factory test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
nftOwner,
|
nftOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
|
@ -2,14 +2,15 @@ import { assert, expect } from 'chai'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { deployContracts, Addresses } from '../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../TestContractHandler'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
import { web3 } from '../../config'
|
import { getTestConfig, web3 } from '../../config'
|
||||||
import {
|
import {
|
||||||
NftFactory,
|
NftFactory,
|
||||||
NftCreateData,
|
NftCreateData,
|
||||||
Router,
|
Router,
|
||||||
balance,
|
balance,
|
||||||
approve,
|
approve,
|
||||||
ZERO_ADDRESS
|
ZERO_ADDRESS,
|
||||||
|
Config
|
||||||
} from '../../../src'
|
} from '../../../src'
|
||||||
import { DatatokenCreateParams, PoolCreationParams, Operation } from '../../../src/@types'
|
import { DatatokenCreateParams, PoolCreationParams, Operation } from '../../../src/@types'
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ describe('Router unit test', () => {
|
|||||||
let user2: string
|
let user2: string
|
||||||
let contracts: Addresses
|
let contracts: Addresses
|
||||||
let router: Router
|
let router: Router
|
||||||
|
let config: Config
|
||||||
|
|
||||||
const NFT_NAME = '72120Bundle'
|
const NFT_NAME = '72120Bundle'
|
||||||
const NFT_SYMBOL = '72Bundle'
|
const NFT_SYMBOL = '72Bundle'
|
||||||
@ -73,6 +75,8 @@ describe('Router unit test', () => {
|
|||||||
ERC_PARAMS.minter = factoryOwner
|
ERC_PARAMS.minter = factoryOwner
|
||||||
ERC_PARAMS.paymentCollector = user2
|
ERC_PARAMS.paymentCollector = user2
|
||||||
ERC_PARAMS.mpFeeAddress = factoryOwner
|
ERC_PARAMS.mpFeeAddress = factoryOwner
|
||||||
|
|
||||||
|
config = await getTestConfig(web3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
@ -80,6 +84,7 @@ describe('Router unit test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
@ -132,7 +137,14 @@ describe('Router unit test', () => {
|
|||||||
.transfer(user1, web3.utils.toWei(DAI_AMOUNT))
|
.transfer(user1, web3.utils.toWei(DAI_AMOUNT))
|
||||||
.send({ from: factoryOwner })
|
.send({ from: factoryOwner })
|
||||||
|
|
||||||
await approve(web3, user1, contracts.daiAddress, contracts.routerAddress, DAI_AMOUNT)
|
await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
user1,
|
||||||
|
contracts.daiAddress,
|
||||||
|
contracts.routerAddress,
|
||||||
|
DAI_AMOUNT
|
||||||
|
)
|
||||||
|
|
||||||
// CREATE A FIRST POOL
|
// CREATE A FIRST POOL
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { getTestConfig, web3 } from '../../../config'
|
||||||
import {
|
import {
|
||||||
allowance,
|
allowance,
|
||||||
approve,
|
approve,
|
||||||
@ -11,7 +11,8 @@ import {
|
|||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
balance,
|
balance,
|
||||||
transfer,
|
transfer,
|
||||||
decimals
|
decimals,
|
||||||
|
Config
|
||||||
} from '../../../../src'
|
} from '../../../../src'
|
||||||
import {
|
import {
|
||||||
PoolCreationParams,
|
PoolCreationParams,
|
||||||
@ -31,6 +32,7 @@ describe('Pool unit test', () => {
|
|||||||
let poolAddress: string
|
let poolAddress: string
|
||||||
let datatoken: string
|
let datatoken: string
|
||||||
let dtParams: DatatokenCreateParams
|
let dtParams: DatatokenCreateParams
|
||||||
|
let config: Config
|
||||||
|
|
||||||
const nftData: NftCreateData = {
|
const nftData: NftCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
@ -49,6 +51,8 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
nftData.owner = factoryOwner
|
nftData.owner = factoryOwner
|
||||||
|
|
||||||
|
config = await getTestConfig(web3)
|
||||||
|
|
||||||
dtParams = {
|
dtParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: factoryOwner,
|
minter: factoryOwner,
|
||||||
@ -71,6 +75,7 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
@ -90,6 +95,7 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
@ -224,11 +230,11 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
await transfer(web3, factoryOwner, contracts.daiAddress, user1, '1000')
|
await transfer(web3, config, factoryOwner, contracts.daiAddress, user1, '1000')
|
||||||
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('1000')
|
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('1000')
|
||||||
|
|
||||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '10')
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '10')
|
||||||
|
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
@ -256,7 +262,7 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '100')
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '100')
|
||||||
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('990')
|
expect(await balance(web3, contracts.daiAddress, user1)).to.equal('990')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
@ -280,7 +286,7 @@ describe('Pool unit test', () => {
|
|||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
||||||
const daiAmountIn = '100'
|
const daiAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '100', true)
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '100', true)
|
||||||
expect(await allowance(web3, contracts.daiAddress, user1, poolAddress)).to.equal(
|
expect(await allowance(web3, contracts.daiAddress, user1, poolAddress)).to.equal(
|
||||||
'100'
|
'100'
|
||||||
)
|
)
|
||||||
@ -682,11 +688,11 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
await transfer(web3, factoryOwner, contracts.usdcAddress, user1, '1000')
|
await transfer(web3, config, factoryOwner, contracts.usdcAddress, user1, '1000')
|
||||||
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('1000')
|
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('1000')
|
||||||
|
|
||||||
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
expect(await balance(web3, datatoken, user1)).to.equal('0')
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '10')
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '10')
|
||||||
|
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
@ -714,7 +720,7 @@ describe('Pool unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100')
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '100')
|
||||||
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('990')
|
expect(await balance(web3, contracts.usdcAddress, user1)).to.equal('990')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
@ -739,7 +745,7 @@ describe('Pool unit test', () => {
|
|||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
||||||
const usdcAmountIn = '100'
|
const usdcAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100', true)
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '100', true)
|
||||||
|
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user1,
|
user1,
|
||||||
|
@ -4,7 +4,7 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3, getTestConfig } from '../../../config'
|
||||||
import {
|
import {
|
||||||
NftFactory,
|
NftFactory,
|
||||||
NftCreateData,
|
NftCreateData,
|
||||||
@ -13,7 +13,8 @@ import {
|
|||||||
approve,
|
approve,
|
||||||
transfer,
|
transfer,
|
||||||
balance,
|
balance,
|
||||||
unitsToAmount
|
unitsToAmount,
|
||||||
|
Config
|
||||||
} from '../../../../src'
|
} from '../../../../src'
|
||||||
import { FreCreationParams, DatatokenCreateParams } from '../../../../src/@types'
|
import { FreCreationParams, DatatokenCreateParams } from '../../../../src/@types'
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
let fixedRate: FixedRateExchange
|
let fixedRate: FixedRateExchange
|
||||||
let dtAddress: string
|
let dtAddress: string
|
||||||
let dtContract: Contract
|
let dtContract: Contract
|
||||||
|
let config: Config
|
||||||
|
|
||||||
const nftData: NftCreateData = {
|
const nftData: NftCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
@ -60,6 +62,8 @@ describe('Fixed Rate unit test', () => {
|
|||||||
dtParams.minter = factoryOwner
|
dtParams.minter = factoryOwner
|
||||||
dtParams.paymentCollector = user2
|
dtParams.paymentCollector = user2
|
||||||
dtParams.mpFeeAddress = factoryOwner
|
dtParams.mpFeeAddress = factoryOwner
|
||||||
|
|
||||||
|
config = await getTestConfig(web3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
@ -197,10 +201,24 @@ describe('Fixed Rate unit test', () => {
|
|||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
||||||
.send({ from: exchangeOwner })
|
.send({ from: exchangeOwner })
|
||||||
await approve(web3, exchangeOwner, dtAddress, contracts.fixedRateAddress, '1000')
|
await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
exchangeOwner,
|
||||||
|
dtAddress,
|
||||||
|
contracts.fixedRateAddress,
|
||||||
|
'1000'
|
||||||
|
)
|
||||||
// user1 gets 100 DAI so he can buy DTs
|
// user1 gets 100 DAI so he can buy DTs
|
||||||
await transfer(web3, exchangeOwner, contracts.daiAddress, user1, '100')
|
await transfer(web3, config, exchangeOwner, contracts.daiAddress, user1, '100')
|
||||||
await approve(web3, user1, contracts.daiAddress, contracts.fixedRateAddress, '100')
|
await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
user1,
|
||||||
|
contracts.daiAddress,
|
||||||
|
contracts.fixedRateAddress,
|
||||||
|
'100'
|
||||||
|
)
|
||||||
|
|
||||||
// user1 has no dts but has 100 DAI
|
// user1 has no dts but has 100 DAI
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
@ -236,7 +254,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#sellDatatokens - user1 should sell some dt', async () => {
|
it('#sellDatatokens - user1 should sell some dt', async () => {
|
||||||
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '100')
|
await approve(web3, config, user1, dtAddress, contracts.fixedRateAddress, '100')
|
||||||
const daiBalanceBefore = new BigNumber(
|
const daiBalanceBefore = new BigNumber(
|
||||||
await balance(web3, contracts.daiAddress, user1)
|
await balance(web3, contracts.daiAddress, user1)
|
||||||
)
|
)
|
||||||
@ -506,10 +524,24 @@ describe('Fixed Rate unit test', () => {
|
|||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
||||||
.send({ from: exchangeOwner })
|
.send({ from: exchangeOwner })
|
||||||
await approve(web3, exchangeOwner, dtAddress, contracts.fixedRateAddress, '1000')
|
await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
exchangeOwner,
|
||||||
|
dtAddress,
|
||||||
|
contracts.fixedRateAddress,
|
||||||
|
'1000'
|
||||||
|
)
|
||||||
// user1 gets 100 USDC so he can buy DTs
|
// user1 gets 100 USDC so he can buy DTs
|
||||||
await transfer(web3, exchangeOwner, contracts.usdcAddress, user1, '100')
|
await transfer(web3, config, exchangeOwner, contracts.usdcAddress, user1, '100')
|
||||||
await approve(web3, user1, contracts.usdcAddress, contracts.fixedRateAddress, '100')
|
await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
user1,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
contracts.fixedRateAddress,
|
||||||
|
'100'
|
||||||
|
)
|
||||||
|
|
||||||
// user1 has no dts but has 100 USDC
|
// user1 has no dts but has 100 USDC
|
||||||
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
expect(await balance(web3, dtAddress, user1)).to.equal('0')
|
||||||
@ -549,7 +581,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#sellDatatokens - user1 should sell some dt', async () => {
|
it('#sellDatatokens - user1 should sell some dt', async () => {
|
||||||
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '10')
|
await approve(web3, config, user1, dtAddress, contracts.fixedRateAddress, '10')
|
||||||
const usdcBalanceBefore = new BigNumber(
|
const usdcBalanceBefore = new BigNumber(
|
||||||
await balance(web3, contracts.usdcAddress, user1)
|
await balance(web3, contracts.usdcAddress, user1)
|
||||||
)
|
)
|
||||||
|
@ -5,7 +5,7 @@ import BigNumber from 'bignumber.js'
|
|||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { getTestConfig, web3 } from '../../../config'
|
||||||
import {
|
import {
|
||||||
allowance,
|
allowance,
|
||||||
amountToUnits,
|
amountToUnits,
|
||||||
@ -15,7 +15,8 @@ import {
|
|||||||
Pool,
|
Pool,
|
||||||
SideStaking,
|
SideStaking,
|
||||||
unitsToAmount,
|
unitsToAmount,
|
||||||
ZERO_ADDRESS
|
ZERO_ADDRESS,
|
||||||
|
Config
|
||||||
} from '../../../../src'
|
} from '../../../../src'
|
||||||
import {
|
import {
|
||||||
DatatokenCreateParams,
|
DatatokenCreateParams,
|
||||||
@ -38,6 +39,7 @@ describe('SideStaking unit test', () => {
|
|||||||
let datatokenContract: Contract
|
let datatokenContract: Contract
|
||||||
let daiContract: Contract
|
let daiContract: Contract
|
||||||
let usdcContract: Contract
|
let usdcContract: Contract
|
||||||
|
let config: Config
|
||||||
|
|
||||||
const VESTED_BLOCKS = 2500000
|
const VESTED_BLOCKS = 2500000
|
||||||
const VESTING_AMOUNT = '10000'
|
const VESTING_AMOUNT = '10000'
|
||||||
@ -74,6 +76,8 @@ describe('SideStaking unit test', () => {
|
|||||||
dtParams.minter = factoryOwner
|
dtParams.minter = factoryOwner
|
||||||
dtParams.paymentCollector = user2
|
dtParams.paymentCollector = user2
|
||||||
dtParams.mpFeeAddress = factoryOwner
|
dtParams.mpFeeAddress = factoryOwner
|
||||||
|
|
||||||
|
config = await getTestConfig(web3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
it('should deploy contracts', async () => {
|
||||||
@ -94,6 +98,7 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
@ -113,6 +118,7 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
await approve(
|
await approve(
|
||||||
web3,
|
web3,
|
||||||
|
config,
|
||||||
factoryOwner,
|
factoryOwner,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
contracts.nftFactoryAddress,
|
contracts.nftFactoryAddress,
|
||||||
@ -254,7 +260,7 @@ describe('SideStaking unit test', () => {
|
|||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.transfer(user1, web3.utils.toWei('1000'))
|
.transfer(user1, web3.utils.toWei('1000'))
|
||||||
.send({ from: factoryOwner })
|
.send({ from: factoryOwner })
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '10')
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '10')
|
||||||
|
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
@ -281,7 +287,7 @@ describe('SideStaking unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '100')
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '100')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: datatoken,
|
tokenOut: datatoken,
|
||||||
@ -304,7 +310,7 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
||||||
const daiAmountIn = '100'
|
const daiAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user1, contracts.daiAddress, poolAddress, '100', true)
|
await approve(web3, config, user1, contracts.daiAddress, poolAddress, '100', true)
|
||||||
expect(await allowance(web3, contracts.daiAddress, user1, poolAddress)).to.equal(
|
expect(await allowance(web3, contracts.daiAddress, user1, poolAddress)).to.equal(
|
||||||
'100'
|
'100'
|
||||||
)
|
)
|
||||||
@ -436,7 +442,7 @@ describe('SideStaking unit test', () => {
|
|||||||
.transfer(user1, transferAmount)
|
.transfer(user1, transferAmount)
|
||||||
.send({ from: factoryOwner })
|
.send({ from: factoryOwner })
|
||||||
|
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '10')
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '10')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: datatoken,
|
tokenOut: datatoken,
|
||||||
@ -459,7 +465,7 @@ describe('SideStaking unit test', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100')
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '100')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: datatoken,
|
tokenOut: datatoken,
|
||||||
@ -482,7 +488,7 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
||||||
const usdcAmountIn = '100'
|
const usdcAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100', true)
|
await approve(web3, config, user1, contracts.usdcAddress, poolAddress, '100', true)
|
||||||
|
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user1,
|
user1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user