@m0-foundation/ntt-sdk-route 0.0.4 → 0.0.6
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/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +50 -43
- package/dist/index.mjs +50 -43
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -13,18 +13,23 @@ type QR = routes.QuoteResult<Op, Vp>;
|
|
|
13
13
|
type Q = routes.Quote<Op, Vp>;
|
|
14
14
|
type R = NttRoute.AutomaticTransferReceipt;
|
|
15
15
|
type Contracts = Ntt.Contracts & {
|
|
16
|
-
|
|
16
|
+
mLikeTokens: string[];
|
|
17
17
|
};
|
|
18
18
|
declare class M0AutomaticRoute<N extends Network> extends routes.AutomaticRoute<N, Op, Vp, R> implements routes.StaticRouteMethods<typeof M0AutomaticRoute> {
|
|
19
19
|
static NATIVE_GAS_DROPOFF_SUPPORTED: boolean;
|
|
20
|
+
static EVM_WRAPPED_M_TOKEN: string;
|
|
21
|
+
static SOLANA_MAINNET_M_TOKEN: string;
|
|
22
|
+
static SOLANA_TESTNET_M_TOKEN: string;
|
|
20
23
|
static EVM_CONTRACTS: Contracts;
|
|
21
24
|
static meta: {
|
|
22
25
|
name: string;
|
|
23
26
|
provider: string;
|
|
24
27
|
};
|
|
28
|
+
static solanaContracts(network: Network): Contracts;
|
|
25
29
|
static supportedNetworks(): Network[];
|
|
30
|
+
static isPlatformSupported(platform: string): boolean;
|
|
26
31
|
static supportedChains(network: Network): Chain[];
|
|
27
|
-
static getContracts(
|
|
32
|
+
static getContracts(chainContext: ChainContext<Network>): Contracts;
|
|
28
33
|
static supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]>;
|
|
29
34
|
static supportedDestinationTokens<N extends Network>(token: TokenId, fromChain: ChainContext<N>, toChain: ChainContext<N>): Promise<TokenId[]>;
|
|
30
35
|
static isProtocolSupported<N extends Network>(chain: ChainContext<N>): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,18 +13,23 @@ type QR = routes.QuoteResult<Op, Vp>;
|
|
|
13
13
|
type Q = routes.Quote<Op, Vp>;
|
|
14
14
|
type R = NttRoute.AutomaticTransferReceipt;
|
|
15
15
|
type Contracts = Ntt.Contracts & {
|
|
16
|
-
|
|
16
|
+
mLikeTokens: string[];
|
|
17
17
|
};
|
|
18
18
|
declare class M0AutomaticRoute<N extends Network> extends routes.AutomaticRoute<N, Op, Vp, R> implements routes.StaticRouteMethods<typeof M0AutomaticRoute> {
|
|
19
19
|
static NATIVE_GAS_DROPOFF_SUPPORTED: boolean;
|
|
20
|
+
static EVM_WRAPPED_M_TOKEN: string;
|
|
21
|
+
static SOLANA_MAINNET_M_TOKEN: string;
|
|
22
|
+
static SOLANA_TESTNET_M_TOKEN: string;
|
|
20
23
|
static EVM_CONTRACTS: Contracts;
|
|
21
24
|
static meta: {
|
|
22
25
|
name: string;
|
|
23
26
|
provider: string;
|
|
24
27
|
};
|
|
28
|
+
static solanaContracts(network: Network): Contracts;
|
|
25
29
|
static supportedNetworks(): Network[];
|
|
30
|
+
static isPlatformSupported(platform: string): boolean;
|
|
26
31
|
static supportedChains(network: Network): Chain[];
|
|
27
|
-
static getContracts(
|
|
32
|
+
static getContracts(chainContext: ChainContext<Network>): Contracts;
|
|
28
33
|
static supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]>;
|
|
29
34
|
static supportedDestinationTokens<N extends Network>(token: TokenId, fromChain: ChainContext<N>, toChain: ChainContext<N>): Promise<TokenId[]>;
|
|
30
35
|
static isProtocolSupported<N extends Network>(chain: ChainContext<N>): boolean;
|
package/dist/index.js
CHANGED
|
@@ -8,21 +8,34 @@ var ethers = require('ethers');
|
|
|
8
8
|
|
|
9
9
|
// src/m0AutomaticRoute.ts
|
|
10
10
|
var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.AutomaticRoute {
|
|
11
|
+
static solanaContracts(network) {
|
|
12
|
+
return {
|
|
13
|
+
token: network == "Mainnet" ? this.SOLANA_MAINNET_M_TOKEN : this.SOLANA_TESTNET_M_TOKEN,
|
|
14
|
+
// Only M token can be bridged from Solana
|
|
15
|
+
mLikeTokens: [],
|
|
16
|
+
manager: "mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY",
|
|
17
|
+
transceiver: { wormhole: "mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY" },
|
|
18
|
+
quoter: "Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
11
21
|
static supportedNetworks() {
|
|
12
22
|
return ["Mainnet", "Testnet"];
|
|
13
23
|
}
|
|
24
|
+
static isPlatformSupported(platform) {
|
|
25
|
+
return platform == "Evm" || platform == "Solana";
|
|
26
|
+
}
|
|
14
27
|
static supportedChains(network) {
|
|
15
28
|
switch (network) {
|
|
16
29
|
case "Mainnet":
|
|
17
|
-
return ["Ethereum", "Arbitrum", "Optimism"];
|
|
30
|
+
return ["Ethereum", "Arbitrum", "Optimism", "Solana"];
|
|
18
31
|
case "Testnet":
|
|
19
|
-
return ["Sepolia", "ArbitrumSepolia", "OptimismSepolia"];
|
|
32
|
+
return ["Sepolia", "ArbitrumSepolia", "OptimismSepolia", "Solana"];
|
|
20
33
|
default:
|
|
21
34
|
throw new Error(`Unsupported network: ${network}`);
|
|
22
35
|
}
|
|
23
36
|
}
|
|
24
|
-
static getContracts(
|
|
25
|
-
switch (chain) {
|
|
37
|
+
static getContracts(chainContext) {
|
|
38
|
+
switch (chainContext.chain) {
|
|
26
39
|
case "Ethereum":
|
|
27
40
|
return this.EVM_CONTRACTS;
|
|
28
41
|
case "Optimism":
|
|
@@ -35,15 +48,17 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
35
48
|
return this.EVM_CONTRACTS;
|
|
36
49
|
case "ArbitrumSepolia":
|
|
37
50
|
return this.EVM_CONTRACTS;
|
|
51
|
+
case "Solana":
|
|
52
|
+
return this.solanaContracts(chainContext.network);
|
|
38
53
|
default:
|
|
39
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
54
|
+
throw new Error(`Unsupported chain: ${chainContext.chain}`);
|
|
40
55
|
}
|
|
41
56
|
}
|
|
42
57
|
static async supportedSourceTokens(fromChain) {
|
|
43
|
-
const { token,
|
|
58
|
+
const { token, mLikeTokens } = this.getContracts(fromChain);
|
|
44
59
|
return [
|
|
45
60
|
sdkConnect.Wormhole.tokenId(fromChain.chain, token),
|
|
46
|
-
sdkConnect.Wormhole.tokenId(fromChain.chain,
|
|
61
|
+
...mLikeTokens.map((x) => sdkConnect.Wormhole.tokenId(fromChain.chain, x))
|
|
47
62
|
];
|
|
48
63
|
}
|
|
49
64
|
static async supportedDestinationTokens(token, fromChain, toChain) {
|
|
@@ -51,10 +66,10 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
51
66
|
if (!sourceTokens.some((t) => sdkConnect.isSameToken(t, token))) {
|
|
52
67
|
return [];
|
|
53
68
|
}
|
|
54
|
-
const { token: mToken,
|
|
69
|
+
const { token: mToken, mLikeTokens } = this.getContracts(toChain);
|
|
55
70
|
return [
|
|
56
71
|
sdkConnect.Wormhole.tokenId(toChain.chain, mToken),
|
|
57
|
-
sdkConnect.Wormhole.tokenId(toChain.chain,
|
|
72
|
+
...mLikeTokens.map((x) => sdkConnect.Wormhole.tokenId(toChain.chain, x))
|
|
58
73
|
];
|
|
59
74
|
}
|
|
60
75
|
static isProtocolSupported(chain) {
|
|
@@ -65,7 +80,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
65
80
|
}
|
|
66
81
|
async isAvailable(request) {
|
|
67
82
|
const ntt = await request.fromChain.getProtocol("Ntt", {
|
|
68
|
-
ntt: _M0AutomaticRoute.getContracts(request.fromChain
|
|
83
|
+
ntt: _M0AutomaticRoute.getContracts(request.fromChain)
|
|
69
84
|
});
|
|
70
85
|
return ntt.isRelayingAvailable(request.toChain.chain);
|
|
71
86
|
}
|
|
@@ -80,10 +95,8 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
80
95
|
parsedAmount,
|
|
81
96
|
request.destination.decimals
|
|
82
97
|
);
|
|
83
|
-
const fromContracts = _M0AutomaticRoute.getContracts(
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
const toContracts = _M0AutomaticRoute.getContracts(request.toChain.chain);
|
|
98
|
+
const fromContracts = _M0AutomaticRoute.getContracts(request.fromChain);
|
|
99
|
+
const toContracts = _M0AutomaticRoute.getContracts(request.toChain);
|
|
87
100
|
const validatedParams = {
|
|
88
101
|
amount: params.amount,
|
|
89
102
|
normalizedParams: {
|
|
@@ -103,7 +116,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
103
116
|
async quote(request, params) {
|
|
104
117
|
const { fromChain, toChain } = request;
|
|
105
118
|
const ntt = await fromChain.getProtocol("Ntt", {
|
|
106
|
-
ntt: _M0AutomaticRoute.getContracts(fromChain
|
|
119
|
+
ntt: _M0AutomaticRoute.getContracts(fromChain)
|
|
107
120
|
});
|
|
108
121
|
if (!await ntt.isRelayingAvailable(toChain.chain)) {
|
|
109
122
|
return {
|
|
@@ -149,22 +162,17 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
149
162
|
const { params } = quote;
|
|
150
163
|
const { fromChain } = request;
|
|
151
164
|
const sender = sdkConnect.Wormhole.parseAddress(signer.chain(), signer.address());
|
|
152
|
-
|
|
153
|
-
|
|
165
|
+
const platform = sdkConnect.chainToPlatform(fromChain.chain);
|
|
166
|
+
const transferAmount = sdkConnect.amount.units(params.normalizedParams.amount);
|
|
167
|
+
const options = params.normalizedParams.options;
|
|
168
|
+
if (platform !== "Evm" && platform !== "Solana")
|
|
169
|
+
throw new Error(`Unsupported platform ${platform}`);
|
|
154
170
|
const ntt = await fromChain.getProtocol("Ntt", {
|
|
155
|
-
ntt: _M0AutomaticRoute.getContracts(fromChain
|
|
171
|
+
ntt: _M0AutomaticRoute.getContracts(fromChain)
|
|
156
172
|
});
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const initXfer = this.transferMLike(
|
|
160
|
-
ntt,
|
|
161
|
-
sender,
|
|
162
|
-
sdkConnect.amount.units(params.normalizedParams.amount),
|
|
163
|
-
to,
|
|
164
|
-
sourceTokenAddress,
|
|
165
|
-
destinationTokenAddress,
|
|
166
|
-
params.normalizedParams.options
|
|
167
|
-
);
|
|
173
|
+
const sourceToken = sdkConnect.canonicalAddress(request.source.id);
|
|
174
|
+
const destinationToken = sdkConnect.canonicalAddress(request.destination.id);
|
|
175
|
+
const initXfer = platform === "Evm" ? this.transferMLike(ntt, sender, transferAmount, to, sourceToken, destinationToken, options) : ntt.transfer(sender, transferAmount, to, options);
|
|
168
176
|
const txids = await sdkConnect.signSendWait(fromChain, initXfer, signer);
|
|
169
177
|
return {
|
|
170
178
|
from: fromChain.chain,
|
|
@@ -225,13 +233,10 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
225
233
|
);
|
|
226
234
|
}
|
|
227
235
|
async *track(receipt, timeout) {
|
|
236
|
+
const isEvmPlatform = (chain) => sdkConnect.chainToPlatform(chain) === "Evm";
|
|
228
237
|
if (sdkConnect.isSourceInitiated(receipt) || sdkConnect.isSourceFinalized(receipt)) {
|
|
229
238
|
const { txid } = receipt.originTxs[receipt.originTxs.length - 1];
|
|
230
|
-
const
|
|
231
|
-
const vaaType = isEvmPlatform(receipt.from) && isEvmPlatform(receipt.to) ? (
|
|
232
|
-
// Automatic NTT transfers between EVM chains use standard relayers
|
|
233
|
-
"Ntt:WormholeTransferStandardRelayer"
|
|
234
|
-
) : "Ntt:WormholeTransfer";
|
|
239
|
+
const vaaType = isEvmPlatform(receipt.from) && isEvmPlatform(receipt.to) ? "Ntt:WormholeTransferStandardRelayer" : "Ntt:WormholeTransfer";
|
|
235
240
|
const vaa = await this.wh.getVaa(txid, vaaType, timeout);
|
|
236
241
|
if (!vaa) {
|
|
237
242
|
throw new Error(`No VAA found for transaction: ${txid}`);
|
|
@@ -253,7 +258,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
253
258
|
}
|
|
254
259
|
const toChain = this.wh.getChain(receipt.to);
|
|
255
260
|
const ntt = await toChain.getProtocol("Ntt", {
|
|
256
|
-
ntt: _M0AutomaticRoute.getContracts(toChain
|
|
261
|
+
ntt: _M0AutomaticRoute.getContracts(toChain)
|
|
257
262
|
});
|
|
258
263
|
if (sdkConnect.isAttested(receipt)) {
|
|
259
264
|
const {
|
|
@@ -269,13 +274,11 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
269
274
|
}
|
|
270
275
|
}
|
|
271
276
|
if (sdkConnect.isRedeemed(receipt)) {
|
|
272
|
-
const {
|
|
273
|
-
attestation: { attestation: vaa }
|
|
274
|
-
} = receipt;
|
|
277
|
+
const { attestation: { attestation: vaa } } = receipt;
|
|
275
278
|
const payload = vaa.payloadName === "WormholeTransfer" ? vaa.payload : vaa.payload["payload"];
|
|
276
|
-
const isExecuted = await ntt.manager.isMessageExecuted(
|
|
279
|
+
const isExecuted = isEvmPlatform(receipt.to) ? await ntt.manager.isMessageExecuted(
|
|
277
280
|
sdkDefinitionsNtt.Ntt.messageDigest(vaa.emitterChain, payload["nttManagerPayload"])
|
|
278
|
-
);
|
|
281
|
+
) : await ntt.getIsExecuted(vaa);
|
|
279
282
|
if (isExecuted) {
|
|
280
283
|
receipt = {
|
|
281
284
|
...receipt,
|
|
@@ -289,18 +292,22 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
289
292
|
};
|
|
290
293
|
// ntt does not support gas drop-off currently
|
|
291
294
|
_M0AutomaticRoute.NATIVE_GAS_DROPOFF_SUPPORTED = false;
|
|
295
|
+
// Wrapped M token address is the same on EVM chains
|
|
296
|
+
_M0AutomaticRoute.EVM_WRAPPED_M_TOKEN = "0x437cc33344a0B27A429f795ff6B469C72698B291";
|
|
297
|
+
_M0AutomaticRoute.SOLANA_MAINNET_M_TOKEN = "mzerokyEX9TNDoK4o2YZQBDmMzjokAeN6M2g2S3pLJo";
|
|
298
|
+
_M0AutomaticRoute.SOLANA_TESTNET_M_TOKEN = "mzeroZRGCah3j5xEWp2Nih3GDejSBbH1rbHoxDg8By6";
|
|
292
299
|
// Contract addresses are the same on all EVM chains
|
|
293
300
|
_M0AutomaticRoute.EVM_CONTRACTS = {
|
|
294
301
|
// M token address is the same on EVM chains
|
|
295
302
|
token: "0x866A2BF4E572CbcF37D5071A7a58503Bfb36be1b",
|
|
296
|
-
// Wrapped M
|
|
297
|
-
|
|
303
|
+
// Wrapped $M and Extension Tokens that can bridged by unwrapping to $M
|
|
304
|
+
mLikeTokens: [_M0AutomaticRoute.EVM_WRAPPED_M_TOKEN],
|
|
298
305
|
// M0 Portal address is the same on EVM chains
|
|
299
306
|
manager: "0xD925C84b55E4e44a53749fF5F2a5A13F63D128fd",
|
|
300
307
|
// Wormhole transceiver address is the same on EVM chains
|
|
301
308
|
transceiver: { wormhole: "0x0763196A091575adF99e2306E5e90E0Be5154841" }
|
|
302
309
|
};
|
|
303
|
-
_M0AutomaticRoute.meta = { name: "M0AutomaticRoute", provider: "
|
|
310
|
+
_M0AutomaticRoute.meta = { name: "M0AutomaticRoute", provider: "M0" };
|
|
304
311
|
var M0AutomaticRoute = _M0AutomaticRoute;
|
|
305
312
|
|
|
306
313
|
exports.M0AutomaticRoute = M0AutomaticRoute;
|
package/dist/index.mjs
CHANGED
|
@@ -6,21 +6,34 @@ import { Contract } from 'ethers';
|
|
|
6
6
|
|
|
7
7
|
// src/m0AutomaticRoute.ts
|
|
8
8
|
var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
9
|
+
static solanaContracts(network) {
|
|
10
|
+
return {
|
|
11
|
+
token: network == "Mainnet" ? this.SOLANA_MAINNET_M_TOKEN : this.SOLANA_TESTNET_M_TOKEN,
|
|
12
|
+
// Only M token can be bridged from Solana
|
|
13
|
+
mLikeTokens: [],
|
|
14
|
+
manager: "mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY",
|
|
15
|
+
transceiver: { wormhole: "mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY" },
|
|
16
|
+
quoter: "Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ"
|
|
17
|
+
};
|
|
18
|
+
}
|
|
9
19
|
static supportedNetworks() {
|
|
10
20
|
return ["Mainnet", "Testnet"];
|
|
11
21
|
}
|
|
22
|
+
static isPlatformSupported(platform) {
|
|
23
|
+
return platform == "Evm" || platform == "Solana";
|
|
24
|
+
}
|
|
12
25
|
static supportedChains(network) {
|
|
13
26
|
switch (network) {
|
|
14
27
|
case "Mainnet":
|
|
15
|
-
return ["Ethereum", "Arbitrum", "Optimism"];
|
|
28
|
+
return ["Ethereum", "Arbitrum", "Optimism", "Solana"];
|
|
16
29
|
case "Testnet":
|
|
17
|
-
return ["Sepolia", "ArbitrumSepolia", "OptimismSepolia"];
|
|
30
|
+
return ["Sepolia", "ArbitrumSepolia", "OptimismSepolia", "Solana"];
|
|
18
31
|
default:
|
|
19
32
|
throw new Error(`Unsupported network: ${network}`);
|
|
20
33
|
}
|
|
21
34
|
}
|
|
22
|
-
static getContracts(
|
|
23
|
-
switch (chain) {
|
|
35
|
+
static getContracts(chainContext) {
|
|
36
|
+
switch (chainContext.chain) {
|
|
24
37
|
case "Ethereum":
|
|
25
38
|
return this.EVM_CONTRACTS;
|
|
26
39
|
case "Optimism":
|
|
@@ -33,15 +46,17 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
33
46
|
return this.EVM_CONTRACTS;
|
|
34
47
|
case "ArbitrumSepolia":
|
|
35
48
|
return this.EVM_CONTRACTS;
|
|
49
|
+
case "Solana":
|
|
50
|
+
return this.solanaContracts(chainContext.network);
|
|
36
51
|
default:
|
|
37
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
52
|
+
throw new Error(`Unsupported chain: ${chainContext.chain}`);
|
|
38
53
|
}
|
|
39
54
|
}
|
|
40
55
|
static async supportedSourceTokens(fromChain) {
|
|
41
|
-
const { token,
|
|
56
|
+
const { token, mLikeTokens } = this.getContracts(fromChain);
|
|
42
57
|
return [
|
|
43
58
|
Wormhole.tokenId(fromChain.chain, token),
|
|
44
|
-
Wormhole.tokenId(fromChain.chain,
|
|
59
|
+
...mLikeTokens.map((x) => Wormhole.tokenId(fromChain.chain, x))
|
|
45
60
|
];
|
|
46
61
|
}
|
|
47
62
|
static async supportedDestinationTokens(token, fromChain, toChain) {
|
|
@@ -49,10 +64,10 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
49
64
|
if (!sourceTokens.some((t) => isSameToken(t, token))) {
|
|
50
65
|
return [];
|
|
51
66
|
}
|
|
52
|
-
const { token: mToken,
|
|
67
|
+
const { token: mToken, mLikeTokens } = this.getContracts(toChain);
|
|
53
68
|
return [
|
|
54
69
|
Wormhole.tokenId(toChain.chain, mToken),
|
|
55
|
-
Wormhole.tokenId(toChain.chain,
|
|
70
|
+
...mLikeTokens.map((x) => Wormhole.tokenId(toChain.chain, x))
|
|
56
71
|
];
|
|
57
72
|
}
|
|
58
73
|
static isProtocolSupported(chain) {
|
|
@@ -63,7 +78,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
63
78
|
}
|
|
64
79
|
async isAvailable(request) {
|
|
65
80
|
const ntt = await request.fromChain.getProtocol("Ntt", {
|
|
66
|
-
ntt: _M0AutomaticRoute.getContracts(request.fromChain
|
|
81
|
+
ntt: _M0AutomaticRoute.getContracts(request.fromChain)
|
|
67
82
|
});
|
|
68
83
|
return ntt.isRelayingAvailable(request.toChain.chain);
|
|
69
84
|
}
|
|
@@ -78,10 +93,8 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
78
93
|
parsedAmount,
|
|
79
94
|
request.destination.decimals
|
|
80
95
|
);
|
|
81
|
-
const fromContracts = _M0AutomaticRoute.getContracts(
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
const toContracts = _M0AutomaticRoute.getContracts(request.toChain.chain);
|
|
96
|
+
const fromContracts = _M0AutomaticRoute.getContracts(request.fromChain);
|
|
97
|
+
const toContracts = _M0AutomaticRoute.getContracts(request.toChain);
|
|
85
98
|
const validatedParams = {
|
|
86
99
|
amount: params.amount,
|
|
87
100
|
normalizedParams: {
|
|
@@ -101,7 +114,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
101
114
|
async quote(request, params) {
|
|
102
115
|
const { fromChain, toChain } = request;
|
|
103
116
|
const ntt = await fromChain.getProtocol("Ntt", {
|
|
104
|
-
ntt: _M0AutomaticRoute.getContracts(fromChain
|
|
117
|
+
ntt: _M0AutomaticRoute.getContracts(fromChain)
|
|
105
118
|
});
|
|
106
119
|
if (!await ntt.isRelayingAvailable(toChain.chain)) {
|
|
107
120
|
return {
|
|
@@ -147,22 +160,17 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
147
160
|
const { params } = quote;
|
|
148
161
|
const { fromChain } = request;
|
|
149
162
|
const sender = Wormhole.parseAddress(signer.chain(), signer.address());
|
|
150
|
-
|
|
151
|
-
|
|
163
|
+
const platform = chainToPlatform(fromChain.chain);
|
|
164
|
+
const transferAmount = amount.units(params.normalizedParams.amount);
|
|
165
|
+
const options = params.normalizedParams.options;
|
|
166
|
+
if (platform !== "Evm" && platform !== "Solana")
|
|
167
|
+
throw new Error(`Unsupported platform ${platform}`);
|
|
152
168
|
const ntt = await fromChain.getProtocol("Ntt", {
|
|
153
|
-
ntt: _M0AutomaticRoute.getContracts(fromChain
|
|
169
|
+
ntt: _M0AutomaticRoute.getContracts(fromChain)
|
|
154
170
|
});
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const initXfer = this.transferMLike(
|
|
158
|
-
ntt,
|
|
159
|
-
sender,
|
|
160
|
-
amount.units(params.normalizedParams.amount),
|
|
161
|
-
to,
|
|
162
|
-
sourceTokenAddress,
|
|
163
|
-
destinationTokenAddress,
|
|
164
|
-
params.normalizedParams.options
|
|
165
|
-
);
|
|
171
|
+
const sourceToken = canonicalAddress(request.source.id);
|
|
172
|
+
const destinationToken = canonicalAddress(request.destination.id);
|
|
173
|
+
const initXfer = platform === "Evm" ? this.transferMLike(ntt, sender, transferAmount, to, sourceToken, destinationToken, options) : ntt.transfer(sender, transferAmount, to, options);
|
|
166
174
|
const txids = await signSendWait(fromChain, initXfer, signer);
|
|
167
175
|
return {
|
|
168
176
|
from: fromChain.chain,
|
|
@@ -223,13 +231,10 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
223
231
|
);
|
|
224
232
|
}
|
|
225
233
|
async *track(receipt, timeout) {
|
|
234
|
+
const isEvmPlatform = (chain) => chainToPlatform(chain) === "Evm";
|
|
226
235
|
if (isSourceInitiated(receipt) || isSourceFinalized(receipt)) {
|
|
227
236
|
const { txid } = receipt.originTxs[receipt.originTxs.length - 1];
|
|
228
|
-
const
|
|
229
|
-
const vaaType = isEvmPlatform(receipt.from) && isEvmPlatform(receipt.to) ? (
|
|
230
|
-
// Automatic NTT transfers between EVM chains use standard relayers
|
|
231
|
-
"Ntt:WormholeTransferStandardRelayer"
|
|
232
|
-
) : "Ntt:WormholeTransfer";
|
|
237
|
+
const vaaType = isEvmPlatform(receipt.from) && isEvmPlatform(receipt.to) ? "Ntt:WormholeTransferStandardRelayer" : "Ntt:WormholeTransfer";
|
|
233
238
|
const vaa = await this.wh.getVaa(txid, vaaType, timeout);
|
|
234
239
|
if (!vaa) {
|
|
235
240
|
throw new Error(`No VAA found for transaction: ${txid}`);
|
|
@@ -251,7 +256,7 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
251
256
|
}
|
|
252
257
|
const toChain = this.wh.getChain(receipt.to);
|
|
253
258
|
const ntt = await toChain.getProtocol("Ntt", {
|
|
254
|
-
ntt: _M0AutomaticRoute.getContracts(toChain
|
|
259
|
+
ntt: _M0AutomaticRoute.getContracts(toChain)
|
|
255
260
|
});
|
|
256
261
|
if (isAttested(receipt)) {
|
|
257
262
|
const {
|
|
@@ -267,13 +272,11 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
267
272
|
}
|
|
268
273
|
}
|
|
269
274
|
if (isRedeemed(receipt)) {
|
|
270
|
-
const {
|
|
271
|
-
attestation: { attestation: vaa }
|
|
272
|
-
} = receipt;
|
|
275
|
+
const { attestation: { attestation: vaa } } = receipt;
|
|
273
276
|
const payload = vaa.payloadName === "WormholeTransfer" ? vaa.payload : vaa.payload["payload"];
|
|
274
|
-
const isExecuted = await ntt.manager.isMessageExecuted(
|
|
277
|
+
const isExecuted = isEvmPlatform(receipt.to) ? await ntt.manager.isMessageExecuted(
|
|
275
278
|
Ntt.messageDigest(vaa.emitterChain, payload["nttManagerPayload"])
|
|
276
|
-
);
|
|
279
|
+
) : await ntt.getIsExecuted(vaa);
|
|
277
280
|
if (isExecuted) {
|
|
278
281
|
receipt = {
|
|
279
282
|
...receipt,
|
|
@@ -287,18 +290,22 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends routes.AutomaticRoute {
|
|
|
287
290
|
};
|
|
288
291
|
// ntt does not support gas drop-off currently
|
|
289
292
|
_M0AutomaticRoute.NATIVE_GAS_DROPOFF_SUPPORTED = false;
|
|
293
|
+
// Wrapped M token address is the same on EVM chains
|
|
294
|
+
_M0AutomaticRoute.EVM_WRAPPED_M_TOKEN = "0x437cc33344a0B27A429f795ff6B469C72698B291";
|
|
295
|
+
_M0AutomaticRoute.SOLANA_MAINNET_M_TOKEN = "mzerokyEX9TNDoK4o2YZQBDmMzjokAeN6M2g2S3pLJo";
|
|
296
|
+
_M0AutomaticRoute.SOLANA_TESTNET_M_TOKEN = "mzeroZRGCah3j5xEWp2Nih3GDejSBbH1rbHoxDg8By6";
|
|
290
297
|
// Contract addresses are the same on all EVM chains
|
|
291
298
|
_M0AutomaticRoute.EVM_CONTRACTS = {
|
|
292
299
|
// M token address is the same on EVM chains
|
|
293
300
|
token: "0x866A2BF4E572CbcF37D5071A7a58503Bfb36be1b",
|
|
294
|
-
// Wrapped M
|
|
295
|
-
|
|
301
|
+
// Wrapped $M and Extension Tokens that can bridged by unwrapping to $M
|
|
302
|
+
mLikeTokens: [_M0AutomaticRoute.EVM_WRAPPED_M_TOKEN],
|
|
296
303
|
// M0 Portal address is the same on EVM chains
|
|
297
304
|
manager: "0xD925C84b55E4e44a53749fF5F2a5A13F63D128fd",
|
|
298
305
|
// Wormhole transceiver address is the same on EVM chains
|
|
299
306
|
transceiver: { wormhole: "0x0763196A091575adF99e2306E5e90E0Be5154841" }
|
|
300
307
|
};
|
|
301
|
-
_M0AutomaticRoute.meta = { name: "M0AutomaticRoute", provider: "
|
|
308
|
+
_M0AutomaticRoute.meta = { name: "M0AutomaticRoute", provider: "M0" };
|
|
302
309
|
var M0AutomaticRoute = _M0AutomaticRoute;
|
|
303
310
|
|
|
304
311
|
export { M0AutomaticRoute };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m0-foundation/ntt-sdk-route",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@wormhole-foundation/sdk": "^1.7.0",
|
|
34
34
|
"@wormhole-foundation/sdk-connect": "^1.7.0",
|
|
35
|
-
"@wormhole-foundation/sdk-definitions-ntt": "^0.
|
|
35
|
+
"@wormhole-foundation/sdk-definitions-ntt": "^0.7.1",
|
|
36
36
|
"@wormhole-foundation/sdk-evm": "^1.7.0",
|
|
37
|
-
"@wormhole-foundation/sdk-evm-ntt": "^0.
|
|
38
|
-
"@wormhole-foundation/sdk-route-ntt": "^0.
|
|
37
|
+
"@wormhole-foundation/sdk-evm-ntt": "^0.7.1",
|
|
38
|
+
"@wormhole-foundation/sdk-route-ntt": "^0.7.1",
|
|
39
39
|
"ethers": "^6.5.1"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|