Skip to content

Commit

Permalink
Finished main logic for wormhole builder
Browse files Browse the repository at this point in the history
  • Loading branch information
ekenigs committed Aug 13, 2024
1 parent 2aa7f35 commit 601b196
Show file tree
Hide file tree
Showing 6 changed files with 557 additions and 21 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"metadatas",
"mnemonic",
"moonbase",
"moonchain",
"moonriver",
"multiasset",
"multicurrencies",
Expand Down
36 changes: 36 additions & 0 deletions packages/builder/fixtures/builderParamsMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import {
AssetAmount,
ChainAsset,
Ecosystem,
EvmChain,
EvmParachain,
Parachain,
} from '@moonbeam-network/xcm-types';
import {
ExtrinsicConfigBuilderPrams,
MrlExtrinsicConfigBuilderPrams,
} from '../src/extrinsic';
import { WormholeConfigBuilderPrams } from '../src/wormhole';

export const apiMock = {
tx: {
Expand Down Expand Up @@ -86,6 +88,21 @@ export const moonbaseAlphaMock = new EvmParachain({
ws: ['wss://wss.api.moonbase.moonbeam.network'],
});

export const fantomTestnet = new EvmChain({
assets: [testChainAsset, testChainAsset2],
ecosystem: Ecosystem.AlphanetRelay,
explorer: 'https://testnet.ftmscan.com',
id: 4_002,
isTestChain: true,
key: 'fantom-testnet',
name: 'Fantom Testnet',
nativeAsset: test,
rpc: 'https://rpc.testnet.fantom.network',
wh: {
name: 'Fantom',
},
});

export const buildParamsMock: ExtrinsicConfigBuilderPrams = {
asset: testAssetAmount,
destination: moonbaseAlphaMock,
Expand Down Expand Up @@ -148,3 +165,22 @@ export const mrlBuildParamsMock2: MrlExtrinsicConfigBuilderPrams = {
},
},
};

export const wormholeConfigBuilderPrams: WormholeConfigBuilderPrams = {
asset: testAssetAmount,
destination: alphanetAssetHubMock,
destinationAddress: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY',
moonChain: moonbaseAlphaMock,
source: fantomTestnet,
sourceAddress: '0xeF46c7649270C912704fB09B75097f6E32208b85',
};

export const wormholeToMoonchainConfigBuilderPrams: WormholeConfigBuilderPrams =
{
asset: testAssetAmount,
destination: moonbaseAlphaMock,
destinationAddress: '0x98891e5FD24Ef33A488A47101F65D212Ff6E650E',
moonChain: moonbaseAlphaMock,
source: fantomTestnet,
sourceAddress: '0xeF46c7649270C912704fB09B75097f6E32208b85',
};
222 changes: 222 additions & 0 deletions packages/builder/src/extrinsic/Erc20ABI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
export const ERC20_ABI = [
{
constant: true,
inputs: [],
name: 'name',
outputs: [
{
name: '',
type: 'string',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{
name: '_spender',
type: 'address',
},
{
name: '_value',
type: 'uint256',
},
],
name: 'approve',
outputs: [
{
name: '',
type: 'bool',
},
],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'totalSupply',
outputs: [
{
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{
name: '_from',
type: 'address',
},
{
name: '_to',
type: 'address',
},
{
name: '_value',
type: 'uint256',
},
],
name: 'transferFrom',
outputs: [
{
name: '',
type: 'bool',
},
],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'decimals',
outputs: [
{
name: '',
type: 'uint8',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [
{
name: '_owner',
type: 'address',
},
],
name: 'balanceOf',
outputs: [
{
name: 'balance',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'symbol',
outputs: [
{
name: '',
type: 'string',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
constant: false,
inputs: [
{
name: '_to',
type: 'address',
},
{
name: '_value',
type: 'uint256',
},
],
name: 'transfer',
outputs: [
{
name: '',
type: 'bool',
},
],
payable: false,
stateMutability: 'nonpayable',
type: 'function',
},
{
constant: true,
inputs: [
{
name: '_owner',
type: 'address',
},
{
name: '_spender',
type: 'address',
},
],
name: 'allowance',
outputs: [
{
name: '',
type: 'uint256',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{
payable: true,
stateMutability: 'payable',
type: 'fallback',
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: 'owner',
type: 'address',
},
{
indexed: true,
name: 'spender',
type: 'address',
},
{
indexed: false,
name: 'value',
type: 'uint256',
},
],
name: 'Approval',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: true,
name: 'from',
type: 'address',
},
{
indexed: true,
name: 'to',
type: 'address',
},
{
indexed: false,
name: 'value',
type: 'uint256',
},
],
name: 'Transfer',
type: 'event',
},
] as const;
29 changes: 29 additions & 0 deletions packages/builder/src/wormhole/WormholeBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// eslint-disable-next-line import/no-extraneous-dependencies
import { describe, expect, it } from 'vitest';

import {
wormholeConfigBuilderPrams,
wormholeToMoonchainConfigBuilderPrams,
} from '../../fixtures';
import { WormholeBuilder } from './WormholeBuilder';

describe('wormholeBuilder', () => {
describe('tokenTransfer with isAutomatic=true', () => {
const transfer = WormholeBuilder().tokenTransfer({ isAutomatic: true });

it('should be correct config', () => {
expect(transfer.build(wormholeConfigBuilderPrams)).toMatchSnapshot();
});
});

describe('tokenTransfer with isAutomatic=false', () => {
const transfer = WormholeBuilder().tokenTransfer({ isAutomatic: false });

it('should be correct config to moon chain', () => {
expect(
transfer.build(wormholeToMoonchainConfigBuilderPrams),
).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 601b196

Please sign in to comment.