Skip to content

Commit

Permalink
Merge pull request #66 from airswap/fixes-and-upgrade
Browse files Browse the repository at this point in the history
Upgrades latest metadata package, fixes for metadata, better prompts
  • Loading branch information
Don Mosites authored Feb 28, 2020
2 parents 3930f01 + 1a8b745 commit f5d3581
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"bugs": "https://github.com/airswap/airswap-cli/issues",
"dependencies": {
"@airswap/indexer": "3.6.8",
"@airswap/metadata": "0.1.4",
"@airswap/metadata": "0.1.5",
"@airswap/order-utils": "0.3.20",
"@airswap/swap": "5.4.7",
"@airswap/tokens": "0.1.4",
Expand Down
7 changes: 4 additions & 3 deletions src/commands/indexer/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export default class IntentGet extends Command {

const indexerAddress = indexerDeploys[chainId]
this.log(chalk.white(`Indexer ${indexerAddress}\n`))
this.log("As a taker, I intend to:\n")

const { side, first, second, signerToken, senderToken }: any = await getSideAndTokens(metadata)

const indexerContract = new ethers.Contract(indexerAddress, Indexer.abi, provider)
const index = indexerContract.indexes(signerToken.address, senderToken.address, protocol)

if (index === constants.ADDRESS_ZERO) {
this.log(chalk.yellow(`Pair ${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this pair with ${chalk.bold('indexer:new')}\n`)
this.log(chalk.yellow(`${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this index with ${chalk.bold('indexer:new')}\n`)
} else {
const result = await indexerContract.getLocators(
signerToken.address,
Expand All @@ -49,7 +50,7 @@ export default class IntentGet extends Command {

this.log(
chalk.underline.bold(
`\nTop peers ${verb} ${first.name} for ${second.name} (${constants.protocolNames[protocol]})\n`,
`\nTop peers ${verb} ${first.symbol} for ${second.symbol} (${constants.protocolNames[protocol]})\n`,
),
)

Expand Down
4 changes: 2 additions & 2 deletions src/commands/indexer/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default class IntentNew extends Command {

indexerContract.indexes(signerToken.address, senderToken.address, protocol).then(async (index: any) => {
if (index !== constants.ADDRESS_ZERO) {
this.log(`${chalk.yellow('Pair already exists')}`)
this.log(`Set intent on this pair with ${chalk.bold('indexer:set')}\n`)
this.log(`${chalk.yellow('Index already exists')}`)
this.log(`Set intent on this index with ${chalk.bold('indexer:set')}\n`)
} else {
if (
await confirm(
Expand Down
9 changes: 5 additions & 4 deletions src/commands/indexer/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ export default class IntentSet extends Command {
const indexerAddress = indexerDeploys[chainId]
const indexerContract = new ethers.Contract(indexerAddress, Indexer.abi, wallet)
this.log(chalk.white(`Indexer ${indexerAddress}\n`))
this.log("As a maker, I intend to:\n")

const { signerToken, senderToken }: any = await getSideAndTokens(metadata, true)

const values: any = await get({
locator: {
description: 'locator',
description: 'locator (url)',
type: 'Locator',
},
stakeAmount: {
description: 'stakeAmount',
description: 'amount to stake',
type: 'Number',
},
})
Expand All @@ -45,8 +46,8 @@ export default class IntentSet extends Command {

indexerContract.indexes(signerToken.address, senderToken.address, protocol).then(async (index: any) => {
if (index === constants.ADDRESS_ZERO) {
this.log(chalk.yellow(`Pair ${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this pair with ${chalk.bold('indexer:new')}\n`)
this.log(chalk.yellow(`${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this index with ${chalk.bold('indexer:new')}\n`)
} else {
const existingEntry = await new ethers.Contract(index, Index.abi, wallet).getLocator(wallet.address)
if (existingEntry !== constants.LOCATOR_ZERO) {
Expand Down
6 changes: 4 additions & 2 deletions src/commands/indexer/unset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ export default class IntentUnset extends Command {
const indexerAddress = indexerDeploys[chainId]
const indexerContract = new ethers.Contract(indexerAddress, Indexer.abi, wallet)
this.log(chalk.white(`Indexer ${indexerAddress}\n`))
this.log("As a maker, I no longer intend to:\n")

const { signerToken, senderToken }: any = await getSideAndTokens(metadata, true)
this.log()

const index = await indexerContract.indexes(signerToken.address, senderToken.address, protocol)
if (index === constants.ADDRESS_ZERO) {
this.log(chalk.yellow(`Pair ${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this pair with ${chalk.bold('indexer:new')}\n`)
this.log(chalk.yellow(`${signerToken.symbol}/${senderToken.symbol} does not exist`))
this.log(`Create this index with ${chalk.bold('indexer:new')}\n`)
} else {
const existingEntry = await new ethers.Contract(index, Index.abi, wallet).getLocator(wallet.address)
if (existingEntry === constants.LOCATOR_ZERO) {
Expand Down
14 changes: 7 additions & 7 deletions src/commands/quote/max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ export default class QuoteMax extends Command {
const params: any = {}

if (side === 'buy') {
params.signerToken = first.addr
params.senderToken = second.addr
params.signerToken = first.address
params.senderToken = second.address
} else {
params.signerToken = second.addr
params.senderToken = first.addr
params.signerToken = second.address
params.senderToken = first.address
}

this.log()
Expand Down Expand Up @@ -63,9 +63,9 @@ export default class QuoteMax extends Command {
verb = 'Selling'
}
this.log(
`\n${verb} up to ${chalk.bold(maxAmount)} ${chalk.bold(first.name)} for ${chalk.bold(maxFor)} ${chalk.bold(
second.name,
)}\n`,
`\n${verb} up to ${chalk.bold(maxAmount)} ${chalk.bold(first.symbol)} for ${chalk.bold(
maxFor,
)} ${chalk.bold(second.symbol)}\n`,
)
}
})
Expand Down
6 changes: 3 additions & 3 deletions src/commands/weth/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class IntentUnset extends Command {

const WETH = metadata.bySymbol['WETH']
const balance = await wallet.provider.getBalance(wallet.address)
const balanceDecimal = utils.getDecimalValue(balance.toString(), WETH.addr, metadata)
const balanceDecimal = utils.getDecimalValue(balance.toString(), WETH.address, metadata)
this.log(`ETH available to deposit: ${chalk.bold(balanceDecimal.toFixed())}`)
this.log(chalk.gray('Some ETH must be saved to execute the transaction.\n'))

Expand All @@ -28,7 +28,7 @@ export default class IntentUnset extends Command {
type: 'Number',
},
})
const atomicAmount = utils.getAtomicValue(amount, WETH.addr, metadata)
const atomicAmount = utils.getAtomicValue(amount, WETH.address, metadata)

if (atomicAmount.eq(0)) {
cancelled('Amount must be greater than zero.')
Expand All @@ -47,7 +47,7 @@ export default class IntentUnset extends Command {
chainId,
)
) {
new ethers.Contract(WETH.addr, WETH9.abi, wallet)
new ethers.Contract(WETH.address, WETH9.abi, wallet)
.deposit({ value: ethers.utils.bigNumberify(atomicAmount.toFixed()), gasPrice })
.then(utils.handleTransaction)
.catch(utils.handleError)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/weth/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default class IntentUnset extends Command {
utils.displayDescription(this, IntentUnset.description, chainId)

const WETH = metadata.bySymbol['WETH']
const tokenContract = new ethers.Contract(WETH.addr, WETH9.abi, wallet)
const tokenContract = new ethers.Contract(WETH.address, WETH9.abi, wallet)
const tokenBalance = await tokenContract.balanceOf(wallet.address)
const balanceDecimal = utils.getDecimalValue(tokenBalance.toString(), WETH.addr, metadata)
const balanceDecimal = utils.getDecimalValue(tokenBalance.toString(), WETH.address, metadata)
this.log(`WETH available to withdraw: ${chalk.bold(balanceDecimal.toFixed())}\n`)

const { amount }: any = await get({
Expand All @@ -28,7 +28,7 @@ export default class IntentUnset extends Command {
type: 'Number',
},
})
const atomicAmount = utils.getAtomicValue(amount, WETH.addr, metadata)
const atomicAmount = utils.getAtomicValue(amount, WETH.address, metadata)

if (atomicAmount.eq(0)) {
cancelled('Amount must be greater than zero.')
Expand All @@ -47,7 +47,7 @@ export default class IntentUnset extends Command {
chainId,
)
) {
new ethers.Contract(WETH.addr, WETH9.abi, wallet)
new ethers.Contract(WETH.address, WETH9.abi, wallet)
.withdraw(ethers.utils.bigNumberify(atomicAmount.toFixed()), { gasPrice })
.then(utils.handleTransaction)
.catch(utils.handleError)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function getData(metadata: any, params: any) {
const data = [[chalk.bold('Param'), chalk.bold('Value')]]
for (const key in params) {
if (patterns.Address.test(params[key]) && params[key] in metadata.byAddress) {
data.push([key, `${params[key]} (${chalk.cyan(metadata.byAddress[params[key]].name)})`])
data.push([key, `${params[key]} (${chalk.cyan(metadata.byAddress[params[key]].symbol)})`])
} else {
data.push([key, params[key]])
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ export async function getRequest(wallet: any, metadata: any, kind: string) {
}

if (side === 'buy') {
const signerAmountAtomic = utils.getAtomicValue(amount, first.addr, metadata)
const signerAmountAtomic = utils.getAtomicValue(amount, first.address, metadata)
Object.assign(params, {
signerAmount: signerAmountAtomic.integerValue(BigNumber.ROUND_FLOOR).toFixed(),
})
} else {
const senderAmountAtomic = utils.getAtomicValue(amount, first.addr, metadata)
const senderAmountAtomic = utils.getAtomicValue(amount, first.address, metadata)
method = 'getSignerSide' + kind
Object.assign(params, {
senderAmount: senderAmountAtomic.integerValue(BigNumber.ROUND_FLOOR).toFixed(),
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
dependencies:
openzeppelin-solidity "2.4"

"@airswap/[email protected].4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@airswap/metadata/-/metadata-0.1.4.tgz#d11bd2bc9a7f47240963f3b1c6cd59c1f33bbea0"
integrity sha512-QNd+fy3fgeIMdKMOg11/vHWmGscrKdBFipN0FzAbqxAQYoVyjrVRYfVTvuRhGWYWqnQU+VGIzUrLAOX1FIEWxw==
"@airswap/[email protected].5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@airswap/metadata/-/metadata-0.1.5.tgz#ad53acf30262485aa36cb7d2a20743041a2423a0"
integrity sha512-qjCiaom2GApVBQp9OUU7H+/rrCkKTfZ1EwSHHU0pc1kEYZ8zEVbEekh+iKCQmvjqmhQDhamPH/uP15up7+oQdw==
dependencies:
"@airswap/constants" "0.3.3"
"@airswap/types" "3.5.9"
Expand Down

0 comments on commit f5d3581

Please sign in to comment.