Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
differentiate --require & --get
Browse files Browse the repository at this point in the history
  • Loading branch information
desaperados committed May 8, 2019
1 parent d7561dd commit a8bfd02
Show file tree
Hide file tree
Showing 27 changed files with 92 additions and 80 deletions.
5 changes: 5 additions & 0 deletions libexec/mcd/mcd---get-from
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -e
fail=$1
mcd --require-from $fail
echo $(seth --to-address $ETH_FROM)
4 changes: 4 additions & 0 deletions libexec/mcd/mcd---get-ilk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e
mcd --require-ilk
echo $(seth --to-bytes32 $(seth --from-ascii "$MCD_ILK"))
6 changes: 6 additions & 0 deletions libexec/mcd/mcd---get-urn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e
fail=$1
mcd --require-urn $fail
export MCD_URN=${MCD_URN:-$ETH_FROM}
seth --to-address $MCD_URN
1 change: 0 additions & 1 deletion libexec/mcd/mcd---require-from
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env bash
set -e
[ -n "$ETH_FROM" ] || mcd --fail "$1: ETH_FROM not set; transact from which account?"
echo $(seth --to-address $ETH_FROM)
49 changes: 47 additions & 2 deletions libexec/mcd/mcd---require-ilk
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
#!/usr/bin/env bash
set -e
mcd---require-ilk-opt
echo $(seth --to-bytes32 $(seth --from-ascii "$MCD_ILK"))

