Last active
May 9, 2018 18:23
-
-
Save adrianmcli/da3cb090f4d2b7c8453462e0e98a64ac to your computer and use it in GitHub Desktop.
just a simple function to transform a typical 0x order object into the form we need.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const transform = ({ | |
exchangeContract, | |
expiration, | |
feeRecipient, | |
salt, | |
maker, | |
taker | |
}) => ({ | |
exchangeContractAddress: exchangeContract, | |
expirationUnixTimestampSec: expiration, | |
feeRecipient: feeRecipient, | |
maker: maker.address, | |
makerFee: maker.feeAmount, | |
makerTokenAddress: maker.token.address, | |
makerTokenAmount: maker.amount, | |
salt: salt, | |
taker: taker.address, | |
takerFee: taker.feeAmount, | |
takerTokenAddress: taker.token.address, | |
takerTokenAmount: taker.amount | |
}) | |
// Example input/output below | |
const example0xOrder = { | |
"maker":{ | |
"address":"0x201c6c7e32fad71d2e8c554958a2283a62a67a48", | |
"token":{ | |
"name":"Aragon", | |
"symbol":"ANT", | |
"decimals":18, | |
"address":"0x960b236a07cf122663c4303350609a66a7b288c0" | |
}, | |
"amount":"20345000000000000000", | |
"feeAmount":"0" | |
}, | |
"taker":{ | |
"address":"", | |
"token":{ | |
"name":"Ether Token", | |
"symbol":"WETH", | |
"decimals":18, | |
"address":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2" | |
}, | |
"amount":"129000000000000000", | |
"feeAmount":"0" | |
}, | |
"expiration":"1515441600", | |
"feeRecipient":"0x0000000000000000000000000000000000000000", | |
"salt":"37090108066070358564552859386421900033660410305386203610878278899066621444429", | |
"signature":{ | |
"v":27, | |
"r":"0xbaad473ee3adbcdf1f946e4c219684d06c0193049f07002fa91b04329cd75b12", | |
"s":"0x06d65682fbe24a83e9f30634923af25056217038dec60d9166af52f5e299637a", | |
"hash":"0xf6c0468b241861b82e781b297ce641f86bc715316804e0677d87fd250ed9da28" | |
}, | |
"exchangeContract":"0x12459c951127e0c374ff9105dda097662a027093", | |
"networkId":1 | |
} | |
console.log(transform(example0xOrder)) | |
// { exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', | |
// expirationUnixTimestampSec: '1515441600', | |
// feeRecipient: '0x0000000000000000000000000000000000000000', | |
// maker: '0x201c6c7e32fad71d2e8c554958a2283a62a67a48', | |
// makerFee: '0', | |
// makerTokenAddress: '0x960b236a07cf122663c4303350609a66a7b288c0', | |
// makerTokenAmount: '20345000000000000000', | |
// salt: '37090108066070358564552859386421900033660410305386203610878278899066621444429', | |
// taker: '', | |
// takerFee: '0', | |
// takerTokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', | |
// takerTokenAmount: '129000000000000000' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment