Skip to content

Instantly share code, notes, and snippets.

const { Ed25519Keypair } = require('@mysten/sui/keypairs/ed25519');
const { toB64 } = require('@mysten/sui/utils');
function compareUint8Arrays(a, b) {
for (let i = 0; i < a.length && i < b.length; i++) {
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
return a.length - b.length;
}
@npty
npty / getTransferFee.ts
Created July 16, 2024 10:01
getTransferFee example for axelarjs v2
import { createAxelarQueryClient } from "@axelarjs/cosmos";
import { AXELAR_RPC_URLS } from "@axelarjs/core";
async function getTransferFee() {
const client = await createAxelarQueryClient(AXELAR_RPC_URLS.testnet);
const response = await client.nexus.transferFee({
amount: "1000000",
destinationChain: "ethereum",
sourceChain: "avalanche",
});
@npty
npty / roundtrip.js
Created March 20, 2024 09:07
axelar-local-dev roundtrip call test
import { createNetwork, relay } from "@axelar-network/axelar-local-dev";
async function main() {
// Initialize an Ethereum network
const eth = await createNetwork({
name: "Ethereum",
});
// Deploy USDC token on the Ethereum network
await eth.deployToken("USDC", "aUSDC", 6, BigInt(100_000e6));
@npty
npty / approved.json
Last active July 20, 2022 08:53
Axelarscan searchGMP api response
{
"data": [
{
"call": {
"id": "0x63ae92b744ba628a9b2e669f7c47f98a98e6126cf8dcf4519ce71ecc3905c682_1_12",
"chain": "avalanche",
"transaction": {
"hash": "0x63ae92b744ba628a9b2e669f7c47f98a98e6126cf8dcf4519ce71ecc3905c682",
"type": 2,
"accessList": [],
@npty
npty / guide-trade-send.md
Last active June 9, 2022 00:33
A sample code to call `sendTrade` function in SquidSwapExecutable contract.

The SquidSwapExecutable address on ropsten is 0xAAF36440Fc91AC239E0C086bC44993d2337446F2

The contract supports the following scenario:

  1. Swap TokenA to TokenB at the source chain via a router contract e.g. UniswapRouter
  2. Send TokenB to the Axelar gateway contract.

Note:

  1. TokenB must be a cross-chain token. All supported tokens can be referred from here https://docs.axelar.dev/resources/testnet
  2. TokenA and TokenB are erc20
  1. Run the following curl in shell script.
curl -X GET "https://api.covalenthq.com/v1/1/events/address/0x11111112542D85B3EF69AE05771c2dCCff4fAa26/?starting-block=11442150&ending-block=12442150&page-number=2&key=ckey_75720a8fd64c4f6f9c6acbabaf9" \
 -H "Accept: application/json"  | jq .
  1. The API returned successfully, but there's no pagination object.

Note: You can also pass the pagination params e.g. page-size or page-number, but there's still no pagination object.

@npty
npty / index.js
Last active May 21, 2021 10:03
biggest-swap-03
const Web3 = require('web3')
// The most common geth rpc is infura.
const GETH_RPC_ENDPOINT = "YOUR_GETH_RPC_ENDPOINT"
// First block on 2021-03-16 on Ethereum
const fromBlock = "12046295"
// 1Inch's AggregatorRouterV3 contract
@npty
npty / index.js
Last active May 21, 2021 09:57
biggest-swap-02
const Web3 = require('web3')
// The most common geth rpc is infura.
const GETH_RPC_ENDPOINT = "YOUR_GETH_RPC_ENDPOINT"
// First block on 2021-03-16 on Ethereum
const fromBlock = "12046295"
// 1Inch's AggregatorRouterV3 contract
const routerV3 = "0x11111112542D85B3EF69AE05771c2dCCff4fAa26"
@npty
npty / index.js
Last active May 21, 2021 09:59
biggest-swap-01
const Web3 = require('web3')
const routerAbi = require('./abi/router.json')
// The most common geth rpc is infura.
const GETH_RPC_ENDPOINT = "YOUR_GETH_RPC_ENDPOINT"
// First block on 2021-03-16 on Ethereum
const fromBlock = "12046295"
// 1Inch's AggregatorRouterV3 contract
@npty
npty / result.js
Last active May 16, 2021 09:50
Example code for Covalent article 5/5
/** Ethereum Chain **/
// Picking random address from https://etherscan.io/
getSwapTransactions('1', '0x6b873dedab01e217b964d1786ecad7f4ee77fbd8')
// Output for Ethereum Chain
Swapped 218024.165017 USDC -> 15912.620260763577 RAD (0x47892d5f5526462244278a55d6b4c94b39c93e485ede8bb668664c9da5f75e08)
Swapped 221395.535603 USDC -> 17975.98032142739 RAD (0x58e4aa8ef3ed5e851161e6f174011a47641938cec5b89d29940ee02b26c2cfa8)
Swapped 43529.645353 USDC -> 3584.958088860996 RAD (0x2f88838acb274c5cf0fcc529dc7b587644192706a1218cdbb5b433c6047be59c)
Swapped 1000 OCC -> 1046.4886117345636 RAD (0xffa5e832ba5b08c9e4dbdf8be20230190eeb21132c6fb42b421ff6169b7bd809)