Skip to content

Commit

Permalink
add arbitrum to chainflip (#1291)
Browse files Browse the repository at this point in the history
* add arbitrum to chainflip

* Aggregator tests

* Arbitrum lower fee bound

* Aggregator example bug fix

* resolve comment

* add changeset

---------

Co-authored-by: 0xp3gasus <[email protected]>
  • Loading branch information
juanfri-web3 and 0xp3gasus authored Oct 3, 2024
1 parent 34825df commit 62eae5e
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 297 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-cows-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-aggregator': patch
---

Add arbitrum to chainflip protocol
5 changes: 5 additions & 0 deletions .changeset/polite-flowers-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xchainjs/xchain-arbitrum': patch
---

Lower fee bound updated to 10000000.
4 changes: 2 additions & 2 deletions examples/aggregator/swap-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const main = async () => {
return {
protocol: swap.protocol,
fromAsset: assetToString(swap.inboundTx.amount.asset),
toAsset: swap.outboundTx ? assetToString(swap.outboundTx.amount.asset) : undefined,
toAsset: swap.status === 'success' ? assetToString(swap.outboundTx.amount.asset) : undefined,
hash: swap.inboundTx.hash,
fromAmount: swap.inboundTx.amount.assetAmount.amount().toString(),
toAmount: swap.outboundTx ? swap.outboundTx.amount.assetAmount.amount().toString() : undefined,
toAmount: swap.status === 'success' ? swap.outboundTx.amount.assetAmount.amount().toString() : undefined,
}
}),
)
Expand Down
58 changes: 29 additions & 29 deletions packages/xchain-aggregator/__e2e__/aggregator.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,33 @@ describe('Aggregator', () => {
console.log(txSubmitted)
})

it('Should get swaps history', async () => {
const swapHistory = await aggregator.getSwapHistory({
chainAddresses: [{ chain: 'BTC', address: 'address' }],
})

console.log(
swapHistory.swaps.map((swap) => {
return {
protocol: swap.protocol,
status: swap.status,
date: swap.date.toDateString(),
inboundTX: {
hash: swap.inboundTx.hash,
address: swap.inboundTx.address,
asset: assetToString(swap.inboundTx.amount.asset),
amount: swap.inboundTx.amount.assetAmount.amount().toString(),
},
outboundTx: swap.outboundTx
? {
hash: swap.outboundTx.hash,
address: swap.outboundTx.address,
asset: assetToString(swap.outboundTx.amount.asset),
amount: swap.outboundTx.amount.assetAmount.amount().toString(),
}
: undefined,
}
}),
)
})
// it('Should get swaps history', async () => {
// const swapHistory = await aggregator.getSwapHistory({
// chainAddresses: [{ chain: 'BTC', address: 'address' }],
// })