missing-deployment() {
cat <<.
Please specify which mcd deployment you wish to target:
For example, try running against the latest kovan
deployment by settig the chain option:
mcd --chain=kovan <command>
You could also try running against a remote testnet:
List available testnets with: \`mcd testnet chains'
and then set the chain option to a testnet id:
mcd --chain=12899149080555595289 <command>
You can also specify a path to a custom address config
file when runing against deployments on a local testnet:
mcd --config=path/to/out.addresses.json <command>
For more options see \`mcd help'.
.
}

[ -n "$MCD_VAT" ] || missing-deployment

missing-ilk() {
cat >&2 <<.
Error: missing Ilk identifier
You must specify an Ilk (collateral type) using the --ilk=<id> option.
See \`mcd ilks' for a list of approved collateral types.
.
exit 1
}

invalid-ilk() {
cat >&2 <<.
Error: invalid Ilk identifier
The Ilk identifier $MCD_ILK is not a recognised collateral type.
See \`mcd ilks' for a list of approved collateral types.
.
exit 1
}

valid-ilks() {
echo $(mcd ilks | cut -d ' ' -f 1)
}

[ -n "$MCD_ILK" ] || missing-ilk

valid-ilks | grep -qE "\s$MCD_ILK\s|\s$MCD_ILK$" || invalid-ilk
49 changes: 0 additions & 49 deletions libexec/mcd/mcd---require-ilk-opt

This file was deleted.

1 change: 0 additions & 1 deletion libexec/mcd/mcd---require-urn
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
set -e
urn=${MCD_URN:-$ETH_FROM}
[[ -n "$urn" ]] || mcd --fail "$1: ETH_FROM or --urn=<address> is required"
echo $(seth --to-address $urn)
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-bite
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ set -e

export ETH_GAS=${ETH_GAS:-250000}

ilk=$(mcd --require-ilk)
urn=$(mcd --require-urn $0)
ilk=$(mcd --get-ilk)
urn=$(mcd --get-urn $0)

p() { printf "%-3s %-50s %-10s\n" "$1" "$2" "$3"; }

Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-cdp-open
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
ilk=$(mcd --require-ilk)
ilk=$(mcd --get-ilk)

export SETH_ASYNC=yes
export ETH_GAS=${ETH_GAS:-250000}
Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-dai
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
set -e

mcd-dai-cmd() {
mcd --require-urn $0 &>/dev/null
mcd --require-urn
exec 5< <(mcd dai $1 vat)
exec 6< <(mcd dai $1 ext)
echo "vat $(cat <&5) Vat Dai $1"
Expand All @@ -23,7 +23,7 @@ case $1 in
balance) {
case $2 in
vat) {
urn=$(mcd --require-urn $0)
urn=$(mcd --get-urn $0)
sig="dai(address)(uint256)"
mcd --to-rad $(seth call ${MCD_VAT?} $sig $urn)
};;
Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-dai-exit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
[ -n "$1" ] || mcd --fail "mcd-dai: Please specify an exit amount"
urn=$(mcd --require-urn dai)
urn=$(mcd --get-urn dai)
usr=$(mcd --to-address ${2:-$urn})

hope() {
Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-dai-join
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

mcd --dai-approve $MCD_JOIN_DAI

urn=$(mcd --require-urn dai)
urn=$(mcd --get-urn dai)
wad=$(seth --to-uint256 $(seth --to-wei $1 eth))
seth send "$MCD_JOIN_DAI" "join(address, uint)" $urn $wad

Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-draw
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
mcd --require-ilk-opt
mcd --require-ilk
rate=$(mcd ilk rate)
wad=$(bc <<< "scale=18; $1 / $rate")
mcd frob 0 $wad
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-drip
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
### mcd-drip -- Trigger stability fee accumulation
### Usage: mcd drip --ilk=<id>
set -e
ilk=$(mcd --require-ilk)
ilk=$(mcd --get-ilk)
seth send "${MCD_JUG?}" "drip(bytes32)" "$ilk"
4 changes: 3 additions & 1 deletion libexec/mcd/mcd-flips-kick
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
set -e
p() { printf "%-3s %-50s %-10s\n" "$1" "$2" "$3"; }

export ETH_GAS=${ETH_GAS:-250000}

sig="flip(uint256,uint256)(uint256)"
tx=$(seth send --async -G 200000 "${MCD_CAT?}" $sig "$1" "$2")
tx=$(seth send --async "${MCD_CAT?}" $sig "$1" "$2")
echo >&2 -n "${0##*/}: Waiting for transaction receipt..."
block=$(SETH_TICK=true seth receipt "$tx" blockNumber)
block=$(seth --to-hex "$block")
Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-frob
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
set -e
[ $# = 2 ] || mcd --fail "$0: Incorrect arguments"

ilk=$(mcd --require-ilk)
urn=$(mcd --require-urn $0)
ilk=$(mcd --get-ilk)
urn=$(mcd --get-urn $0)

dink=$(seth --to-uint256 $(mcd --to-hex $(seth --to-wei "$1 eth")))
dart=$(seth --to-uint256 $(mcd --to-hex $(seth --to-wei "$2 eth")))
Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-gem
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(mcd gem help)
}

if [[ -n "$1" ]] && [[ "$1" != "help" ]]; then
mcd---require-ilk-opt
mcd --require-ilk
fi

case $1 in
Expand All @@ -41,7 +41,7 @@ case $1 in
mcd-gem-balance $2;
;;
supply)
ilk=$(mcd --require-ilk)
ilk=$(mcd --get-ilk)
case $2 in
mcd) { mcd gem-supply; };;
ext) { mcd gem-supply-ext; };;
Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-gem-balance
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
ilk=$(mcd---require-ilk)
urn=$(mcd --require-urn gem)
ilk=$(mcd --get-ilk)
urn=$(mcd --get-urn gem)
gem=$(mcd gem symbol)
case $1 in
vat) {
Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-gem-exit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
[ -n "$1" ] || mcd --fail "mcd-gem: Please specify an exit amount"

usr=$(mcd --require-from gem)
usr=$(mcd --get-from gem)

wad=$(seth --to-word $(seth --to-wei $1 eth))
sig="exit(address, uint)"
Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-gem-join
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
set -e
[ -n "$1" ] || mcd --fail "mcd-gem: Please specify a join amount"

mcd---require-ilk-opt
mcd --require-ilk

gem=$(mcd gem address)
join=$(mcd gem adapter)

mcd --gem-approve $join $1

urn=$(mcd --require-urn gem)
urn=$(mcd --get-urn gem)
wad=$(seth --to-uint256 $(seth --to-wei $1 eth))
seth send "$join" "join(address, uint)" $urn $wad

Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-ilk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
### mcd --ilk=ETH-A ilk Art
set -e

id=$(mcd --require-ilk)
id=$(mcd --get-ilk)

vat() { mcd --vat-ilk $id; }
cat() { mcd --cat-ilk $id; }
Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-poke
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
### Example: mcd --ilk=ETH-A poke
set -e

ilk=$(mcd --require-ilk)
ilk=$(mcd --get-ilk)
seth send ${MCD_SPOT?} 'poke(bytes32)' "$ilk"
[[ $SETH_ASYNC != yes ]] && mcd --ilk=$MCD_ILK ilk spot
3 changes: 2 additions & 1 deletion libexec/mcd/mcd-test
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ fi
export SETH_ASYNC=yes
export ETH_GAS=700000

p() { [ $1 = "false" ] && echo "FAIL" && exit; }

#====================================================================
# Helpers
#====================================================================

p() { [ $1 = "false" ] && echo "FAIL" && exit; }

numericCompare() {
p $(awk -v n1="${1}" -v n2="${2}" \
'BEGIN { print (n1 == n2) ? "true" : "false" }' 2>/dev/null)
Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-unwrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### mcd-unwrap -- Unwrap WETH to ETH
### Usage: mcd unwrap <amount>
set -e
mcd --require-from $0 &>/dev/null
mcd --require-from $0
[ -n "$1" ] || mcd --fail "mcd-wrap: Please specify an amount to wrap"
seth send ${ETH?} 'withdraw(uint)' $(seth --to-word $(seth --to-wei "$1 eth"))

Expand Down
4 changes: 2 additions & 2 deletions libexec/mcd/mcd-urn
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
### With `<arg>` get a specified Urn parameter
set -e

URN=$(mcd --require-urn $0)
ILK=$(mcd --require-ilk)
URN=$(mcd --get-urn $0)
ILK=$(mcd --get-ilk)

vat() { mcd --vat-urn $ILK $URN; }

Expand Down
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-wipe
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
mcd --require-ilk-opt
mcd --require-ilk
rate=$(mcd ilk rate)
wad=$(bc <<< "scale=18; $1 / $rate")
mcd frob 0 -- -$wad
2 changes: 1 addition & 1 deletion libexec/mcd/mcd-wrap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### mcd-wrap -- Wrap ETH to WETH
### Usage: mcd wrap <amount>
set -e
mcd --require-from $0 &>/dev/null
mcd --require-from $0
[ -n "$1" ] || mcd --fail "mcd-wrap: Please specify an amount to wrap"
seth send ${ETH?} --value $(seth --to-wei "$1 eth")

Expand Down

0 comments on commit a8bfd02

Please sign in to comment.