-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2700b8a
commit d67b2f6
Showing
7 changed files
with
255 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { EuphratesFactory__factory } from '@acala-network/asset-router/dist/typechain-types'; | ||
|
||
import { EUPHRATES_ADDR, EUPHRATES_POOLS } from '../consts'; | ||
import { | ||
Mainnet, | ||
RouteParamsEuphrates, | ||
_populateRelayTx, | ||
_populateRouteTx, | ||
getChainConfig, | ||
getMainnetChainId, | ||
} from '../utils'; | ||
import { RelayerError } from '../middlewares'; | ||
|
||
const prepareRouteEuphrates = async (chain: Mainnet) => { | ||
const chainId = getMainnetChainId(chain); | ||
const chainConfig = await getChainConfig(chainId); | ||
const { feeAddr, euphratesFactoryAddr, wallet } = chainConfig; | ||
|
||
const euphratesFactory = EuphratesFactory__factory.connect(euphratesFactoryAddr!, wallet); | ||
|
||
return { euphratesFactory, feeAddr }; | ||
}; | ||
|
||
export const shouldRouteEuphrates = async (params: RouteParamsEuphrates) => { | ||
try { | ||
const { euphratesFactory, feeAddr } = await prepareRouteEuphrates(Mainnet.Acala); | ||
if (!EUPHRATES_POOLS.includes(params.poolId)) { | ||
throw new RelayerError(`euphrates poolId ${params.poolId} is not supported`, params); | ||
} | ||
|
||
const routerAddr = await euphratesFactory.callStatic.deployEuphratesRouter( | ||
feeAddr, | ||
params, | ||
EUPHRATES_ADDR, | ||
); | ||
|
||
return { | ||
shouldRoute: true, | ||
routerAddr, | ||
}; | ||
} catch (err) { | ||
return { | ||
shouldRoute: false, | ||
msg: err.message, | ||
}; | ||
} | ||
}; | ||
|
||
export const routeEuphrates = async (params: RouteParamsEuphrates) => { | ||
if (params.token === undefined) { | ||
throw new RelayerError('no token address provided for routeEuphrates', params); | ||
} | ||
|
||
const { euphratesFactory, feeAddr } = await prepareRouteEuphrates(Mainnet.Acala); | ||
const tx = await euphratesFactory.deployEuphratesRouterAndRoute( | ||
feeAddr, | ||
params, | ||
EUPHRATES_ADDR, | ||
params.token, | ||
); | ||
const receipt = await tx.wait(); | ||
|
||
return receipt.transactionHash; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DOT } from '@acala-network/contracts/utils/AcalaTokens'; | ||
import { HomaFactory__factory } from '@acala-network/asset-router/dist/typechain-types'; | ||
import { KSM } from '@acala-network/contracts/utils/KaruraTokens'; | ||
|
||
import { | ||
Mainnet, | ||
RouteParamsHoma, | ||
_populateRelayTx, | ||
_populateRouteTx, | ||
getChainConfig, | ||
getMainnetChainId, | ||
toAddr32, | ||
} from '../utils'; | ||
|
||
const prepareRouteHoma = async (chain: Mainnet) => { | ||
const chainId = getMainnetChainId(chain); | ||
const chainConfig = await getChainConfig(chainId); | ||
const { feeAddr, homaFactoryAddr, wallet } = chainConfig; | ||
|
||
const homaFactory = HomaFactory__factory.connect(homaFactoryAddr!, wallet); | ||
const routeToken = chain === Mainnet.Acala ? DOT : KSM; | ||
|
||
return { homaFactory, feeAddr, routeToken }; | ||
}; | ||
|
||
export const shouldRouteHoma = async ({ chain, destAddr }: RouteParamsHoma) => { | ||
try { | ||
const { homaFactory, feeAddr } = await prepareRouteHoma(chain); | ||
const routerAddr = await homaFactory.callStatic.deployHomaRouter( | ||
feeAddr, | ||
toAddr32(destAddr), | ||
); | ||
|
||
return { | ||
shouldRoute: true, | ||
routerAddr, | ||
}; | ||
} catch (err) { | ||
return { | ||
shouldRoute: false, | ||
msg: err.message, | ||
}; | ||
} | ||
}; | ||
|
||
export const routeHoma = async ({ chain, destAddr }: RouteParamsHoma) => { | ||
const { homaFactory, feeAddr, routeToken } = await prepareRouteHoma(chain); | ||
const tx = await homaFactory.deployHomaRouterAndRoute(feeAddr, toAddr32(destAddr), routeToken); | ||
const receipt = await tx.wait(); | ||
|
||
return receipt.transactionHash; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
export * from './relay'; | ||
export * from './route'; | ||
export * from './testTimeout'; | ||
export * from './getVersion'; | ||
export * from './wormhole'; | ||
export * from './xcm'; | ||
export * from './homa'; | ||
export * from './euphrates'; | ||
export * from './health'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.