// console.log(
// swapHistory.swaps.map((swap) => {
// return {
// protocol: swap.protocol,
// status: swap.status,
// date: swap.date.toDateString(),
// inboundTX: {
// hash: swap.inboundTx.hash,
// address: swap.inboundTx.address,
// asset: assetToString(swap.inboundTx.amount.asset),
// amount: swap.inboundTx.amount.assetAmount.amount().toString(),
// },
// outboundTx: swap.outboundTx
// ? {
// hash: swap.outboundTx.hash,
// address: swap.outboundTx.address,
// asset: assetToString(swap.outboundTx.amount.asset),
// amount: swap.outboundTx.amount.assetAmount.amount().toString(),
// }
// : undefined,
// }
// }),
// )
// })
})
43 changes: 17 additions & 26 deletions packages/xchain-aggregator/__mocks__/@chainflip/sdk/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ class SwapSDK {
evmChainId: 11155111,
isMainnet: false,
requiredBlockConfirmations: 7,
maxRetryDurationBlocks: undefined,
},
{
chain: 'Polkadot',
name: 'Polkadot',
evmChainId: undefined,
isMainnet: false,
requiredBlockConfirmations: undefined,
maxRetryDurationBlocks: undefined,
},
{
chain: 'Bitcoin',
name: 'Bitcoin',
evmChainId: undefined,
isMainnet: false,
requiredBlockConfirmations: 6,
maxRetryDurationBlocks: undefined,
},
]
}
Expand Down Expand Up @@ -126,6 +129,7 @@ class SwapSDK {
depositAddress: 'BITCOINfakeaddress',
depositChannelId: 'bitcoin-channel-id',
brokerCommissionBps: 0,
affiliateBrokers: [],
depositChannelExpiryBlock: BigInt(10000),
estimatedDepositChannelExpiryTime: 1716889354,
channelOpeningFee: BigInt(100),
Expand All @@ -136,6 +140,7 @@ class SwapSDK {
depositAddress: 'ETHEREUMfakeaddress',
depositChannelId: 'ethereum-channel-id',
brokerCommissionBps: 0,
affiliateBrokers: [],
depositChannelExpiryBlock: BigInt(20000),
estimatedDepositChannelExpiryTime: 1716889354,
channelOpeningFee: BigInt(100),
Expand All @@ -146,6 +151,7 @@ class SwapSDK {
depositAddress: 'POLKADOTfakeaddress',
depositChannelId: 'polkadot-channel-id',
brokerCommissionBps: 0,
affiliateBrokers: [],
depositChannelExpiryBlock: BigInt(30000),
estimatedDepositChannelExpiryTime: 1716889354,
channelOpeningFee: BigInt(100),
Expand All @@ -168,6 +174,7 @@ class SwapSDK {
destChain,
amount,
quote: {
type: 'REGULAR',
intermediateAmount: '36115119',
egressAmount: '51193',
includedFees: [
Expand All @@ -184,13 +191,13 @@ class SwapSDK {
amount: '36115',
},
{
type: 'LIQUIDITY',
type: 'NETWORK',
chain: 'Ethereum',
asset: 'ETH',
amount: '4655411871275',
},
{
type: 'LIQUIDITY',
type: 'NETWORK',
chain: 'Ethereum',
asset: 'USDC',
amount: '18057',
Expand All @@ -204,6 +211,8 @@ class SwapSDK {
],
lowLiquidityWarning: false,
estimatedDurationSeconds: 702,
poolInfo: [],
estimatedPrice: '2300',
},
}
}
Expand All @@ -222,6 +231,7 @@ class SwapSDK {
destChain,
amount,
quote: {
type: 'REGULAR',
intermediateAmount: '13560635',
egressAmount: '2063188201000691',
includedFees: [
Expand All @@ -237,18 +247,6 @@ class SwapSDK {
asset: 'USDC',
amount: '13560',
},
{
type: 'LIQUIDITY',
chain: 'Ethereum',
asset: 'USDT',
amount: '6783',
},
{
type: 'LIQUIDITY',
chain: 'Ethereum',
asset: 'USDC',
amount: '6780',
},
{
type: 'EGRESS',
chain: 'Ethereum',
Expand All @@ -258,6 +256,8 @@ class SwapSDK {
],
lowLiquidityWarning: false,
estimatedDurationSeconds: 114,
poolInfo: [],
estimatedPrice: '1',
},
}
}
Expand All @@ -276,6 +276,7 @@ class SwapSDK {
destChain,
amount,
quote: {
type: 'REGULAR',
intermediateAmount: '33919877',
egressAmount: '24884030',
includedFees: [
Expand All @@ -291,18 +292,6 @@ class SwapSDK {
asset: 'USDC',
amount: '33919',
},
{
type: 'LIQUIDITY',
chain: 'Ethereum',
asset: 'ETH',
amount: '4357594332450',
},
{
type: 'LIQUIDITY',
chain: 'Ethereum',
asset: 'USDC',
amount: '16959',
},
{
type: 'EGRESS',
chain: 'Ethereum',
Expand All @@ -312,6 +301,8 @@ class SwapSDK {
],
lowLiquidityWarning: false,
estimatedDurationSeconds: 114,
poolInfo: [],
estimatedPrice: '2300',
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-aggregator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"directory": "release/package"
},
"dependencies": {
"@chainflip/sdk": "1.3.0",
"@chainflip/sdk": "1.6.0",
"@xchainjs/xchain-client": "workspace:*",
"@xchainjs/xchain-mayachain": "workspace:*",
"@xchainjs/xchain-mayachain-amm": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ export class ChainflipProtocol implements IProtocol {
return this.sdk.getAssets()
}, 24 * 60 * 60 * 1000)
}
approveRouterToSpend(_params: { asset: TokenAsset; amount?: CryptoAmount }): Promise<TxSubmitted> {
throw new Error('Method not implemented.')
public approveRouterToSpend(_params: { asset: TokenAsset; amount?: CryptoAmount }): Promise<TxSubmitted> {
throw new Error('Not implemented')
}
shouldBeApproved(_params: { asset: TokenAsset; amount: CryptoAmount; address: string }): Promise<boolean> {
throw new Error('Method not implemented.')
public async shouldBeApproved(_params: {
asset: TokenAsset
amount: CryptoAmount
address: string
}): Promise<boolean> {
return Promise.resolve(false)
}

/**
Expand Down Expand Up @@ -209,11 +213,7 @@ export class ChainflipProtocol implements IProtocol {
}
const chainAssets = await this.assetsData.getValue()
const assetData = chainAssets.find((chainAsset) => {
const contractAddress = asset.symbol.split('-').length > 1 ? asset.symbol.split('-')[1] : undefined
return (
chainAsset.asset === xAssetToCAsset(asset) &&
chainAsset.contractAddress?.toLowerCase() === contractAddress?.toLowerCase()
)
return chainAsset.asset === xAssetToCAsset(asset) && asset.chain === cChainToXChain(chainAsset.chain)
})
if (!assetData) throw Error(`${asset.ticker} asset not supported in ${asset.chain} chain`)
return assetData
Expand Down
8 changes: 8 additions & 0 deletions packages/xchain-aggregator/src/protocols/chainflip/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const cChainToXChain = (chain: CChain): XChain => {
return 'ETH'
case 'Polkadot':
return 'POL'
case 'Arbitrum':
return 'ARB'
case 'Solana':
return 'SOL'
default:
throw Error('Unsupported chain in XChainJS')
}
Expand All @@ -22,6 +26,10 @@ export const xChainToCChain = (chain: XChain): CChain => {
return Chains.Ethereum
case 'POL':
return Chains.Polkadot
case 'ARB':
return Chains.Arbitrum
case 'SOL':
return Chains.Solana
default:
throw Error('Unsupported chain in Chainflip')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/xchain-arbitrum/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BigNumber, ethers } from 'ethers'

// Define constants related to Arbitrum
export const ARB_DECIMAL = 18
export const LOWER_FEE_BOUND = 100_000_000
export const LOWER_FEE_BOUND = 100_000_00
export const UPPER_FEE_BOUND = 1_000_000_000
export const ARB_GAS_ASSET_DECIMAL = 18
export const ARBChain = 'ARB' as const
Expand Down
Loading

0 comments on commit 62eae5e

Please sign in to comment.