@upcoming/multichain-library 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Constants.d.ts +8 -0
- package/dist/Constants.js +11 -0
- package/dist/GnosisBzzBalance.d.ts +3 -0
- package/dist/GnosisBzzBalance.js +34 -0
- package/dist/GnosisNativeBalance.d.ts +3 -0
- package/dist/GnosisNativeBalance.js +17 -0
- package/dist/GnosisNativeTransfer.d.ts +8 -0
- package/dist/GnosisNativeTransfer.js +29 -0
- package/dist/GnosisSwap.d.ts +18 -0
- package/dist/GnosisSwap.js +40 -0
- package/dist/GnosisTransactionCount.d.ts +2 -0
- package/dist/GnosisTransactionCount.js +26 -0
- package/dist/Settings.d.ts +8 -0
- package/dist/Settings.js +10 -0
- package/dist/SushiSwap.d.ts +29 -0
- package/dist/SushiSwap.js +11 -0
- package/dist/TokenPrice.d.ts +3 -0
- package/dist/TokenPrice.js +13 -0
- package/dist/Waiter.d.ts +4 -0
- package/dist/Waiter.js +44 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +56 -0
- package/package.json +28 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Constants = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
exports.Constants = {
|
|
6
|
+
nullAddress: '0x0000000000000000000000000000000000000000',
|
|
7
|
+
bzzGnosisAddress: '0xdbf3ea6f5bee45c02255b2c26a16f300502f68da',
|
|
8
|
+
ethereumChainId: 1,
|
|
9
|
+
gnosisChainId: 100,
|
|
10
|
+
daiDustAmount: cafe_utility_1.FixedPointNumber.fromDecimalString('0.01', 18)
|
|
11
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGnosisBzzBalance = getGnosisBzzBalance;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const Constants_1 = require("./Constants");
|
|
6
|
+
async function getGnosisBzzBalance(address, settings) {
|
|
7
|
+
address = address.toLowerCase();
|
|
8
|
+
if (address.startsWith('0x')) {
|
|
9
|
+
address = address.slice(2);
|
|
10
|
+
}
|
|
11
|
+
const payload = {
|
|
12
|
+
jsonrpc: '2.0',
|
|
13
|
+
id: 1,
|
|
14
|
+
method: 'eth_call',
|
|
15
|
+
params: [
|
|
16
|
+
{
|
|
17
|
+
from: Constants_1.Constants.nullAddress,
|
|
18
|
+
data: `0x70a08231000000000000000000000000${address}`,
|
|
19
|
+
to: Constants_1.Constants.bzzGnosisAddress
|
|
20
|
+
},
|
|
21
|
+
'latest'
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
const response = await fetch(settings.gnosisJsonRpc, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
body: JSON.stringify(payload),
|
|
28
|
+
signal: AbortSignal.timeout(settings.fetchTimeoutMillis)
|
|
29
|
+
});
|
|
30
|
+
const data = await response.json();
|
|
31
|
+
const object = cafe_utility_1.Types.asObject(data);
|
|
32
|
+
const balance = cafe_utility_1.Types.asHexString(object.result, { strictPrefix: true, uneven: true });
|
|
33
|
+
return new cafe_utility_1.FixedPointNumber(BigInt(balance), 16);
|
|
34
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGnosisNativeBalance = getGnosisNativeBalance;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
async function getGnosisNativeBalance(address, settings) {
|
|
6
|
+
const payload = { jsonrpc: '2.0', id: 1, method: 'eth_getBalance', params: [address, 'latest'] };
|
|
7
|
+
const response = await fetch(settings.gnosisJsonRpc, {
|
|
8
|
+
method: 'POST',
|
|
9
|
+
headers: { 'Content-Type': 'application/json' },
|
|
10
|
+
body: JSON.stringify(payload),
|
|
11
|
+
signal: AbortSignal.timeout(settings.fetchTimeoutMillis)
|
|
12
|
+
});
|
|
13
|
+
const data = await response.json();
|
|
14
|
+
const object = cafe_utility_1.Types.asObject(data);
|
|
15
|
+
const price = cafe_utility_1.Types.asHexString(object.result, { strictPrefix: true, uneven: true });
|
|
16
|
+
return new cafe_utility_1.FixedPointNumber(BigInt(price), 18);
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
2
|
+
export interface TransferGnosisNativeOptions {
|
|
3
|
+
amount: string | bigint;
|
|
4
|
+
originPrivateKey: `0x${string}`;
|
|
5
|
+
originAddress: `0x${string}`;
|
|
6
|
+
to: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
export declare function transferGnosisNative(options: TransferGnosisNativeOptions, settings: MultichainLibrarySettings): Promise<`0x${string}`>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferGnosisNative = transferGnosisNative;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const accounts_1 = require("viem/accounts");
|
|
7
|
+
const chains_1 = require("viem/chains");
|
|
8
|
+
const Constants_1 = require("./Constants");
|
|
9
|
+
const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
|
|
10
|
+
async function transferGnosisNative(options, settings) {
|
|
11
|
+
const account = (0, accounts_1.privateKeyToAccount)(options.originPrivateKey);
|
|
12
|
+
const client = (0, viem_1.createWalletClient)({
|
|
13
|
+
chain: chains_1.gnosis,
|
|
14
|
+
transport: (0, viem_1.http)(settings.gnosisJsonRpc)
|
|
15
|
+
});
|
|
16
|
+
return account
|
|
17
|
+
.signTransaction({
|
|
18
|
+
chain: Constants_1.Constants.gnosisChainId,
|
|
19
|
+
chainId: Constants_1.Constants.gnosisChainId,
|
|
20
|
+
account: options.originAddress,
|
|
21
|
+
gas: BigInt(21000),
|
|
22
|
+
gasPrice: BigInt(cafe_utility_1.Numbers.make('1 gwei')),
|
|
23
|
+
type: 'legacy',
|
|
24
|
+
to: options.to,
|
|
25
|
+
value: BigInt(options.amount),
|
|
26
|
+
nonce: await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings)
|
|
27
|
+
})
|
|
28
|
+
.then(signedTx => client.sendRawTransaction({ serializedTransaction: signedTx }));
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
2
|
+
export interface GnosisSwapAutoOptions {
|
|
3
|
+
amount: string | bigint;
|
|
4
|
+
originPrivateKey: `0x${string}`;
|
|
5
|
+
originAddress: `0x${string}`;
|
|
6
|
+
to: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
export declare function swapOnGnosisAuto(options: GnosisSwapAutoOptions, settings: MultichainLibrarySettings): Promise<`0x${string}`>;
|
|
9
|
+
export interface GnosisSwapCustomOptions {
|
|
10
|
+
originPrivateKey: `0x${string}`;
|
|
11
|
+
originAddress: `0x${string}`;
|
|
12
|
+
gas: bigint | string | number;
|
|
13
|
+
gasPrice: bigint | string | number;
|
|
14
|
+
to: `0x${string}`;
|
|
15
|
+
value: bigint | string | number;
|
|
16
|
+
data: `0x${string}`;
|
|
17
|
+
}
|
|
18
|
+
export declare function swapOnGnosisCustom(options: GnosisSwapCustomOptions, settings: MultichainLibrarySettings): Promise<`0x${string}`>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.swapOnGnosisAuto = swapOnGnosisAuto;
|
|
4
|
+
exports.swapOnGnosisCustom = swapOnGnosisCustom;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const accounts_1 = require("viem/accounts");
|
|
7
|
+
const chains_1 = require("viem/chains");
|
|
8
|
+
const Constants_1 = require("./Constants");
|
|
9
|
+
const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
|
|
10
|
+
const SushiSwap_1 = require("./SushiSwap");
|
|
11
|
+
async function swapOnGnosisAuto(options, settings) {
|
|
12
|
+
const quote = await (0, SushiSwap_1.getSushiSwapQuote)(options.amount.toString(), options.originAddress, options.to, settings);
|
|
13
|
+
return swapOnGnosisCustom({
|
|
14
|
+
originPrivateKey: options.originPrivateKey,
|
|
15
|
+
originAddress: options.originAddress,
|
|
16
|
+
gas: BigInt(quote.tx.gas),
|
|
17
|
+
gasPrice: BigInt(quote.tx.gasPrice),
|
|
18
|
+
to: quote.tx.to,
|
|
19
|
+
value: BigInt(quote.tx.value),
|
|
20
|
+
data: quote.tx.data
|
|
21
|
+
}, settings);
|
|
22
|
+
}
|
|
23
|
+
async function swapOnGnosisCustom(options, settings) {
|
|
24
|
+
const account = (0, accounts_1.privateKeyToAccount)(options.originPrivateKey);
|
|
25
|
+
const client = (0, viem_1.createWalletClient)({ chain: chains_1.gnosis, transport: (0, viem_1.http)(settings.gnosisJsonRpc) });
|
|
26
|
+
return account
|
|
27
|
+
.signTransaction({
|
|
28
|
+
chain: Constants_1.Constants.gnosisChainId,
|
|
29
|
+
chainId: Constants_1.Constants.gnosisChainId,
|
|
30
|
+
account: options.originAddress,
|
|
31
|
+
gas: BigInt(options.gas),
|
|
32
|
+
gasPrice: BigInt(options.gasPrice),
|
|
33
|
+
type: 'legacy',
|
|
34
|
+
to: options.to,
|
|
35
|
+
value: BigInt(options.value),
|
|
36
|
+
data: options.data,
|
|
37
|
+
nonce: await (0, GnosisTransactionCount_1.getGnosisTransactionCount)(options.originAddress, settings)
|
|
38
|
+
})
|
|
39
|
+
.then(signedTx => client.sendRawTransaction({ serializedTransaction: signedTx }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGnosisTransactionCount = getGnosisTransactionCount;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
async function getGnosisTransactionCount(address, settings) {
|
|
6
|
+
address = address.toLowerCase();
|
|
7
|
+
if (address.startsWith('0x')) {
|
|
8
|
+
address = address.slice(2);
|
|
9
|
+
}
|
|
10
|
+
const payload = {
|
|
11
|
+
jsonrpc: '2.0',
|
|
12
|
+
id: 1,
|
|
13
|
+
method: 'eth_getTransactionCount',
|
|
14
|
+
params: [`0x${address}`, 'latest']
|
|
15
|
+
};
|
|
16
|
+
const response = await fetch(settings.gnosisJsonRpc, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: JSON.stringify(payload),
|
|
20
|
+
signal: AbortSignal.timeout(settings.fetchTimeoutMillis)
|
|
21
|
+
});
|
|
22
|
+
const data = await response.json();
|
|
23
|
+
const object = cafe_utility_1.Types.asObject(data);
|
|
24
|
+
const count = cafe_utility_1.Types.asHexString(object.result, { strictPrefix: true, uneven: true });
|
|
25
|
+
return parseInt(count, 16);
|
|
26
|
+
}
|
package/dist/Settings.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultMultichainLibrarySettings = getDefaultMultichainLibrarySettings;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
function getDefaultMultichainLibrarySettings() {
|
|
6
|
+
return {
|
|
7
|
+
gnosisJsonRpc: 'https://xdai.fairdatasociety.org/',
|
|
8
|
+
fetchTimeoutMillis: cafe_utility_1.Dates.seconds(10)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
2
|
+
interface SushiToken {
|
|
3
|
+
address: `0x${string}`;
|
|
4
|
+
symbol: string;
|
|
5
|
+
name: string;
|
|
6
|
+
decimals: number;
|
|
7
|
+
}
|
|
8
|
+
interface SushiTx {
|
|
9
|
+
from: `0x${string}`;
|
|
10
|
+
to: `0x${string}`;
|
|
11
|
+
gas: string;
|
|
12
|
+
gasPrice: number;
|
|
13
|
+
data: `0x${string}`;
|
|
14
|
+
value: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SushiResponse {
|
|
17
|
+
status: 'Success' | string;
|
|
18
|
+
tokens: SushiToken[];
|
|
19
|
+
tokenFrom: number;
|
|
20
|
+
tokenTo: number;
|
|
21
|
+
swapPrice: number;
|
|
22
|
+
priceImpact: number;
|
|
23
|
+
amountIn: string;
|
|
24
|
+
assumedAmountOut: string;
|
|
25
|
+
gasSpent: number;
|
|
26
|
+
tx: SushiTx;
|
|
27
|
+
}
|
|
28
|
+
export declare function getSushiSwapQuote(amount: string, sender: string, recipient: string, settings: MultichainLibrarySettings): Promise<SushiResponse>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSushiSwapQuote = getSushiSwapQuote;
|
|
4
|
+
const Constants_1 = require("./Constants");
|
|
5
|
+
async function getSushiSwapQuote(amount, sender, recipient, settings) {
|
|
6
|
+
const tokenIn = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; // xDAI
|
|
7
|
+
const tokenOut = Constants_1.Constants.bzzGnosisAddress;
|
|
8
|
+
const response = await fetch(`https://api.sushi.com/swap/v7/100?tokenIn=${tokenIn}&tokenOut=${tokenOut}&amount=${amount}&maxSlippage=0.005&sender=${sender}&recipient=${recipient}&fee=0.0025&feeBy=output&feeReceiver=0xde7259893af7cdbc9fd806c6ba61d22d581d5667&simulate=true`, { signal: AbortSignal.timeout(settings.fetchTimeoutMillis) });
|
|
9
|
+
const data = await response.json();
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
2
|
+
export declare function getTokenPrice(tokenAddress: `0x${string}`, chainId: number, settings: MultichainLibrarySettings): Promise<number>;
|
|
3
|
+
export declare function getGnosisBzzTokenPrice(settings: MultichainLibrarySettings): Promise<number>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTokenPrice = getTokenPrice;
|
|
4
|
+
exports.getGnosisBzzTokenPrice = getGnosisBzzTokenPrice;
|
|
5
|
+
const Constants_1 = require("./Constants");
|
|
6
|
+
async function getTokenPrice(tokenAddress, chainId, settings) {
|
|
7
|
+
const response = await fetch(`https://api.relay.link/currencies/token/price?address=${tokenAddress}&chainId=${chainId}`, { signal: AbortSignal.timeout(settings.fetchTimeoutMillis) });
|
|
8
|
+
const data = (await response.json());
|
|
9
|
+
return data.price;
|
|
10
|
+
}
|
|
11
|
+
async function getGnosisBzzTokenPrice(settings) {
|
|
12
|
+
return getTokenPrice(Constants_1.Constants.bzzGnosisAddress, Constants_1.Constants.gnosisChainId, settings);
|
|
13
|
+
}
|
package/dist/Waiter.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
2
|
+
export declare function waitForGnosisBzzBalanceToIncrease(address: string, initialBalance: bigint, settings: MultichainLibrarySettings): Promise<void>;
|
|
3
|
+
export declare function waitForGnosisNativeBalanceToDecrease(address: `0x${string}`, initialBalance: bigint, settings: MultichainLibrarySettings): Promise<void>;
|
|
4
|
+
export declare function waitForGnosisNativeBalanceToIncrease(address: `0x${string}`, initialBalance: bigint, settings: MultichainLibrarySettings): Promise<void>;
|
package/dist/Waiter.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForGnosisBzzBalanceToIncrease = waitForGnosisBzzBalanceToIncrease;
|
|
4
|
+
exports.waitForGnosisNativeBalanceToDecrease = waitForGnosisNativeBalanceToDecrease;
|
|
5
|
+
exports.waitForGnosisNativeBalanceToIncrease = waitForGnosisNativeBalanceToIncrease;
|
|
6
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
7
|
+
const GnosisBzzBalance_1 = require("./GnosisBzzBalance");
|
|
8
|
+
const GnosisNativeBalance_1 = require("./GnosisNativeBalance");
|
|
9
|
+
async function waitForGnosisBzzBalanceToIncrease(address, initialBalance, settings) {
|
|
10
|
+
await cafe_utility_1.System.waitFor(async () => {
|
|
11
|
+
try {
|
|
12
|
+
const balance = await (0, GnosisBzzBalance_1.getGnosisBzzBalance)(address, settings);
|
|
13
|
+
return balance.value > initialBalance;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error(`Error fetching ${address} wallet BZZ balance:`, error);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}, { attempts: 20, waitMillis: cafe_utility_1.Dates.seconds(15) });
|
|
20
|
+
}
|
|
21
|
+
async function waitForGnosisNativeBalanceToDecrease(address, initialBalance, settings) {
|
|
22
|
+
await cafe_utility_1.System.waitFor(async () => {
|
|
23
|
+
try {
|
|
24
|
+
const balance = await (0, GnosisNativeBalance_1.getGnosisNativeBalance)(address, settings);
|
|
25
|
+
return balance.value < initialBalance;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error(`Error fetching ${address} wallet native balance:`, error);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}, { attempts: 20, waitMillis: cafe_utility_1.Dates.seconds(15) });
|
|
32
|
+
}
|
|
33
|
+
async function waitForGnosisNativeBalanceToIncrease(address, initialBalance, settings) {
|
|
34
|
+
await cafe_utility_1.System.waitFor(async () => {
|
|
35
|
+
try {
|
|
36
|
+
const balance = await (0, GnosisNativeBalance_1.getGnosisNativeBalance)(address, settings);
|
|
37
|
+
return balance.value > initialBalance;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error(`Error fetching ${address} wallet native balance:`, error);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}, { attempts: 20, waitMillis: cafe_utility_1.Dates.seconds(15) });
|
|
44
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FixedPointNumber } from 'cafe-utility';
|
|
2
|
+
import { TransferGnosisNativeOptions } from './GnosisNativeTransfer';
|
|
3
|
+
import { GnosisSwapAutoOptions, GnosisSwapCustomOptions } from './GnosisSwap';
|
|
4
|
+
import { MultichainLibrarySettings } from './Settings';
|
|
5
|
+
import { SushiResponse } from './SushiSwap';
|
|
6
|
+
export declare class MultichainLibrary {
|
|
7
|
+
settings: MultichainLibrarySettings;
|
|
8
|
+
constructor(settings?: Partial<MultichainLibrarySettings>);
|
|
9
|
+
getGnosisBzzBalance(address: string): Promise<FixedPointNumber>;
|
|
10
|
+
getGnosisNativeBalance(address: `0x${string}`): Promise<FixedPointNumber>;
|
|
11
|
+
getTokenPrice(tokenAddress: `0x${string}`, chainId: number): Promise<number>;
|
|
12
|
+
getGnosisBzzTokenPrice(): Promise<number>;
|
|
13
|
+
transferGnosisNative(options: TransferGnosisNativeOptions): Promise<`0x${string}`>;
|
|
14
|
+
waitForGnosisBzzBalanceToIncrease(address: string, initialBalance: bigint): Promise<void>;
|
|
15
|
+
waitForGnosisNativeBalanceToDecrease(address: `0x${string}`, initialBalance: bigint): Promise<void>;
|
|
16
|
+
waitForGnosisNativeBalanceToIncrease(address: `0x${string}`, initialBalance: bigint): Promise<void>;
|
|
17
|
+
swapOnGnosisAuto(options: GnosisSwapAutoOptions): Promise<`0x${string}`>;
|
|
18
|
+
swapOnGnosisCustom(options: GnosisSwapCustomOptions): Promise<`0x${string}`>;
|
|
19
|
+
getGnosisTransactionCount(address: `0x${string}`): Promise<number>;
|
|
20
|
+
getSushiSwapQuote(amount: string, sender: string, recipient: string): Promise<SushiResponse>;
|
|
21
|
+
}
|
|
22
|
+
export { MultichainLibrarySettings } from './Settings';
|
|
23
|
+
export { SushiResponse } from './SushiSwap';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultichainLibrary = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const GnosisBzzBalance_1 = require("./GnosisBzzBalance");
|
|
6
|
+
const GnosisNativeBalance_1 = require("./GnosisNativeBalance");
|
|
7
|
+
const GnosisNativeTransfer_1 = require("./GnosisNativeTransfer");
|
|
8
|
+
const GnosisSwap_1 = require("./GnosisSwap");
|
|
9
|
+
const GnosisTransactionCount_1 = require("./GnosisTransactionCount");
|
|
10
|
+
const Settings_1 = require("./Settings");
|
|
11
|
+
const SushiSwap_1 = require("./SushiSwap");
|
|
12
|
+
const TokenPrice_1 = require("./TokenPrice");
|
|
13
|
+
const Waiter_1 = require("./Waiter");
|
|
14
|
+
class MultichainLibrary {
|
|
15
|
+
settings;
|
|
16
|
+
constructor(settings) {
|
|
17
|
+
this.settings = cafe_utility_1.Objects.deepMerge2((0, Settings_1.getDefaultMultichainLibrarySettings)(), settings || {});
|
|
18
|
+
}
|
|
19
|
+
getGnosisBzzBalance(address) {
|
|
20
|
+
return (0, GnosisBzzBalance_1.getGnosisBzzBalance)(address, this.settings);
|
|
21
|
+
}
|
|
22
|
+
getGnosisNativeBalance(address) {
|
|
23
|
+
return (0, GnosisNativeBalance_1.getGnosisNativeBalance)(address, this.settings);
|
|
24
|
+
}
|
|
25
|
+
getTokenPrice(tokenAddress, chainId) {
|
|
26
|
+
return (0, TokenPrice_1.getTokenPrice)(tokenAddress, chainId, this.settings);
|
|
27
|
+
}
|
|
28
|
+
getGnosisBzzTokenPrice() {
|
|
29
|
+
return (0, TokenPrice_1.getGnosisBzzTokenPrice)(this.settings);
|
|
30
|
+
}
|
|
31
|
+
transferGnosisNative(options) {
|
|
32
|
+
return (0, GnosisNativeTransfer_1.transferGnosisNative)(options, this.settings);
|
|
33
|
+
}
|
|
34
|
+
waitForGnosisBzzBalanceToIncrease(address, initialBalance) {
|
|
35
|
+
return (0, Waiter_1.waitForGnosisBzzBalanceToIncrease)(address, initialBalance, this.settings);
|
|
36
|
+
}
|
|
37
|
+
waitForGnosisNativeBalanceToDecrease(address, initialBalance) {
|
|
38
|
+
return (0, Waiter_1.waitForGnosisNativeBalanceToDecrease)(address, initialBalance, this.settings);
|
|
39
|
+
}
|
|
40
|
+
waitForGnosisNativeBalanceToIncrease(address, initialBalance) {
|
|
41
|
+
return (0, Waiter_1.waitForGnosisNativeBalanceToIncrease)(address, initialBalance, this.settings);
|
|
42
|
+
}
|
|
43
|
+
swapOnGnosisAuto(options) {
|
|
44
|
+
return (0, GnosisSwap_1.swapOnGnosisAuto)(options, this.settings);
|
|
45
|
+
}
|
|
46
|
+
swapOnGnosisCustom(options) {
|
|
47
|
+
return (0, GnosisSwap_1.swapOnGnosisCustom)(options, this.settings);
|
|
48
|
+
}
|
|
49
|
+
getGnosisTransactionCount(address) {
|
|
50
|
+
return (0, GnosisTransactionCount_1.getGnosisTransactionCount)(address, this.settings);
|
|
51
|
+
}
|
|
52
|
+
getSushiSwapQuote(amount, sender, recipient) {
|
|
53
|
+
return (0, SushiSwap_1.getSushiSwapQuote)(amount, sender, recipient, this.settings);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.MultichainLibrary = MultichainLibrary;
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@upcoming/multichain-library",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"description": "",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"cafe-utility": "^33.0.0",
|
|
22
|
+
"viem": "^2.38.2"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^24.7.2",
|
|
26
|
+
"typescript": "^5.9.3"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Node 16",
|
|
4
|
+
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"lib": ["ES2022"],
|
|
8
|
+
"module": "CommonJS",
|
|
9
|
+
"target": "ES2022",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"noImplicitAny": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"strictNullChecks": true
|
|
19
|
+
}
|
|
20
|
+
}
|