-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redeeming functionalities for Womrhole
- Loading branch information
Showing
11 changed files
with
214 additions
and
14 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
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
28 changes: 28 additions & 0 deletions
28
packages/builder/src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
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,28 @@ | ||
import type { Address } from 'viem'; | ||
import { ContractConfig } from '../../../../../contract'; | ||
import type { MrlRedeemConfigBuilder } from '../../../../MrlBuilder.interfaces'; | ||
import { GMP_ABI } from './GmpAbi'; | ||
|
||
const module = 'GMP'; | ||
|
||
export const GMP_CONTRACT_ADDRESS = | ||
'0x0000000000000000000000000000000000000816'; | ||
|
||
export function Gmp() { | ||
return { | ||
wormholeTransferERC20: (): MrlRedeemConfigBuilder => ({ | ||
build: ({ bytes }) => { | ||
const hex = | ||
`0x${Buffer.from(bytes as Uint8Array).toString('hex')}` as Address; | ||
|
||
return new ContractConfig({ | ||
address: GMP_CONTRACT_ADDRESS, | ||
abi: GMP_ABI, | ||
args: [hex], | ||
func: 'wormholeTransferERC20', | ||
module, | ||
}); | ||
}, | ||
}), | ||
}; | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/builder/src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts
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,15 @@ | ||
export const GMP_ABI = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'bytes', | ||
name: 'vaa', | ||
type: 'bytes', | ||
}, | ||
], | ||
name: 'wormholeTransferERC20', | ||
outputs: [], | ||
stateMutability: 'nonpayable', | ||
type: 'function', | ||
}, | ||
] as const; |
1 change: 1 addition & 0 deletions
1
packages/builder/src/mrl/providers/wormhole/contract/Gmp/index.ts
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 @@ | ||
export * from './Gmp'; |
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,7 +1,8 @@ | ||
import { Batch } from './Batch'; | ||
import { Gmp } from './Gmp'; | ||
import { TokenBridge } from './TokenBridge'; | ||
import { TokenBridgeRelayer } from './TokenBridgeRelayer'; | ||
|
||
export function contract() { | ||
return { Batch, TokenBridge, TokenBridgeRelayer }; | ||
return { Batch, Gmp, TokenBridge, TokenBridgeRelayer }; | ||
} |
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
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,49 @@ | ||
import { type ContractConfig, MrlBuilder } from '@moonbeam-network/xcm-builder'; | ||
import { EvmService, type EvmSigner } from '@moonbeam-network/xcm-sdk'; | ||
import type { EvmChain, EvmParachain } from '@moonbeam-network/xcm-types'; | ||
import { WormholeService } from '../services/wormhole'; | ||
|
||
export interface GetRedeemDataParams { | ||
txId: string; | ||
chain: EvmChain | EvmParachain; | ||
} | ||
|
||
export async function getRedeemData({ txId, chain }: GetRedeemDataParams) { | ||
// TODO this is just for wormhole | ||
const wh = WormholeService.create(chain); | ||
|
||
const vaa = await wh.getVaa(txId); | ||
const tokenTransfer = await wh.getTokenTransfer(vaa, txId); | ||
|
||
const isXcm = vaa.payloadName === 'TransferWithPayload'; | ||
|
||
return { | ||
vaa, | ||
tokenTransfer, | ||
async redeem(signer: EvmSigner) { | ||
const isComplete = await wh.isComplete(vaa, tokenTransfer); | ||
|
||
if (isComplete) { | ||
throw new Error('This transaction is already finalized in Wormhole'); | ||
} | ||
|
||
if (isXcm) { | ||
const bytes = await wh.getVaaBytes(vaa); | ||
|
||
const contract = MrlBuilder() | ||
.wormhole() | ||
.contract() | ||
.Gmp() | ||
.wormholeTransferERC20() | ||
.build({ bytes }) as ContractConfig; | ||
|
||
const evm = EvmService.create(chain); | ||
const hash = await evm.transfer(signer, contract); | ||
|
||
return hash; | ||
} | ||
|
||
return await wh.completeTransfer(tokenTransfer, signer); | ||
}, | ||
}; | ||
} |
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
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
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