Skip to content

Commit

Permalink
Merge pull request #110 from DefiLlama/neoiss/master
Browse files Browse the repository at this point in the history
Neoiss/master
  • Loading branch information
vrtnd authored Jan 22, 2024
2 parents eb4f0ae + 56cbd8e commit 202689f
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 4 deletions.
143 changes: 143 additions & 0 deletions src/adapters/butternetwork/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { Chain } from "@defillama/sdk/build/general";
import { BridgeAdapter, PartialContractEventParams } from "../../helpers/bridgeAdapter.type";
import { getTxDataFromEVMEventLogs } from "../../helpers/processTransactions";

const contractAddresses = {
bsc: {
mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380",
tokens: {
USDT: "0x55d398326f99059fF775485246999027B3197955",
USDC: "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
DAI: "0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3",
ETH: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
MAP: "0x8105ECe4ce08B6B6449539A5db23e23b973DfA8f"
}
},
polygon: {
mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380",
tokens: {
USDT: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
USDC: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
DAI: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
ETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619",
MAP: "0xBAbceE78586d3e9E80E0d69601A17f983663Ba6a"
}
},
ethereum: {
mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380",
tokens: {
USDT: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
DAI: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
ETH: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
MAP: "0x9e976f211daea0d652912ab99b0dc21a7fd728e4"
}
},
map: {
mosContract: "0xfeB2b97e4Efce787c08086dC16Ab69E063911380",
tokens: {
USDT: "0x33daba9618a75a7aff103e53afe530fbacf4a3dd",
USDC: "0x9f722b2cb30093f766221fd0d37964949ed66918",
DAI: "0xEdDfAac857cb94aE8A0347e2b1b06f21AA1AAeFA",
ETH: "0x05ab928d446d8ce6761e368c8e7be03c3168a9ec",
MAP: "0x13cb04d4a5dfb6398fc5ab005a6c84337256ee23"
}
}
} as {
[chain: string]: {
mosContract: string;
tokens: {};
};
};

const tokenDepositParams: PartialContractEventParams = {
target: "",
topic: "mapSwapIn(uint256,uint256,bytes32,address,bytes,address,uint256)",
abi: [
"event mapSwapIn(uint256 indexed fromChain, uint256 indexed toChain, bytes32 indexed orderId, address token, bytes from, address toAddress, uint256 amountOut)"
],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash"
},
argKeys: {
from: "from",
to: "toAddress",
token: "token",
amount: "amountOut"
},
isDeposit: true
};

const tokenWithdrawalParams: PartialContractEventParams = {
target: "",
topic: "mapSwapOut(uint256,uint256,bytes32,bytes,bytes,bytes,uint256,bytes)",
abi: ["event mapSwapOut(uint256 indexed fromChain, uint256 indexed toChain, bytes32 orderId, bytes token, bytes from, bytes to, uint256 amount, bytes swapData)"],
logKeys: {
blockNumber: "blockNumber",
txHash: "transactionHash"
},
argKeys: {
to: "to",
amount: "amount"
},
isDeposit: false
};

const constructParams = (chain: string) => {
let eventParams = [] as any;

const chainAddresses = contractAddresses[chain]
const mos = chainAddresses.mosContract;
const tokens = chainAddresses.tokens;

// const finalMOSDepositParams = {
// ...tokenDepositParams,
// target: mos,
// fixedEventData: {
// to: mos
// }
// };
// const finalMOSWithdrawalParams = {
// ...tokenWithdrawalParams,
// target: mos,
// fixedEventData: {
// from: mos
// }
// };
// eventParams.push(finalMOSDepositParams, finalMOSWithdrawalParams);

for (let token of Object.values(tokens)) {
const finalTokenDepositParams = {
...tokenDepositParams,
target: token,
fixedEventData: {
to: mos,
token: token
}
};
const finalTokenWithdrawalParams = {
...tokenWithdrawalParams,
target: token,
fixedEventData: {
from: mos,
token: token
}
};
eventParams.push(finalTokenDepositParams, finalTokenWithdrawalParams);
}

return async (fromBlock: number, toBlock: number) =>
getTxDataFromEVMEventLogs("butternetwork", chain as Chain, fromBlock, toBlock, eventParams);
};


const adapter: BridgeAdapter = {
bsc: constructParams("bsc"),
polygon: constructParams("polygon"),
ethereum: constructParams("ethereum"),
'map relay chain': constructParams("map")
};

export default adapter;

3 changes: 2 additions & 1 deletion src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import pepeteam_bridge from './pepeteam-bridge';
import pnetwork from './pnetwork';
import interport from './interport-finance';
import shimmerbridge from "./shimmerbridge";
import butternetwork from "./butternetwork";
import xy from './xy-finance'


export default {
polygon,
synapse,
Expand Down Expand Up @@ -88,6 +88,7 @@ export default {
pnetwork,
interport,
shimmerbridge,
butternetwork,
xy,
} as {
[bridge: string]: BridgeAdapter;
Expand Down
13 changes: 13 additions & 0 deletions src/data/bridgeNetworkData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,17 @@ export default [
avalanche: "avax",
},
},
{
id: 47,
displayName: "Butter Network",
bridgeDbName: "butternetwork",
iconLink: "icons:butternetwork",
largeTxThreshold: 10000,
url: "",
chains: ["Ethereum", "Polygon", "BSC", "MAP Relay Chain"],
chainMapping: {
"map relay chain": "map",
},
destinationChain: "MAP Relay Chain",
},
] as BridgeNetwork[];
5 changes: 2 additions & 3 deletions src/utils/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export const runAdapterHistorical = async (
const bridgeNetwork = bridgeNetworks.filter((bridgeNetwork) => bridgeNetwork.id === bridgeNetworkId)[0];
const { bridgeDbName } = bridgeNetwork;
const adapter = adapters[bridgeDbName];
if (chain?.toLowerCase() === bridgeNetwork.destinationChain?.toLowerCase()) {
const adapterChainEventsFn = adapter[chain];
if (chain?.toLowerCase() === bridgeNetwork.destinationChain?.toLowerCase() && !adapterChainEventsFn) {
console.log(`Skipping ${bridgeDbName} on ${chain} because it is not the destination chain.`);
return;
}
Expand All @@ -350,8 +351,6 @@ export const runAdapterHistorical = async (
}
await insertConfigEntriesForAdapter(adapter, bridgeDbName, bridgeNetwork?.destinationChain);

const adapterChainEventsFn = adapter[chain];

if (!adapterChainEventsFn && chain?.toLowerCase() !== bridgeNetwork.destinationChain?.toLowerCase()) {
const errString = `Chain ${chain} not found on adapter ${bridgeDbName}.`;
await insertErrorRow({
Expand Down

0 comments on commit 202689f

Please sign in to comment.