Skip to content

Commit

Permalink
Merge pull request #1492 from AmbireTech/bull-run-campaign
Browse files Browse the repository at this point in the history
Humanizer updates for bull run campaign
  • Loading branch information
stojnovsky authored Jan 8, 2024
2 parents 98e13dd + 4c8b0a0 commit 54417b4
Show file tree
Hide file tree
Showing 11 changed files with 667 additions and 8 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@web3-react/abstract-connector": "^6.0.7",
"@web3-react/types": "^6.0.7",
"adex-protocol-eth": "git+https://[email protected]/AmbireTech/adex-protocol-eth.git#4ddebac4109e9709c4cc862ee0708f208dac9ee2",
"ambire-common": "github:AmbireTech/ambire-common#v1.0.2",
"ambire-common": "github:AmbireTech/ambire-common#v1.0.3",
"bip44-constants": "^128.0.0",
"blockies-ts": "^1.0.0",
"chart.js": "^3.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ const ExtendedSummaryItem = ({ item, i, networkDetails, feeAssets }) => {
</a>
)
}
if (item.type === 'link')
return (
<div>
<a href={item.link} target="_blank" rel="noreferrer">
{item.text}
</a>
</div>
)

return null
}
Expand Down
82 changes: 82 additions & 0 deletions src/lib/humanizers/Bungee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Interface } from 'ethers/lib/utils'
import networks from 'consts/networks'
import { nativeToken, getName } from 'lib/humanReadableTransactions'

const getNetwork = (chainId, extended = false) => {
const network = networks.find((n) => n.chainId === Number(chainId))
return !extended ? network.name : { ...network, type: 'network' }
}

// bungee runs some of its calls through falllback that serves as router to unverified contracts,
// thats why we can't fetch data from block explorers in ambire constants
const Bungee = (humanizerInfo) => {
const iface = new Interface(humanizerInfo.abis.StargateImplL2V2)
return {
// some bungee bridge txn start with 4 bytes number and the next 4 bytes are a sigHash
// bungee uses fallback and later redirects to address based on the first 4 bytes
'0x00000005:0x3a23F943181408EAC424116Af7b7790c94Cb97a5': (
txn,
network,
{ extended = false }
) => {
const parsedCallData = `0x${txn.data.slice(10)}`
const [_number, recipient, chainId, _bytes, _moreData] = iface.decodeFunctionData(
'swapAndBridge(uint32,address,uint256,bytes32,bytes)',
parsedCallData
)
return !extended
? [`Bridge tokens on Bungee to ${getNetwork(chainId)}`]
: [['Bridge', 'tokens on Bungee to', getNetwork(chainId, true)]]
},
'0x00000016:0x3a23F943181408EAC424116Af7b7790c94Cb97a5': (
txn,
network,
{ extended = false }
) => {
const parsedCallData = `0x${txn.data.slice(10)}`
const [_number, _data, [address1, address2, destinationNetwork]] = iface.decodeFunctionData(
'swapAndBridge(uint32,bytes,(address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes32))',
parsedCallData
)
return !extended
? [`Bridge tokens on Bungee to ${getNetwork(destinationNetwork)}`]
: [['Bridge', 'tokens on Bungee to', getNetwork(destinationNetwork, true)]]
},
'0x00000003:0x3a23F943181408EAC424116Af7b7790c94Cb97a5': (
txn,
network,
{ extended = false }
) => {
const parsedCallData = `0x${txn.data.slice(10)}`
const [amountnNative, bytes32, recipient, destinationNetwork] = iface.decodeFunctionData(
'bridgeNativeTo(uint256,bytes32,address,uint256)',
parsedCallData
)

return !extended
? [
`Bridge ${nativeToken(network, amountnNative)} to ${getNetwork(destinationNetwork)} ${
recipient !== txn.from ? `and send to ${getName(humanizerInfo, recipient)}` : ''
}`
]
: [
[
'Bridge',
{
type: 'token',
...nativeToken(network, amountnNative, true)
},
'to',
getNetwork(destinationNetwork, true),
...(recipient !== txn.from
? [
'and send to',
{ type: 'address', address: recipient, name: getName(humanizerInfo, recipient) }
]
: [])
]
]
}
}
}
export default Bungee
28 changes: 28 additions & 0 deletions src/lib/humanizers/CowSwap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Interface } from 'ethers/lib/utils'
import { token } from 'lib/humanReadableTransactions'

const onBehalfText = (onBehalf, txnFrom) =>
onBehalf.toLowerCase() !== txnFrom.toLowerCase() ? ` on behalf of ${onBehalf}` : ''

const CowSwap = (humanizerInfo) => {
const iface = new Interface(humanizerInfo.abis.CowSwapSettlement)

return {
[iface.getSighash('setPreSignature')]: (txn, network, { extended }) => {
const [orderUid, _signed] = iface.parseTransaction(txn).args
if (extended)
return [
[
'Execute CowSwap order',
{
type: 'link',
link: `https://explorer.cow.fi/orders/${orderUid}?tab=overview`,
text: 'more info here'
}
]
]
return [`CowSwap order ${orderUid}`]
}
}
}
export default CowSwap
52 changes: 52 additions & 0 deletions src/lib/humanizers/GMX.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Interface } from 'ethers/lib/utils'
import { token, getName } from 'lib/humanReadableTransactions'

