Skip to content

Commit

Permalink
Release v0.11.7 (#189)
Browse files Browse the repository at this point in the history
* fix: toChain address validation

* chore: remove chain name to identifier converter

* chore: add integration test

* chore: add chain identifier validation with suggestions

* chore: add chain identifiers list

* chore: use chain identifiers for wrap

* chore: remove version bumping

* version bump

* chore: update changelog

* fix typo

* fix: github actions deps

* chore: improve unwrap

* chore: update chain ids

* bump version

* chore: update past changelog

* chore: update changelog

* fix: tests

* chore: revert unwrap function
  • Loading branch information
vladwulf authored Oct 26, 2022
1 parent 928ddf1 commit 68bec79
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 62 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.11.7] - 2022-OCTOBER-26

- updated supported chains list
- updated `getDepositAddressForNativeUnwrap` to expose intermediary deposit address
- removed salt argument from `getDepositAddressForNativeUnwrap` and `getDepositAddressForNativeWrap`
- use bytes32 `0x0` salt

## [0.11.6] - 2022-OCTOBER-17

- update `getDepositAddress` in `AxelarAssetTransfer` to use chain identifiers
- update `getDepositAddress` in `AxelarAssetTransfer` to verify source & destination chain and provide suggestion
- added chain identifiers list as object literal
- fixed destination address check bug
- added wrap/unwrap functionality

## [0.11.5] - 2022-OCTOBER-12

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelar-network/axelarjs-sdk",
"version": "0.11.6",
"version": "0.11.7",
"description": "The JavaScript SDK for Axelar Network",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
21 changes: 12 additions & 9 deletions src/chains/supported-chains-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,39 @@ export const CHAINS = {
OSMOSIS: "osmosis-4",
SEI: "sei",
AURORA: "aurora",
AVALANCHE: "avalanche",
AVALANCHE: "Avalanche",
BINANCE: "binance",
ETHEREUM: "ethereum-2",
FANTOM: "fantom",
MOONBEAM: "moonbeam",
POLYGON: "polygon",
FANTOM: "Fantom",
MOONBEAM: "Moonbeam",
POLYGON: "Polygon",
TERRA: "terra-3",
},
MAINNET: {
ASSETMANTLE: "assetmantle",
AVALANCHE: "avalanche",
AVALANCHE: "Avalanche",
AXELAR: "axelarnet",
BINANCE: "binance",
COMDEX: "comdex",
COSMOSHUB: "cosmoshub",
CRESCENT: "crescent",
ETHEREUM: "ethereum",
ETHEREUM: "Ethereum",
EVMOS: "evmos",
FANTOM: "fantom",
FANTOM: "Fantom",
FETCH: "fetch",
INJECTIVE: "injective",
JUNO: "juno",
KI: "ki",
KUJIRA: "kujira",
MOONBEAM: "moonbeam",
MOONBEAM: "Moonbeam",
OSMOSIS: "osmosis",
POLYGON: "polygon",
POLYGON: "Polygon",
REGEN: "regen",
SECRET: "secret",
STARGAZE: "stargaze",
TERRA: "terra-2",
EMONEY: "e-money",
AGORIC: "agoric",
UMEEE: "umee",
},
};
55 changes: 24 additions & 31 deletions src/libs/AxelarAssetTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import { v4 as uuidv4 } from "uuid";
import fetch from "cross-fetch";
import { CLIENT_API_GET_OTC, CLIENT_API_POST_TRANSFER_ASSET, OTC } from "../services/types";
import {
defaultAbiCoder,
getCreate2Address,
Interface,
keccak256,
solidityPack,
} from "ethers/lib/utils";

import { CLIENT_API_GET_OTC, CLIENT_API_POST_TRANSFER_ASSET, OTC } from "../services/types";
import { RestService, SocketService } from "../services";
import {
createWallet,
validateChainIdentifier,
validateDestinationAddressByChainName,
} from "../utils";

import { getConfigs } from "../constants";
import { AxelarAssetTransferConfig, Environment } from "./types";
import {
defaultAbiCoder,
getCreate2Address,
hexlify,
hexZeroPad,
Interface,
keccak256,
solidityPack,
} from "ethers/lib/utils";
import DepositReceiver from "../../artifacts/contracts/deposit-service/DepositReceiver.sol/DepositReceiver.json";
import ReceiverImplementation from "../../artifacts/contracts/deposit-service/ReceiverImplementation.sol/ReceiverImplementation.json";
import s3 from "./TransactionRecoveryApi/constants/s3";
import { loadChains } from "../chains";

import { constants } from "ethers";
const { HashZero } = constants;

export class AxelarAssetTransfer {
readonly environment: Environment;
Expand Down Expand Up @@ -53,19 +52,16 @@ export class AxelarAssetTransfer {
fromChain: string,
toChain: string,
destinationAddress: string,
refundAddress?: string,
salt?: number
refundAddress?: string
): Promise<string> {
const hexSalt = hexZeroPad(hexlify(salt || 0), 32);

refundAddress = refundAddress || (await this.getGasReceiverContractAddress(fromChain));
const { address } = await this.getDepositAddressFromRemote(
"wrap",
fromChain,
toChain,
destinationAddress,
refundAddress,
hexSalt
HashZero
);

const expectedAddress = await this.validateOfflineDepositAddress(
Expand All @@ -74,10 +70,10 @@ export class AxelarAssetTransfer {
toChain,
destinationAddress,
refundAddress,
hexSalt
HashZero
);

if (address !== expectedAddress) return "";
if (address !== expectedAddress) throw new Error("Deposit address mismatch");

return address;
}
Expand All @@ -86,19 +82,17 @@ export class AxelarAssetTransfer {
fromChain: string,
toChain: string,
destinationAddress: string,
refundAddress: string,
salt?: number
refundAddress?: string
): Promise<string> {
const hexSalt = hexZeroPad(hexlify(salt || 0), 32);

refundAddress = refundAddress || (await this.getGasReceiverContractAddress(fromChain));

const { address: unwrapAddress } = await this.getDepositAddressFromRemote(
"unwrap",
undefined,
toChain,
destinationAddress,
refundAddress,
hexSalt
HashZero
);

const expectedAddress = await this.validateOfflineDepositAddress(
Expand All @@ -107,19 +101,20 @@ export class AxelarAssetTransfer {
toChain,
destinationAddress,
refundAddress,
hexSalt
HashZero
);

if (unwrapAddress !== expectedAddress) return "";
if (unwrapAddress !== expectedAddress) throw new Error("Deposit address mismatch");

const realDepositAddress = await this.getDepositAddress(
const denom = await this.getERC20Denom(toChain);
const finalDepositAddress = await this.getDepositAddress(
fromChain,
toChain,
unwrapAddress,
await this.getERC20Denom(toChain)
denom
);

return realDepositAddress;
return finalDepositAddress;
}

async getDepositAddressFromRemote(
Expand Down Expand Up @@ -317,9 +312,7 @@ export class AxelarAssetTransfer {
async getERC20Denom(chainName: string): Promise<string> {
if (!this.evmDenomMap[chainName.toLowerCase()]) {
const staticInfo = await this.getStaticInfo();
console.log("staticInfo", staticInfo);
const denom = staticInfo.chains[chainName.toLowerCase()]?.nativeAsset[0];
console.log("denom", denom);
if (denom) {
this.evmDenomMap[chainName.toLowerCase()] = denom;
}
Expand Down
18 changes: 7 additions & 11 deletions src/libs/test/AxelarAssetTransfer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { hexlify, hexZeroPad } from "ethers/lib/utils";
import { CLIENT_API_GET_OTC, CLIENT_API_POST_TRANSFER_ASSET } from "../..";
import { CHAINS, CLIENT_API_GET_OTC, CLIENT_API_POST_TRANSFER_ASSET } from "../..";
import { AxelarAssetTransfer } from "../AxelarAssetTransfer";
import { Environment, EvmChain } from "../types";
import {
Expand Down Expand Up @@ -318,8 +318,8 @@ describe("AxelarAssetTransfer", () => {
});

describe("when called", () => {
const fromChain = "terra";
const toChain = "avalanche";
const fromChain = CHAINS.TESTNET.TERRA;
const toChain = CHAINS.TESTNET.AVALANCHE;
const depositAddress = "0xF16DfB26e1FEc993E085092563ECFAEaDa7eD7fD";
const asset = "uusd";
let response: any;
Expand Down Expand Up @@ -392,23 +392,20 @@ describe("AxelarAssetTransfer", () => {
EvmChain.AVALANCHE,
EvmChain.FANTOM,
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d",
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d",
0
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d"
)
).resolves.toBe(address);
});
});
describe("getDepositAddressForNativeUnwrap", () => {
let unwrapAddress: string;
let realDepositAddress: string;
beforeEach(async () => {
unwrapAddress = "0x34bd65b158b6b4cc539388842cb2447c0a28acc0";
realDepositAddress = "realDepositAddress";
jest.clearAllMocks();
jest
.spyOn(bridge, "getDepositAddressFromRemote")
.mockResolvedValue({ address: unwrapAddress });
jest.spyOn(bridge, "getDepositAddress").mockResolvedValue(realDepositAddress);
jest.spyOn(bridge, "getDepositAddress").mockResolvedValue(unwrapAddress);
jest
.spyOn(bridge, "getDepositServiceContractAddress")
.mockResolvedValue("0xc1DCb196BA862B337Aa23eDA1Cb9503C0801b955");
Expand All @@ -420,10 +417,9 @@ describe("AxelarAssetTransfer", () => {
EvmChain.AVALANCHE,
EvmChain.FANTOM,
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d",
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d",
0
"0x74Ccd7d9F1F40417C6F7fD1151429a2c44c34e6d"
)
).resolves.toBe(realDepositAddress);
).resolves.toBe(unwrapAddress);
expect(bridge.getDepositAddress).toHaveBeenCalledWith(
EvmChain.AVALANCHE,
EvmChain.FANTOM,
Expand Down
10 changes: 7 additions & 3 deletions src/libs/test/AxelarQueryAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TransferFeeResponse,
} from "@axelar-network/axelarjs-types/axelar/nexus/v1beta1/query";
import { ethers } from "ethers";
import { CHAINS } from "../../chains";
import { AxelarQueryAPI } from "../AxelarQueryAPI";
import { Environment, EvmChain, GasToken } from "../types";

Expand Down Expand Up @@ -80,8 +81,8 @@ describe("AxelarQueryAPI", () => {

test("It should return estimated gas amount that makes sense for native token", async () => {
const gasAmount = await api.estimateGasFee(
EvmChain.AVALANCHE,
EvmChain.ETHEREUM,
CHAINS.TESTNET.AVALANCHE as EvmChain,
CHAINS.TESTNET.ETHEREUM as EvmChain,
GasToken.AVAX
);

Expand All @@ -92,7 +93,10 @@ describe("AxelarQueryAPI", () => {

describe("getNativeGasBaseFee", () => {
test("It should return base fee for a certain source chain / destination chain combination", async () => {
const gasResult = await api.getNativeGasBaseFee(EvmChain.AVALANCHE, EvmChain.ETHEREUM);
const gasResult = await api.getNativeGasBaseFee(
CHAINS.TESTNET.AVALANCHE as EvmChain,
CHAINS.TESTNET.ETHEREUM as EvmChain
);
expect(gasResult.success).toBeTruthy();
expect(gasResult.baseFee).toBeDefined();
expect(gasResult.error).toBeUndefined();
Expand Down
46 changes: 46 additions & 0 deletions test/e2e/testnet/native-assets.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { AxelarAssetTransfer } from "../../../src";

describe("AxelarAssetTransfer", () => {
jest.setTimeout(20000);
let sdk: AxelarAssetTransfer;

beforeAll(() => {
sdk = new AxelarAssetTransfer({
environment: "testnet",
});
});

describe("getDepositAddressForNativeWrap()", () => {
let address: string;
beforeAll(async () => {
address = await sdk.getDepositAddressForNativeWrap(
"avalanche",
"ethereum-2",
"0xA57ADCE1d2fE72949E4308867D894CD7E7DE0ef2"
);
});

it("should get native deposit address", () => {
expect(address).toBeTruthy();
console.log({
address,
});
});
});

describe("getDepositAddressForNativeUnwrap()", () => {
let depositAddress: string;
beforeAll(async () => {
const result = await sdk.getDepositAddressForNativeUnwrap(
"moonbeam",
"avalanche",
"0xA57ADCE1d2fE72949E4308867D894CD7E7DE0ef2"
);
depositAddress = result;
});

it("should get native deposit address", () => {
expect(depositAddress).toBeTruthy();
});
});
});
3 changes: 1 addition & 2 deletions test/integration/asset-wrap.integration-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ describe("Asset Wrap", () => {
EvmChain.ETHEREUM,
EvmChain.MOONBEAM,
"0xa411977dd24F1547065C6630E468a43275cB4d7f",
"",
undefined
""
);
});

Expand Down
10 changes: 5 additions & 5 deletions test/integration/deposit-address/evm-cosmos.integration-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { AxelarAssetTransfer, CHAINS } from "../../../src";
jest.setTimeout(20000);

const sdk = new AxelarAssetTransfer({
environment: "testnet",
environment: "mainnet",
});
const cosmosAddress = "osmo1x3z2vepjd7fhe30epncxjrk0lehq7xdqe8ltsn";
const evmAsset = "uausdc";
const cosmosAddress = "terra1u8xlzsfuxe0lv6u2ws2zymrnnlc9pmyynu7pym";
const evmAsset = "uusdc";

describe("EVM - COSMOS", () => {
describe("getDepositAddress()", () => {
let depositAddress: string;

beforeAll(async () => {
depositAddress = await sdk.getDepositAddress(
CHAINS.TESTNET.AVALANCHE,
CHAINS.TESTNET.OSMOSIS,
CHAINS.MAINNET.AVALANCHE,
CHAINS.MAINNET.TERRA,
cosmosAddress,
evmAsset
);
Expand Down
Loading

0 comments on commit 68bec79

Please sign in to comment.