-
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.
Merge branch 'v3-next' of github.com:moonbeam-foundation/xcm-sdk into…
… mjm/connection-v3
- Loading branch information
Showing
12 changed files
with
242 additions
and
15 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
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
import { u8aToHex } from '@polkadot/util'; | ||
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 = u8aToHex(bytes); | ||
|
||
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
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 WormholeRedeemParams { | ||
txId: string; | ||
chain: EvmChain | EvmParachain; | ||
} | ||
|
||
export async function getRedeemData({ txId, chain }: WormholeRedeemParams) { | ||
// 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