The Tech of Cross-Chain Predictions with Azuro & deBridge

Julia Gallen
azuroprotocol

--

Azuro has integrated deBridge, enabling quick access to prediction markets within one UI from a number of chains, previously unavailable withing the Azuro ecosystem. Let’s have a look how these two make it work.

The ‘Why’ and ‘How’ of Bridges

Cross-chain tech is crucial in allowing tokens and information to navigate the fragmented landscape of blockchains. By acting as bridges, these tools are able to securely lock and then transfer tokens between blockchains using an integrated messaging infrastructure for transaction completion.

How DLN (the deBridge protocol integrated by Azuro) makes this happen is that it locks the tokens on the source chain and then unlocks and transfers the funds to the target chain once the order is successfully verified.

1. The ‘Why’

Let’s consider a simple user scenario:

  • Jonny wants to place a bet in one of Azuro’s dApps, but he’s only got funds on Arbitrum. Since most of Azuro’s dApps are mainly on Polygon, Jonny needs to find a way to swap his funds to a different chain. Jonny doesn’t have time to leave the dApp, that’s why a bridge that gives Jonny the right tokens within the dApp is so handy.
  • Jonny chooses the game and market to place a bet on, opens a betslip widget and creates a cross-chain transaction specifying Polygon as the destination chain and how much he wants to bet.
  • Azuro calls the deBridge API which ensures that the tokens are locked in the originating chain and can be replicated or represented in the destination chain, ready for the betting event.
  • Azuro’s smart contract receives and executes this bet on Polygon. Jonny is about to get rich 🙂

2. The ‘How’

Now let’s break down the tech behind this scenario:

Combining deBridge’s cross-chain capabilities with Azuro’s betting protocols creates a powerful ecosystem for cross-chain betting. Here’s a step-by-step breakdown of how these technologies integrate:

  1. Azuro uses deBridge’s API to fetch information about supported chains and tokens, integrating this data into a widget for the dApps to get together with the AzuroSDK.

The segment of code below shows how Azuro prepares the URL parameters for a deBridge API request to create a transaction. It specifies both the source and destination chains and details the token and amount to be used in the bet. The externalCall parameter is crucial as it encodes the betting function (betFor) to be called on Azuro's smart contract on the destination chain (Polygon), using the deBridge protocol to route this transaction.

const params = new URLSearchParams({
dstChainId: 137, // Polygon as the destination chain
srcChainOrderAuthorityAddress: bettorAddress as string,
prependOperatingExpenses: 'false',
srcChainId: String(fromChainId), // Arbitrum as the source chain
srcChainTokenIn: fromTokenAddress, // Token used for the bet
srcChainTokenInAmount: 'auto',
dstChainTokenOut: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', // USDT on Polygon
dstChainTokenOutAmount: String(rawAmount),
dstChainTokenOutRecipient: bettorAddress as string,
dstChainOrderAuthorityAddress: bettorAddress as string,
externalCall: JSON.stringify({
version: 'evm_1',
fields: {
to: lpAddress,
data: encodeFunctionData({
abi: lpAbi,
functionName: 'betFor',
args: [
bettorAddress,
coreAddress,
rawAmount,
rawDeadline,
{
affiliate,
minOdds,
data: betData,
},
],
}),
},
}),
referralCode: String(referralCode),
});

2. Messaging Infrastructure

When a user places a bet on Azuro’s dApp, the dApp communicates with deBridge to handle the cross-chain elements of the transaction.

const deBridgeCreateTxResponse = await fetch(https://api.dln.trade/v1.0/dln/order/create-tx?${params})
const {
orderId,
estimation,
tx,
fixFee
} = await deBridgeCreateTxResponse.json()j

Here, the actual API call is made to deBridge’s create-tx endpoint with the prepared parameters. This call initiates the cross-chain transaction and returns details such as the order ID, transaction specifics, and estimated fees involved in the transfer. The response from this API call will be used to track and manage the bet.

Before executing the transaction, it’s essential to ensure that the deBridge contract is allowed to handle the tokens required for the bet on behalf of the user.

const allowanceTx = useReadContract({
chainId: fromChainId,
address: estimation?.srcChainTokenIn.address,
abi: erc20Abi,
functionName: 'allowance',
args: [
bettorAddress,
tx?.to as Address,
],
});
const isApproveRequired = Boolean(
allowanceTx.data !== undefined && allowanceTx.data < BigInt(estimation?.srcChainTokenIn?.amount || 0)
);
const approveTx = useWriteContract();
approveTx.writeContract({
address: estimation?.srcChainTokenIn.address,
abi: erc20Abi,
chainId: fromChainId,
functionName: 'approve',
args: [
tx?.to as Address,
maxUint256,
],
});

3. Transaction Monitoring:

The code above checks if the deBridge contract has enough allowance to transfer the tokens needed for the bet. If not, it sends an approval transaction to authorize deBridge to handle the required amount of tokens. This step is critical to ensure that the bet transaction doesn’t fail due to lack of permissions.

Azuro’s smart contracts are integral to this process, particularly functions like betFor, which not only place the bet but also confirm its validity and execution across the involved blockchains. This ensures that all transactions are not only secure but also adhere to the specific betting regulations of the destination chain.

deBridge provides a generic messaging protocol that enables decentralized transfer and interaction between different blockchains. Throughout the betting process, Azuro and deBridge provide tools and APIs to monitor the status of bets and transactions across chains. This ensures transparency and allows users to track their bets in real-time.

deBridge handles the secure and efficient transfer of assets and betting data between chains, while Azuro manages the betting specifics and execution on the destination chain. This synergy expands the possibilities for decentralized betting, making it accessible regardless of the user’s preferred blockchain.

Azuro is the onchain predictions layer. It consists of modular tooling, oracle and liquidity solutions for EVM chains to host powerful prediction and gaming apps.

With its unique infrastructure layer approach, Azuro makes onchain predictions and gaming portable and composable. It allows anyone to engage and monetize users by building apps, integrations, and products quickly, permissionlessly and with zero upfront or running costs.

Disclaimer: This content is provided for informational purposes only, and should not be relied upon as legal, business, investment, financial or tax advice. References to any digital assets, projects and platforms do not constitute any recommendation for any action or an offer to provide investment, financial or other advisory services. This content may not under any circumstances be relied upon when making a decision to purchase any digital asset referenced herein.

--

--

Julia Gallen
azuroprotocol

Curious about new tech, ancient people, and timeless stories 📜