const GMX = (humanizerInfo) => {
const orderHandler = new Interface(humanizerInfo.abis.GMXOrderHandler)

return {
[orderHandler.getSighash('executeOrder')]: (txn, network, { extended }) => {
// oracleParams
/*
struct SetPricesParams {
uint256 signerInfo;
address[] tokens;
uint256[] compactedMinOracleBlockNumbers;
uint256[] compactedMaxOracleBlockNumbers;
uint256[] compactedOracleTimestamps;
uint256[] compactedDecimals;
uint256[] compactedMinPrices;
uint256[] compactedMinPricesIndexes;
uint256[] compactedMaxPrices;
uint256[] compactedMaxPricesIndexes;
bytes[] signatures;
address[] priceFeedTokens;
address[] realtimeFeedTokens;
bytes[] realtimeFeedData;
}
*/
const { key, oracleParams } = orderHandler.parseTransaction(txn).args
const tokens = oracleParams.realtimeFeedTokens
const data = oracleParams.realtimeFeedData
if (extended)
return [
[
'Open GMX position',
'from',
{ type: 'token', ...token(humanizerInfo, tokens[tokens.length - 2], -1, true) },
'to',
{ type: 'token', ...token(humanizerInfo, tokens[0], -1, true) }
]
]
return [
`Open GMX position from ${token(humanizerInfo, tokens[tokens.length - 1], -1)} to ${token(
humanizerInfo,
tokens[0],
-1
)}`
]
}
}
}

export default GMX
94 changes: 94 additions & 0 deletions src/lib/humanizers/Joe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { Interface } from 'ethers/lib/utils'
import { token, getName, nativeToken } from 'lib/humanReadableTransactions'

const Joe = (humanizerInfo) => {
const iface = new Interface(humanizerInfo.abis.JoeRouter)

return {
[iface.getSighash('swapExactTokensForAVAX')]: (txn, network, { extended }) => {
const { amountIn, amountOutMin, path, to, deadline } = iface.parseTransaction(txn).args
if (extended)
return [
[
'Swap',
{ type: 'token', ...token(humanizerInfo, path[0], amountIn, true) },
'for at least',
{ type: 'token', ...token(humanizerInfo, path[path.length - 1], amountOutMin, true) },
...(txn.from !== to
? [
'and send swapped to',
{ type: 'address', address: to, name: getName(humanizerInfo, to) }
]
: [])
]
]
return [
`Swap ${token(humanizerInfo, path[0], amountIn)} for at least ${token(
humanizerInfo,
path[path.length - 1],
amountOutMin
)} ${txn.from !== to ? `and send swapped to ${getName(humanizerInfo, to)}` : ''}`
]
},
[iface.getSighash('swapExactAVAXForTokens(uint256,address[],address,uint256)')]: (
txn,
network,
{ extended }
) => {
const { to, amountOutMin, path, deadline } = iface.parseTransaction(txn).args
if (extended)
return [
[
'Swap',
{ type: 'token', ...nativeToken(network, txn.value, true) },
'for at least',
{ type: 'token', ...token(humanizerInfo, path[path.length - 1], amountOutMin, true) },
...(txn.from !== to
? [
'and send swapped to',
{ type: 'address', address: to, name: getName(humanizerInfo, to) }
]
: [])
]
]
return [
`Swap ${nativeToken(network, txn.value)} for at least ${token(
humanizerInfo,
path[path.length - 1],
amountOutMin
)} ${txn.from !== to ? ` and send swapped to ${getName(humanizerInfo, to)}` : ''}`
]
},
[iface.getSighash('swapAVAXForExactTokens(uint256,address[],address,uint256)')]: (
txn,
network,
{ extended }
) => {
const [amountOutMin, path, to, deadline] = iface.parseTransaction(txn).args

if (extended)
return [
[
'Swap',
{ type: 'token', ...nativeToken(network, txn.value, true) },
'for at least',
{ type: 'token', ...token(humanizerInfo, path[path.length - 1], amountOutMin, true) },
...(txn.from !== to
? [
'and send swapped to',
{ type: 'address', address: to, name: getName(humanizerInfo, to) }
]
: [])
]
]
return [
`Swap ${nativeToken(network, txn.value)} for at least ${token(
humanizerInfo,
path[path.length - 1],
amountOutMin
)} ${txn.from !== to ? ` and send swapped to ${getName(humanizerInfo, to)}` : ''}`
]
}
}
}
export default Joe
48 changes: 48 additions & 0 deletions src/lib/humanizers/Lido.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Interface } from 'ethers/lib/utils'
import { token, getName, nativeToken } from 'lib/humanReadableTransactions'

function getAddress(humanizerInfo, address) {
return {
type: 'address',
address,
name: getName(humanizerInfo, address)
}
}
const MATIC_ON_ETH_ADDRESS = '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'
const Lido = (humanizerInfo) => {
const ifaceETH = new Interface(humanizerInfo.abis.LidoStETH)
const ifaceMATIC = new Interface(humanizerInfo.abis.LidoStMATIC)
return {
[ifaceETH.getSighash('submit')]: (txn, network, { extended }) => {
const { _positionId, _recipient } = ifaceETH.parseTransaction(txn).args
if (extended)
return [
_recipient === txn.from
? [`Stake ${nativeToken(network, txn.value)}`]
: [
'Stake',
{
type: 'token',
...nativeToken(network, txn.value, true)
},
'to',
getAddress(humanizerInfo, txn.to)
]
]
return [
_recipient === txn.from
? [`Withdraw swapped tokens from position ${_positionId}`]
: [`Send swapped tokens from position ${_positionId} to ${_recipient}`]
]
},
[ifaceMATIC.getSighash('submit')]: (txn, network, { extended }) => {
const { _amount } = ifaceMATIC.parseTransaction(txn).args
if (extended)
return [
['Stake', { type: 'token', ...token(humanizerInfo, MATIC_ON_ETH_ADDRESS, _amount, true) }]
]
return [[`Stake ${token(humanizerInfo, MATIC_ON_ETH_ADDRESS, _amount)}`]]
}
}
}
export default Lido
Loading

0 comments on commit 54417b4

Please sign in to comment.