Skip to content

Commit

Permalink
update with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Rihyx committed Mar 27, 2024
2 parents 82ce0a9 + 12512b8 commit e3a8005
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 44 deletions.
5 changes: 0 additions & 5 deletions .changeset/new-tools-move.md

This file was deleted.

6 changes: 3 additions & 3 deletions examples/sdk-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"author": "",
"license": "MIT",
"dependencies": {
"@moonbeam-network/xcm-config": "2.0.4",
"@moonbeam-network/xcm-sdk": "2.0.6",
"@moonbeam-network/xcm-utils": "2.0.1"
"@moonbeam-network/xcm-config": "2.0.5",
"@moonbeam-network/xcm-sdk": "2.0.7",
"@moonbeam-network/xcm-utils": "2.0.2"
},
"devDependencies": {
"bun": "^1.0.21"
Expand Down
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @moonbeam-network/xcm-builder

## 2.0.2

### Patch Changes

- Updated dependencies [[`3ade51ff0ef5acc4a6f84391159d3652cd6ee792`](https://github.com/moonbeam-foundation/xcm-sdk/commit/3ade51ff0ef5acc4a6f84391159d3652cd6ee792)]:
- @moonbeam-network/xcm-utils@2.0.2
- @moonbeam-network/xcm-types@2.0.2

## 2.0.1

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/builder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-builder",
"version": "2.0.1",
"version": "2.0.2",
"description": "Moonbeam XCM builder",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -50,8 +50,8 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-types": "2.0.1",
"@moonbeam-network/xcm-utils": "2.0.1",
"@moonbeam-network/xcm-types": "2.0.2",
"@moonbeam-network/xcm-utils": "2.0.2",
"big.js": "^6.2.1",
"type-fest": "^3.8.0"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @moonbeam-network/xcm-config

## 2.0.5

### Patch Changes

- Updated dependencies []:
- @moonbeam-network/xcm-builder@2.0.2
- @moonbeam-network/xcm-types@2.0.2

## 2.0.4

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-config",
"version": "2.0.4",
"version": "2.0.5",
"description": "All necessary configuration to transfer assets from Moonbeam, Moonriver, Moonbase to other parachains and back",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -50,8 +50,8 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-builder": "2.0.1",
"@moonbeam-network/xcm-types": "2.0.1"
"@moonbeam-network/xcm-builder": "2.0.2",
"@moonbeam-network/xcm-types": "2.0.2"
},
"peerDependencies": {
"@polkadot/types": "^10.10.1",
Expand Down
12 changes: 12 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @moonbeam-network/xcm-sdk

## 2.0.7

### Patch Changes

- [#223](https://github.com/moonbeam-foundation/xcm-sdk/pull/223) [`8a488f2823cd19dce651251e774998f4e97cc4bf`](https://github.com/moonbeam-foundation/xcm-sdk/commit/8a488f2823cd19dce651251e774998f4e97cc4bf) Thanks [@mmaurello](https://github.com/mmaurello)! - Inform required amount in error message for multi assets

- Updated dependencies [[`3ade51ff0ef5acc4a6f84391159d3652cd6ee792`](https://github.com/moonbeam-foundation/xcm-sdk/commit/3ade51ff0ef5acc4a6f84391159d3652cd6ee792)]:
- @moonbeam-network/xcm-utils@2.0.2
- @moonbeam-network/xcm-builder@2.0.2
- @moonbeam-network/xcm-types@2.0.2
- @moonbeam-network/xcm-config@2.0.5

## 2.0.6

### Patch Changes
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-sdk",
"version": "2.0.6",
"version": "2.0.7",
"description": "The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -51,10 +51,10 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-builder": "2.0.1",
"@moonbeam-network/xcm-config": "2.0.4",
"@moonbeam-network/xcm-types": "2.0.1",
"@moonbeam-network/xcm-utils": "2.0.1",
"@moonbeam-network/xcm-builder": "2.0.2",
"@moonbeam-network/xcm-config": "2.0.5",
"@moonbeam-network/xcm-types": "2.0.2",
"@moonbeam-network/xcm-utils": "2.0.2",
"big.js": "^6.2.1"
},
"peerDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/contract/contracts/Xtokens/Xtokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class Xtokens implements TransferContractInterface {
if (amount === 0n) {
return 0n;
}

/**
* Contract can throw an error if user balance is smaller than fee.
* Or if you try to send 0 as amount.
Expand Down
42 changes: 38 additions & 4 deletions packages/sdk/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import {
} from '@moonbeam-network/xcm-builder';
import {
AssetConfig,
DestinationFeeConfig,
FeeAssetConfig,
TransferConfig,
} from '@moonbeam-network/xcm-config';
import { AnyChain, AssetAmount } from '@moonbeam-network/xcm-types';
import { convertDecimals, toBigInt } from '@moonbeam-network/xcm-utils';
import {
convertDecimals,
toBigInt,
toDecimal,
} from '@moonbeam-network/xcm-utils';
import Big from 'big.js';
import { TransferContractInterface, createContract } from '../contract';
import { PolkadotService } from '../polkadot';
Expand Down Expand Up @@ -133,11 +138,17 @@ export async function getSourceData({
fee: destinationFee.amount,
feeAsset: chain.getAssetId(destinationFee),
});
const destinationFeeBalanceAmount = zeroDestinationFeeAmount.copyWith({
amount: destinationFeeBalance,
});

const fee = await getFee({
balance,
chain,
contract,
decimals: zeroFeeAmount.decimals,
destinationFeeBalanceAmount,
destinationFeeConfig: config.destinationFee,
evmSigner,
extrinsic,
feeConfig: config.fee,
Expand All @@ -149,9 +160,7 @@ export async function getSourceData({
const { existentialDeposit } = polkadot;
const feeAmount = zeroFeeAmount.copyWith({ amount: fee });
const feeBalanceAmount = zeroFeeAmount.copyWith({ amount: feeBalance });
const destinationFeeBalanceAmount = zeroDestinationFeeAmount.copyWith({
amount: destinationFeeBalance,
});

const minAmount = zeroAmount.copyWith({ amount: min });

const maxAmount = getMax({
Expand Down Expand Up @@ -211,6 +220,8 @@ export interface GetFeeParams {
evmSigner?: EvmSigner;
extrinsic?: ExtrinsicConfig;
feeConfig?: FeeAssetConfig;
destinationFeeConfig?: DestinationFeeConfig;
destinationFeeBalanceAmount?: AssetAmount;
polkadot: PolkadotService;
sourceAddress: string;
}
Expand All @@ -220,6 +231,8 @@ export async function getFee({
chain,
contract,
decimals,
destinationFeeConfig,
destinationFeeBalanceAmount,
evmSigner,
extrinsic,
feeConfig,
Expand All @@ -231,6 +244,27 @@ export async function getFee({
throw new Error('EVM Signer must be provided');
}

if (
destinationFeeConfig &&
destinationFeeBalanceAmount &&
typeof destinationFeeConfig.amount === 'number'
) {
const destinationFeeBalance = Number(
toDecimal(
destinationFeeBalanceAmount.amount,
destinationFeeBalanceAmount.decimals,
),
);
if (
destinationFeeBalance &&
destinationFeeConfig.amount > destinationFeeBalance
) {
throw new Error(
`Can't get a fee, make sure you have ${destinationFeeConfig?.amount} ${destinationFeeConfig?.asset.originSymbol} needed for fees in destination`,
);
}
}

return getContractFee(balance, contract, decimals, evmSigner);
}

Expand Down
7 changes: 7 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @moonbeam-network/xcm-types

## 2.0.2

### Patch Changes

- Updated dependencies [[`3ade51ff0ef5acc4a6f84391159d3652cd6ee792`](https://github.com/moonbeam-foundation/xcm-sdk/commit/3ade51ff0ef5acc4a6f84391159d3652cd6ee792)]:
- @moonbeam-network/xcm-utils@2.0.2

## 2.0.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-types",
"version": "2.0.1",
"version": "2.0.2",
"description": "Moonbeam XCM Types",
"scripts": {
"build": "tsup",
Expand Down Expand Up @@ -49,7 +49,7 @@
"types": "./build/index.d.ts",
"main": "./build/index.cjs",
"dependencies": {
"@moonbeam-network/xcm-utils": "2.0.1",
"@moonbeam-network/xcm-utils": "2.0.2",
"big.js": "^6.2.1",
"type-fest": "^3.8.0",
"viem": "^2.8.6"
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @moonbeam-network/xcm-utils

## 2.0.2

### Patch Changes

- [#211](https://github.com/moonbeam-foundation/xcm-sdk/pull/211) [`3ade51ff0ef5acc4a6f84391159d3652cd6ee792`](https://github.com/moonbeam-foundation/xcm-sdk/commit/3ade51ff0ef5acc4a6f84391159d3652cd6ee792) Thanks [@mmaurello](https://github.com/mmaurello)! - Add MRL types to polkadot API

## 2.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonbeam-network/xcm-utils",
"version": "2.0.1",
"version": "2.0.2",
"description": "Moonbeam XCM utilities",
"scripts": {
"build": "tsup",
Expand Down

0 comments on commit e3a8005

Please sign in to comment.