Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 8cc52e0

Browse files
fix: similar interface for substrate and evm transfers (#570)
## Description Change `destinationAddress` to `recipientAddress` in substrate transfers as well as `amount` to `transferAmount` to match `evm` ## How Has This Been Tested? Testing details. Updated existing unit tests ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [X] I have ensured that all acceptance criteria (or expected behavior) from issue are met - [X] I have added tests to cover my changes. - [X] I have ensured that all the checks are passing and green, I've signed the CLA bot
1 parent 0f9af9a commit 8cc52e0

File tree

7 files changed

+26
-29
lines changed

7 files changed

+26
-29
lines changed

examples/evm-to-evm-non-fungible-transfer/src/transfer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
Eip1193Provider,
3-
Environment,
4-
getSygmaScanLink,
5-
} from "@buildwithsygma/core";
1+
import { Eip1193Provider, getSygmaScanLink } from "@buildwithsygma/core";
62
import {
73
createNonFungibleAssetTransfer,
84
NonFungibleTransferParams,

examples/substrate-to-evm-fungible-transfer/src/transfer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const substrateTransfer = async (): Promise<void> => {
4444
sourceAddress: account.address,
4545
resource: RESOURCE_ID,
4646
amount: BigInt(1) * BigInt(1e18),
47-
destinationAddress: RECIPIENT_ADDRESS,
47+
recipientAddress: RECIPIENT_ADDRESS,
4848
environment: process.env.SYGMA_ENV,
4949
};
5050

packages/substrate/src/__test__/fungible.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('SubstrateFungibleAssetTransfer', () => {
3030
sourceNetworkProvider: api,
3131
resource: '0x0000000000000000000000000000000000000000000000000000000000000300',
3232
amount: BigInt(100),
33-
destinationAddress: '0x98729c03c4D5e820F5e8c45558ae07aE63F97461',
33+
recipientAddress: '0x98729c03c4D5e820F5e8c45558ae07aE63F97461',
3434
environment: Environment.LOCAL,
3535
};
3636
});
@@ -43,16 +43,16 @@ describe('SubstrateFungibleAssetTransfer', () => {
4343
test('should set constructor values', async () => {
4444
const transfer = await createSubstrateFungibleAssetTransfer(transferRequest);
4545

46-
expect(transfer.amount).toBe(BigInt(100));
46+
expect(transfer.transferAmount).toBe(BigInt(100));
4747
expect(transfer.sourceNetworkProvider).toBe(transfer.sourceNetworkProvider);
48-
expect(transfer.destinationAddress).toBe(transferRequest.destinationAddress);
48+
expect(transfer.recipientAddress).toBe(transferRequest.recipientAddress);
4949
});
5050

5151
test('should throw an error if destination address is Invalid', async () => {
5252
const invalidDestinationAddress = 'someAddress';
5353
const transfer = createSubstrateFungibleAssetTransfer({
5454
...transferRequest,
55-
destinationAddress: invalidDestinationAddress,
55+
recipientAddress: invalidDestinationAddress,
5656
});
5757

5858
await expect(() => transfer).rejects.toThrow('Invalid EVM Address');
@@ -63,7 +63,7 @@ describe('SubstrateFungibleAssetTransfer', () => {
6363
test('should set another EVM destination address', async () => {
6464
const transfer = await createSubstrateFungibleAssetTransfer(transferRequest);
6565
transfer.setDestinationAddress('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
66-
expect(transfer.destinationAddress).toBe('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
66+
expect(transfer.recipientAddress).toBe('0x742d35Cc6634C0532925a3b844Bc454e4438f44e');
6767
});
6868

6969
test('should not set an invalid destination address', async () => {

packages/substrate/src/fungible.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface SubstrateAssetTransferRequest extends BaseTransferParams {
2626
sourceAddress: string;
2727
sourceNetworkProvider: ApiPromise;
2828
amount: bigint;
29-
destinationAddress: string;
29+
recipientAddress: string;
3030
}
3131

3232
export async function createSubstrateFungibleAssetTransfer(
@@ -39,18 +39,18 @@ export async function createSubstrateFungibleAssetTransfer(
3939
}
4040

4141
class SubstrateFungibleAssetTransfer extends BaseTransfer {
42-
amount: bigint;
43-
destinationAddress: string = '';
42+
transferAmount: bigint;
43+
recipientAddress: string = '';
4444
sourceNetworkProvider: ApiPromise;
4545

4646
constructor(transfer: SubstrateAssetTransferRequest, config: Config) {
4747
super(transfer, config);
48-
this.amount = transfer.amount;
48+
this.transferAmount = transfer.amount;
4949
this.sourceNetworkProvider = transfer.sourceNetworkProvider;
5050
const environment = transfer.environment ?? Environment.MAINNET;
5151

52-
if (isValidAddressForNetwork(environment, transfer.destinationAddress, this.destination.type))
53-
this.destinationAddress = transfer.destinationAddress;
52+
if (isValidAddressForNetwork(environment, transfer.recipientAddress, this.destination.type))
53+
this.recipientAddress = transfer.recipientAddress;
5454
}
5555

5656
public getSourceNetworkProvider(): ApiPromise {
@@ -62,7 +62,7 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
6262
* @param {bigint} amount
6363
*/
6464
setAmount(amount: bigint): void {
65-
this.amount = amount;
65+
this.transferAmount = amount;
6666
}
6767

6868
/**
@@ -71,7 +71,7 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
7171
*/
7272
setDestinationAddress(destinationAddress: string): void {
7373
if (isValidAddressForNetwork(this.environment, destinationAddress, this.destination.type))
74-
this.destinationAddress = destinationAddress;
74+
this.recipientAddress = destinationAddress;
7575
}
7676

7777
/**
@@ -80,7 +80,7 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
8080
* @returns {Promise<SubstrateFee>}
8181
*/
8282
async getFee(amount?: bigint): Promise<SubstrateFee> {
83-
if (amount) this.amount = amount;
83+
if (amount) this.transferAmount = amount;
8484

8585
const resource = this.resource as SubstrateResource;
8686

@@ -99,7 +99,7 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
9999
);
100100
case FeeHandlerType.PERCENTAGE:
101101
return await getPercentageFee(this.sourceNetworkProvider, {
102-
details: { amount: this.amount.toString(), recipient: this.destinationAddress },
102+
details: { amount: this.transferAmount.toString(), recipient: this.recipientAddress },
103103
from: this.source,
104104
resource,
105105
sender: '',
@@ -118,7 +118,7 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
118118

119119
// Native token balance check
120120
if ([FeeHandlerType.BASIC].includes(fee.type)) {
121-
const amountBigNumber = new BN(this.amount.toString());
121+
const amountBigNumber = new BN(this.transferAmount.toString());
122122
const balance = await getNativeTokenBalance(this.sourceNetworkProvider, this.sourceAddress);
123123

124124
if (new BN(balance.free).lt(amountBigNumber)) {
@@ -161,9 +161,9 @@ class SubstrateFungibleAssetTransfer extends BaseTransfer {
161161
this.environment,
162162
this.sourceNetworkProvider,
163163
resource.xcmMultiAssetId,
164-
this.amount.toString(),
164+
this.transferAmount.toString(),
165165
this.destination.id.toString(),
166-
this.destinationAddress,
166+
this.recipientAddress,
167167
);
168168
}
169169
}

packages/substrate/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './fungible.js';
22
export * from './utils/index.js';
3+
export * from './types.js';

packages/utils/src/__test__/liquidity.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const mockedTransferEVM = {
4747
};
4848

4949
const mockedTransferSubstrate = {
50-
amount: 0n,
50+
transferAmount: 0n,
5151
resource: mockedResource,
5252
config: {
5353
findDomainConfig: jest.fn(),
@@ -128,7 +128,7 @@ describe('hasEnoughLiquidity - substrate', () => {
128128
});
129129

130130
it('should return true if there is enough liquidity', async () => {
131-
mockedTransferSubstrate.amount = BigInt(5);
131+
mockedTransferSubstrate.transferAmount = BigInt(5);
132132

133133
const isEnough = await hasEnoughLiquidity(
134134
mockedTransferSubstrate as unknown as Awaited<ReturnType<typeof createFungibleAssetTransfer>>,
@@ -138,7 +138,7 @@ describe('hasEnoughLiquidity - substrate', () => {
138138
expect(isEnough).toEqual(true);
139139
});
140140
it('should return false if there isnt enough liquidity', async () => {
141-
mockedTransferSubstrate.amount = BigInt(10);
141+
mockedTransferSubstrate.transferAmount = BigInt(10);
142142

143143
const isEnough = await hasEnoughLiquidity(
144144
mockedTransferSubstrate as unknown as Awaited<ReturnType<typeof createFungibleAssetTransfer>>,

packages/utils/src/liquidity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export async function hasEnoughLiquidity(
6464
);
6565

6666
return (
67-
(transfer as Awaited<ReturnType<typeof createSubstrateFungibleAssetTransfer>>).amount <=
68-
substrateHandlerBalance
67+
(transfer as Awaited<ReturnType<typeof createSubstrateFungibleAssetTransfer>>)
68+
.transferAmount <= substrateHandlerBalance
6969
);
7070
}
7171
// TODO: Bitcoin?

0 commit comments

Comments
 (0)