Coder Social home page Coder Social logo

bridges-server's Introduction

Bridges adapters

Installation

npm i

Adding new adapter

Adapter output

Array of

txHash:  string,
blockNumber:  number,
from:  string,
to:  string,
token:  string,
isDeposit:  boolean 
amount: BigNumber 

If your bridge is on 2 chains you can create adapter for 1 chain and track both deposits and withdrawals

const  adapter: BridgeAdapter = {
ethereum:  constructParams("ethereum"),
polygon:  constructParams("polygon"),
fantom:  constructParams("fantom"),
avalanche:  constructParams("avax"),
bsc:  constructParams("bsc"),
klaytn:  constructParams("klaytn"),
}; 

Log event parameters

type  ContractEventParams = {
target: string | null;
topic: string;
abi: string[];
logKeys?: EventKeyMapping; // retrieve data from event log
argKeys?: EventKeyMapping; // retrieve data from parsed event log
argGetters?: Partial<Record<keyof  EventKeyMapping, (log: any) =>  any>>;
txKeys?: EventKeyMapping; // retrieve data from transaction referenced in event log
topics?: (string | null)[];
isDeposit: boolean;
chain?: Chain; // override chain given as parameter in getTxDataFromEVMEventLogs
isTransfer?: boolean;
fixedEventData?: EventKeyMapping; // hard-code any final values
inputDataExtraction?: InputDataExtraction; // retrieve data from event log's input data field
selectIndexesFromArrays?: EventKeyMapping; // extract data returned as an array by specifying the index of element
functionSignatureFilter?: FunctionSignatureFilter;
filter?: EventLogFilter;
mapTokens?: { [token: string]: string }; // can expand to map other keys if needed
getTokenFromReceipt?: {
token: boolean;
amount?: boolean;
native?: string; // if provided native token address, will return amount of native token transferred if there are no ercs transferred
};

Example

const  ethWithdrawalParams: PartialContractEventParams = {
target: "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1",
topic: "ETHWithdrawalFinalized(address,address,uint256,bytes)",
abi: ["event ETHWithdrawalFinalized(address indexed _from, address indexed _to, uint256 _amount, bytes _data)"],
isDeposit: false, // event type 
logKeys: {
  blockNumber:  "blockNumber", 
  txHash:  "transactionHash",// if event log data key != adapter ouptup key
},
argKeys: {
  to: "_to", 
  amount: "_amount", // if event data key !== output key
},
fixedEventData: {
  from: "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1", // static keys
  token: WETH,
},
}; 

Bridge Data

Create new object for your bridge in ./src/data/bridgeNetworkData.ts

id:  1, // new id 
displayName:  "Polygon PoS Bridge", // name
bridgeDbName:  "polygon", // name in db
iconLink:  "chain:polygon", // icon name in https://icons.llamao.fi/icons/
largeTxThreshold:  10000,
url:  "",
chains: ["Ethereum", "Polygon"], // Bridge chains. If your bridge is on 2 chains you can create adapter for 1 chain and track both deposits and withdrawals
destinationChain:  "Polygon", // When bridge connects 2 chains, for example Ethereum<->Optimism and there is only one adapter on one chain which tracks deposits and withdrawals for both chains

Testing

Adapter Testing:

npm run test [adapter name] [number of blocks to test on]
Example: 
npm run test across 1000

Backfill testing:

npm run test-txs [start ts] [end ts] [adapter name]
Example: 
npm run test-txs 1688476361 1688919317 synapse

bridges-server's People

Contributors

cocoahomology avatar vrtnd avatar nemusonaneko avatar 0xngmi avatar h3lio5 avatar allush avatar npty avatar defi-moses avatar cc7768 avatar wyf-accept avatar lgingerich avatar eserilev avatar fankouzu avatar goneuronxyz avatar 0xstrobe avatar abg4 avatar kev1n-peters avatar realdealshaman avatar yaroslavnekryach avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.