@wormhole-foundation/wormhole-connect 2.5.0-beta.0-development → 2.5.0-beta.2-development
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/assets/{aptos-t5JANz4b.js → aptos-BGyyK8mz.js} +3 -3
- package/dist/assets/{aptos-DvAOSqnD.js → aptos-Cepohe0c.js} +1 -1
- package/dist/assets/{blake2b-CzqSqyTv.js → blake2b-BwI-z5NJ.js} +1 -1
- package/dist/assets/{ccip-4EBcfi6P.js → ccip-BpjdU5zN.js} +1 -1
- package/dist/assets/{chunk-IMTC3J2M-Cms0K4gx.js → chunk-IMTC3J2M-CWE1FuDc.js} +1 -1
- package/dist/assets/events-6PekJgMN.js +1 -0
- package/dist/assets/{evm-8e-eySdo.js → evm-DS7RCBlt.js} +2 -2
- package/dist/assets/{evm-CYjbe4kH.js → evm-DvDOQf0K.js} +4 -4
- package/dist/assets/{index-M2j4uONF.js → index-5kmPKAJ_.js} +1 -1
- package/dist/assets/{index-DALVDBZq.js → index-BP8gdgNH.js} +1 -1
- package/dist/assets/{index-BgVVAYar.js → index-BXRb91Mn.js} +1 -1
- package/dist/assets/{index-SO_H3W5I.js → index-Bbr14gKC.js} +1 -1
- package/dist/assets/index-BjVbgKwL.js +1 -0
- package/dist/assets/{index-JtvUouOr.js → index-BwPu1wGj.js} +1 -1
- package/dist/assets/{index-CwGBYrGm.js → index-BxXKtU8j.js} +1 -1
- package/dist/assets/{index-BKj7Inys.js → index-BzNSt2uL.js} +1 -1
- package/dist/assets/{index-CSHmWPOV.js → index-C1f05Vbe.js} +1 -1
- package/dist/assets/{index-BcX-2q-J.js → index-C74fy0qh.js} +1 -1
- package/dist/assets/{index-Dl17aI3S.js → index-CCOom38X.js} +1 -1
- package/dist/assets/{index-C0rvraea.js → index-CHnF49kB.js} +1 -1
- package/dist/assets/{index-DmaqQuhH.js → index-CyxmcHOs.js} +1 -1
- package/dist/assets/{index-Chd_bwGM.js → index-D1MoRUWm.js} +1 -1
- package/dist/assets/{index-CqA1lXp5.js → index-D54DXHBu.js} +1 -1
- package/dist/assets/index-D8nnAO88.js +1 -0
- package/dist/assets/index-DpMc0uqY.js +1 -0
- package/dist/assets/{index-Ced_GF9G.js → index-FNyibGfB.js} +2 -2
- package/dist/assets/{index-D9U4BOHM.js → index-X7Qc-hll.js} +1 -1
- package/dist/assets/{index-CcMXeWAX.js → index-YqzS8F8M.js} +2 -2
- package/dist/assets/{index.es-Bzsluoyw.js → index.es-B2WvD5Rz.js} +6 -6
- package/dist/assets/{solana-BHeUantu.js → solana-Dj3oh4lV.js} +2 -2
- package/dist/assets/solana-DseaNtL0.js +2 -0
- package/dist/assets/solanaEmbed.esm-xl7iC7nm.js +37 -0
- package/dist/assets/sui-BdOrw1dc.js +2 -0
- package/dist/assets/{sui-CLrvrAHM.js → sui-Ck-FZzH_.js} +1 -1
- package/dist/assets/unsignedTransaction-arVvzoJx.js +1 -0
- package/dist/main.js +102 -102
- package/dist/src/AppRouter.d.ts.map +1 -1
- package/dist/src/utils/coingecko.d.ts.map +1 -1
- package/lib/{aptos-By3qLiAP.js → aptos-BHFBFxf9.js} +1 -1
- package/lib/{aptos-C3Ph4uY9.mjs → aptos-BusONhYq.mjs} +5 -5
- package/lib/{aptos-Cs46Nns5.mjs → aptos-DS0eK_De.mjs} +2 -2
- package/lib/{aptos-D7X5GMcO.js → aptos-Dqp93_ct.js} +2 -2
- package/lib/{base64-B-n8C-1n.js → base64-Cjk6rii_.js} +1 -1
- package/lib/{base64-DxqKuhqD.mjs → base64-Vgzj53Io.mjs} +1 -1
- package/lib/{ccip-BoG9ZHRV.js → ccip-BLUli_Dz.js} +1 -1
- package/lib/{ccip-DgwbitdX.mjs → ccip-FbY2UZlg.mjs} +1 -1
- package/lib/{chunk-IMTC3J2M-DfLEkM5Z.js → chunk-IMTC3J2M-6yduhw0s.js} +1 -1
- package/lib/{chunk-IMTC3J2M-w136PyXJ.mjs → chunk-IMTC3J2M-AkEA0_z6.mjs} +3 -3
- package/lib/{evm-Bta1KBsb.js → evm-BB0d_Gf4.js} +2 -2
- package/lib/{evm--NPB9x1d.mjs → evm-DAHEa0cY.mjs} +5 -5
- package/lib/{evm-BwXOj4Er.js → evm-DZww7tTt.js} +3 -3
- package/lib/{evm-OXQXmbRf.mjs → evm-gEzFFEsO.mjs} +6 -6
- package/lib/{index-C2jvFfvC.js → index-6m6Q8Vsa.js} +1 -1
- package/lib/{index-0m16n7L7.js → index-8STuBnQE.js} +1 -1
- package/lib/{index-hFtbBndd.js → index-B5i1j7Dy.js} +1 -1
- package/lib/{index-CoEGiDGu.js → index-BZh72NtL.js} +1 -1
- package/lib/{index-C86P0A0Y.mjs → index-BaMrMiTv.mjs} +1 -1
- package/lib/{index-BEHglvs0.js → index-BbxXJYWg.js} +1 -1
- package/lib/{index-ByicGRKs.mjs → index-Bcl7n3KD.mjs} +2 -2
- package/lib/{index-Bi6PAFR8.mjs → index-BeYO1LV3.mjs} +2 -2
- package/lib/{index-wsfzS6PN.js → index-Bhgci81L.js} +120 -120
- package/lib/{index-CWffCIQl.js → index-BuPKwE_4.js} +1 -1
- package/lib/{index-C5tynAhb.mjs → index-C27ZY3oS.mjs} +1 -1
- package/lib/{index-bDliG7yg.mjs → index-C6YOw6gB.mjs} +4 -4
- package/lib/{index-1WX3nZoM.mjs → index-CA09NOzo.mjs} +3 -3
- package/lib/index-CHaex8L3.mjs +75 -0
- package/lib/{index-B5z5oFY1.js → index-CSK3DRpf.js} +1 -1
- package/lib/{index-Cslbrg97.js → index-CT45reKG.js} +1 -1
- package/lib/{index-PnMJX4OC.mjs → index-CkXJo6xD.mjs} +1 -1
- package/lib/{index-FGc8swXY.mjs → index-Cs1dlfzD.mjs} +1 -1
- package/lib/{index-CKtZvS3X.mjs → index-CxTd6N-A.mjs} +2 -2
- package/lib/{index-CGbtcED2.mjs → index-D9hjnIst.mjs} +2 -2
- package/lib/{index-CksJcNrV.mjs → index-DDZaEBsC.mjs} +3 -3
- package/lib/{index-CDwpyfnd.mjs → index-DR-fv3uE.mjs} +2 -2
- package/lib/{index-BGqNMVpQ.js → index-DUC1gOTG.js} +1 -1
- package/lib/{index-Bpx_Rf1J.js → index-DUZnVNwZ.js} +1 -1
- package/lib/{index-DLiQpgMj.js → index-DXzXHly-.js} +1 -1
- package/lib/{index-MytorfyK.mjs → index-D_PIxJ0d.mjs} +2 -2
- package/lib/index-D_XBMeuk.js +1 -0
- package/lib/{index-DSejRtdA.js → index-DcYZkDfF.js} +1 -1
- package/lib/{index-cyTUScMF.js → index-DhR1_nfh.js} +1 -1
- package/lib/index-DhowVYVk.mjs +191 -0
- package/lib/{index-BLxoZ8qT.js → index-DlNp9VMO.js} +1 -1
- package/lib/{index-zMaT9P4V.mjs → index-DpeIjsSi.mjs} +1 -1
- package/lib/{index-B3smMSuW.js → index-Ds5QMWJr.js} +1 -1
- package/lib/{index-BXc3l4Br.mjs → index-Ds6Q5qfX.mjs} +2 -2
- package/lib/{index-DlW1-aGm.js → index-DtjJKYjA.js} +1 -1
- package/lib/{index-ILKgpNXM.js → index-FoZ3qnSm.js} +1 -1
- package/lib/{index-CoX_24Ky.mjs → index-GSQqQOXb.mjs} +1 -1
- package/lib/{index-m0543tB2.mjs → index-LdDD7AAy.mjs} +20959 -32801
- package/lib/index-OqOcvaDE.mjs +654 -0
- package/lib/{index-50mhIuON.mjs → index-QCqnETT_.mjs} +2 -2
- package/lib/index-j8CdhHvQ.js +1 -0
- package/lib/{index-Dt0J9sau.js → index-pWRTEePn.js} +1 -1
- package/lib/{index-DPM7TGSv.mjs → index-pg4EQbm-.mjs} +11 -2
- package/lib/index-s9pQs8eO.js +1 -0
- package/lib/{index-CANn2DFq.mjs → index-tI4rmxN8.mjs} +1 -1
- package/lib/{index-NTAse-vE.js → index-u05I0QmU.js} +1 -1
- package/lib/{index.es-DIL345_I.js → index.es-BeAVotPr.js} +2 -2
- package/lib/{index.es-Bh1QXm67.mjs → index.es-Z5ZsZIyC.mjs} +5 -5
- package/lib/index.js +1 -1
- package/lib/index.mjs +19 -19
- package/lib/{signer-CeNONJjb.mjs → signer-B0f07_6U.mjs} +1 -1
- package/lib/{signer-Br2-fgMa.js → signer-yr6Zpc2i.js} +1 -1
- package/lib/{solana-C5lAA_Eh.mjs → solana-C-LeRjT-.mjs} +4 -4
- package/lib/solana-Ci7N1M7R.js +1 -0
- package/lib/solana-DCefclYK.mjs +17 -0
- package/lib/{solana-Bwwk-8HE.js → solana-DWYDxAWP.js} +1 -1
- package/lib/{solanaEmbed.esm-_NPc8tZC.mjs → solanaEmbed.esm-CEtmCHNm.mjs} +1 -1
- package/lib/{solanaEmbed.esm-BMTrlSVI.js → solanaEmbed.esm-D5pFIuXZ.js} +1 -1
- package/lib/src/AppRouter.d.ts.map +1 -1
- package/lib/src/utils/coingecko.d.ts.map +1 -1
- package/lib/sui-756LVCZm.js +1 -0
- package/lib/{sui-zLYQBpSC.js → sui-BIUo4whG.js} +1 -1
- package/lib/sui-BuI3_sI0.mjs +585 -0
- package/lib/{sui-X62i5q3_.mjs → sui-naAV3r83.mjs} +1 -1
- package/package.json +17 -17
- package/dist/assets/index-BRtMY3at.js +0 -1
- package/dist/assets/index-BUlVFUMr.js +0 -1
- package/dist/assets/index-RBS_ALc7.js +0 -1
- package/dist/assets/solana-BEFCVrXa.js +0 -2
- package/dist/assets/solanaEmbed.esm-B7A7qKmk.js +0 -37
- package/dist/assets/sui-C1wbtvIC.js +0 -2
- package/lib/index-CNkTJOH_.js +0 -1
- package/lib/index-DN6dWOSB.js +0 -1
- package/lib/index-DUOnxuE_.mjs +0 -252
- package/lib/index-DqFY4i5u.js +0 -1
- package/lib/index-Eomc9IwB.mjs +0 -936
- package/lib/index-fkzogQYE.mjs +0 -376
- package/lib/solana-4Qcfxe9o.js +0 -1
- package/lib/solana-DM9nG3cQ.mjs +0 -17
- package/lib/sui-BvJu9wTN.mjs +0 -701
- package/lib/sui-pGBefbTJ.js +0 -1
package/lib/index-Eomc9IwB.mjs
DELETED
|
@@ -1,936 +0,0 @@
|
|
|
1
|
-
var he = Object.defineProperty;
|
|
2
|
-
var pe = (s, e, t) => e in s ? he(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
-
var g = (s, e, t) => pe(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
-
import { c0 as W, aa as T, cL as ne, ae as we, cU as ye, $ as me, ao as ke, cV as B, cW as oe, cX as ae, a0 as be, a2 as Ie, ap as je, a3 as ve, a5 as Ce, a6 as v, a7 as Be, a9 as Te, bG as Ee, b$ as L, bL as _e, bE as E, bI as Ae, c5 as Q, c2 as Oe, cY as O, bM as K, cZ as q, cy as X, c_ as Se, bQ as se } from "./index-m0543tB2.mjs";
|
|
5
|
-
import "./index-DUOnxuE_.mjs";
|
|
6
|
-
const P = "::", z = "0x2::sui::SUI", R = (s) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(s), U = (s) => s.replace(/(0x)(0*)/g, "0x");
|
|
7
|
-
function Z(s) {
|
|
8
|
-
return s = s.startsWith("0x") ? s.slice(2) : s, s = s.length % 2 === 0 ? s : "0" + s, `0x${s.length === 64 ? s : T.encode(ne.zpad(T.decode(s), 32))}`;
|
|
9
|
-
}
|
|
10
|
-
const ee = (s) => {
|
|
11
|
-
const e = s.split(P);
|
|
12
|
-
if (e.length !== 3)
|
|
13
|
-
throw new Error(`Invalid Sui type: ${s}`);
|
|
14
|
-
return [we(e[0]), e[1], e[2]].join(P);
|
|
15
|
-
}, $e = (s) => new m(s).getCoinType(), ie = (s) => new m(s).getPackageId(), ce = (s) => {
|
|
16
|
-
const e = U(s).match(/0x2::table::Table<(.*)>/);
|
|
17
|
-
if (!e)
|
|
18
|
-
throw new Error(`Invalid table type: ${s}`);
|
|
19
|
-
if (e.length < 2)
|
|
20
|
-
throw new Error(`Invalid table type: ${s}`);
|
|
21
|
-
const [t] = e[1].split(",");
|
|
22
|
-
if (!t || !R(t))
|
|
23
|
-
throw new Error(`Invalid key type: ${t}`);
|
|
24
|
-
return t;
|
|
25
|
-
}, S = class S {
|
|
26
|
-
constructor(e) {
|
|
27
|
-
// Full 32 bytes of Address
|
|
28
|
-
g(this, "address");
|
|
29
|
-
// Optional module and contract name
|
|
30
|
-
g(this, "module");
|
|
31
|
-
if (S.instanceof(e))
|
|
32
|
-
this.address = e.address, this.module = e.module;
|
|
33
|
-
else if (W.instanceof(e))
|
|
34
|
-
this.address = e.toUint8Array();
|
|
35
|
-
else if (typeof e == "string") {
|
|
36
|
-
if (R(e)) {
|
|
37
|
-
const t = e.split(P);
|
|
38
|
-
this.module = t.slice(1).join(P), e = t[0];
|
|
39
|
-
}
|
|
40
|
-
if (e = Z(e), !T.valid(e))
|
|
41
|
-
throw new Error("Invalid Sui address: " + e);
|
|
42
|
-
this.address = T.decode(e);
|
|
43
|
-
} else
|
|
44
|
-
this.address = e;
|
|
45
|
-
}
|
|
46
|
-
unwrap() {
|
|
47
|
-
const e = this.getPackageId(), t = this.module ? P + this.module : "";
|
|
48
|
-
return `${e}${t}`;
|
|
49
|
-
}
|
|
50
|
-
toString() {
|
|
51
|
-
return this.unwrap();
|
|
52
|
-
}
|
|
53
|
-
toNative() {
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
toUint8Array() {
|
|
57
|
-
return this.address;
|
|
58
|
-
}
|
|
59
|
-
toUniversalAddress() {
|
|
60
|
-
return new W(this.toUint8Array());
|
|
61
|
-
}
|
|
62
|
-
getPackageId() {
|
|
63
|
-
return Z(T.encode(this.address));
|
|
64
|
-
}
|
|
65
|
-
getCoinType() {
|
|
66
|
-
if (this.module === "sui::SUI")
|
|
67
|
-
return z;
|
|
68
|
-
if (!this.module)
|
|
69
|
-
throw new Error("No module present in Sui token address");
|
|
70
|
-
return this.unwrap();
|
|
71
|
-
}
|
|
72
|
-
static instanceof(e) {
|
|
73
|
-
return e.constructor.platform === S.platform;
|
|
74
|
-
}
|
|
75
|
-
equals(e) {
|
|
76
|
-
return S.instanceof(e) ? e.unwrap() === this.unwrap() : this.toUniversalAddress().equals(e);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
g(S, "byteSize", 32), g(S, "platform", "Sui");
|
|
80
|
-
let m = S;
|
|
81
|
-
ye("Sui", m);
|
|
82
|
-
class de {
|
|
83
|
-
constructor(e, t, n, r, o = !1) {
|
|
84
|
-
g(this, "transaction");
|
|
85
|
-
g(this, "network");
|
|
86
|
-
g(this, "chain");
|
|
87
|
-
g(this, "description");
|
|
88
|
-
g(this, "parallelizable");
|
|
89
|
-
this.transaction = e, this.network = t, this.chain = n, this.description = r, this.parallelizable = o;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
class xe extends me {
|
|
93
|
-
}
|
|
94
|
-
const te = "Sui", N = (s) => {
|
|
95
|
-
var t;
|
|
96
|
-
const e = (t = s.data) == null ? void 0 : t.content;
|
|
97
|
-
return e && e.dataType === "moveObject" ? e.fields : null;
|
|
98
|
-
}, le = (s, e) => {
|
|
99
|
-
try {
|
|
100
|
-
return ee(s) === ee(e);
|
|
101
|
-
} catch {
|
|
102
|
-
return !1;
|
|
103
|
-
}
|
|
104
|
-
}, J = (s) => (s == null ? void 0 : s.type) === "created", Ue = (s) => (s == null ? void 0 : s.type) === "published";
|
|
105
|
-
function Pe(s) {
|
|
106
|
-
return Array.isArray(s);
|
|
107
|
-
}
|
|
108
|
-
function b(s) {
|
|
109
|
-
return !Array.isArray(s) && typeof s == "object" && "fields" in s && "type" in s;
|
|
110
|
-
}
|
|
111
|
-
function F(s) {
|
|
112
|
-
return typeof s == "object" && !Pe(s) && !b(s);
|
|
113
|
-
}
|
|
114
|
-
function Fe(s) {
|
|
115
|
-
return typeof s == "object" && "id" in s;
|
|
116
|
-
}
|
|
117
|
-
const Re = async (s, e) => {
|
|
118
|
-
const { data: t, error: n } = await s.getObject({
|
|
119
|
-
id: e,
|
|
120
|
-
options: { showContent: !0 }
|
|
121
|
-
});
|
|
122
|
-
if (n)
|
|
123
|
-
throw new Error("Error getting object: " + n);
|
|
124
|
-
if (!t || !b(t.content))
|
|
125
|
-
throw new Error(`Cannot get oject for state id ${e}: ` + t);
|
|
126
|
-
return ie(t.content.type);
|
|
127
|
-
}, M = async (s, e) => {
|
|
128
|
-
if (!ke(e))
|
|
129
|
-
throw new Error(`Invalid object ID: ${e}`);
|
|
130
|
-
const t = await s.getObject({
|
|
131
|
-
id: e,
|
|
132
|
-
options: {
|
|
133
|
-
showContent: !0
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
return N(t);
|
|
137
|
-
}, V = async (s, e) => {
|
|
138
|
-
let t, n;
|
|
139
|
-
do {
|
|
140
|
-
const i = await s.getDynamicFields({
|
|
141
|
-
parentId: e,
|
|
142
|
-
cursor: n
|
|
143
|
-
});
|
|
144
|
-
t = i.data.find((a) => a.name.type.endsWith("CurrentPackage")), n = i.hasNextPage ? i.nextCursor : null;
|
|
145
|
-
} while (n && !t);
|
|
146
|
-
if (!t)
|
|
147
|
-
throw new Error("CurrentPackage not found");
|
|
148
|
-
const r = await s.getObject({
|
|
149
|
-
id: t.objectId,
|
|
150
|
-
options: {
|
|
151
|
-
showContent: !0
|
|
152
|
-
}
|
|
153
|
-
}), o = N(r);
|
|
154
|
-
if (!o || !F(o))
|
|
155
|
-
throw new Error("Unable to get fields from object response");
|
|
156
|
-
if (!("value" in o) || !b(o.value))
|
|
157
|
-
throw new Error("Unable to get package id");
|
|
158
|
-
return o.value.fields.package;
|
|
159
|
-
}, Ne = async (s, e, t) => {
|
|
160
|
-
let n = null, r = null, o = null, i;
|
|
161
|
-
do {
|
|
162
|
-
if (o = await s.getOwnedObjects({
|
|
163
|
-
owner: t,
|
|
164
|
-
filter: {
|
|
165
|
-
StructType: `${e}::emitter::EmitterCap`
|
|
166
|
-
},
|
|
167
|
-
options: {
|
|
168
|
-
showContent: !0
|
|
169
|
-
},
|
|
170
|
-
cursor: i
|
|
171
|
-
}), !o || !o.data)
|
|
172
|
-
throw Error("Failed to get owned objects");
|
|
173
|
-
for (const a of o.data) {
|
|
174
|
-
if (!a.data)
|
|
175
|
-
continue;
|
|
176
|
-
const { version: c, objectId: u } = a.data;
|
|
177
|
-
(n === null || c < n) && (n = c, r = u);
|
|
178
|
-
}
|
|
179
|
-
i = o.hasNextPage ? o.nextCursor : void 0;
|
|
180
|
-
} while (i);
|
|
181
|
-
return r;
|
|
182
|
-
}, Me = async (s, e) => {
|
|
183
|
-
const t = new B(), [n] = t.publish({
|
|
184
|
-
modules: s.modules.map((r) => Array.from(ae.decode(r))),
|
|
185
|
-
dependencies: s.dependencies.map((r) => oe(r))
|
|
186
|
-
});
|
|
187
|
-
return t.transferObjects([n], t.pure.address(e)), t;
|
|
188
|
-
}, C = class C extends be {
|
|
189
|
-
constructor(e, t) {
|
|
190
|
-
super(e, t ?? Ie(e, C._platform));
|
|
191
|
-
}
|
|
192
|
-
getRpc(e) {
|
|
193
|
-
if (e in this.config)
|
|
194
|
-
return new je({ url: this.config[e].rpc });
|
|
195
|
-
throw new Error("No configuration available for chain: " + e);
|
|
196
|
-
}
|
|
197
|
-
getChain(e) {
|
|
198
|
-
if (e in this.config)
|
|
199
|
-
return new xe(e, this);
|
|
200
|
-
throw new Error("No configuration available for chain: " + e);
|
|
201
|
-
}
|
|
202
|
-
static nativeTokenId(e, t) {
|
|
203
|
-
if (!C.isSupportedChain(t))
|
|
204
|
-
throw new Error(`invalid chain for ${te}: ${t}`);
|
|
205
|
-
return ve.tokenId(t, z);
|
|
206
|
-
}
|
|
207
|
-
static isNativeTokenId(e, t, n) {
|
|
208
|
-
return !C.isSupportedChain(t) || n.chain !== t ? !1 : this.nativeTokenId(e, t) === n;
|
|
209
|
-
}
|
|
210
|
-
static isSupportedChain(e) {
|
|
211
|
-
return Ce(e) === C._platform;
|
|
212
|
-
}
|
|
213
|
-
static async getDecimals(e, t, n) {
|
|
214
|
-
if (v(n))
|
|
215
|
-
return Be(C._platform);
|
|
216
|
-
const r = new m(n);
|
|
217
|
-
try {
|
|
218
|
-
const i = await M(t, r.toString());
|
|
219
|
-
if (i && "decimals" in i)
|
|
220
|
-
return i.decimals;
|
|
221
|
-
} catch {
|
|
222
|
-
}
|
|
223
|
-
const o = await t.getCoinMetadata({ coinType: r.toString() });
|
|
224
|
-
if (o === null)
|
|
225
|
-
throw new Error(`Can't fetch decimals for token ${r.toString()}`);
|
|
226
|
-
return o.decimals;
|
|
227
|
-
}
|
|
228
|
-
static async getCoins(e, t, n) {
|
|
229
|
-
let r = [], o = null;
|
|
230
|
-
const i = new m(t).toString();
|
|
231
|
-
do {
|
|
232
|
-
const a = await e.getCoins({
|
|
233
|
-
owner: i,
|
|
234
|
-
coinType: n,
|
|
235
|
-
cursor: o
|
|
236
|
-
});
|
|
237
|
-
r = [...r, ...a.data], o = a.hasNextPage ? a.nextCursor : null;
|
|
238
|
-
} while (o);
|
|
239
|
-
return r;
|
|
240
|
-
}
|
|
241
|
-
static async getBalance(e, t, n, r) {
|
|
242
|
-
if (v(r)) {
|
|
243
|
-
const { totalBalance: i } = await t.getBalance({
|
|
244
|
-
owner: n
|
|
245
|
-
});
|
|
246
|
-
return BigInt(i);
|
|
247
|
-
}
|
|
248
|
-
const { totalBalance: o } = await t.getBalance({
|
|
249
|
-
owner: n,
|
|
250
|
-
coinType: r.toString()
|
|
251
|
-
});
|
|
252
|
-
return BigInt(o);
|
|
253
|
-
}
|
|
254
|
-
static async getBalances(e, t, n, r) {
|
|
255
|
-
return (await Promise.all(r.map(async (i) => {
|
|
256
|
-
const a = await this.getBalance(e, t, n, i);
|
|
257
|
-
return { [v(i) ? "native" : new m(i).toString()]: a };
|
|
258
|
-
}))).reduce((i, a) => Object.assign(i, a), {});
|
|
259
|
-
}
|
|
260
|
-
static async sendWait(e, t, n) {
|
|
261
|
-
const r = [];
|
|
262
|
-
for (const o of n) {
|
|
263
|
-
const i = await t.executeTransactionBlock(o);
|
|
264
|
-
await t.waitForTransaction({ digest: i.digest }), r.push(i.digest);
|
|
265
|
-
}
|
|
266
|
-
return r;
|
|
267
|
-
}
|
|
268
|
-
static async getLatestBlock(e) {
|
|
269
|
-
return Number(await e.getLatestCheckpointSequenceNumber());
|
|
270
|
-
}
|
|
271
|
-
static async getLatestFinalizedBlock(e) {
|
|
272
|
-
return this.getLatestBlock(e);
|
|
273
|
-
}
|
|
274
|
-
static chainFromChainId(e) {
|
|
275
|
-
const t = Te(C._platform, e);
|
|
276
|
-
if (t === void 0)
|
|
277
|
-
throw new Error(`Unknown native chain id ${e}`);
|
|
278
|
-
const [n, r] = t;
|
|
279
|
-
return [n, r];
|
|
280
|
-
}
|
|
281
|
-
static async chainFromRpc(e) {
|
|
282
|
-
const t = await e.call("sui_getChainIdentifier", []);
|
|
283
|
-
return this.chainFromChainId(t);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
g(C, "_platform", te);
|
|
287
|
-
let I = C;
|
|
288
|
-
const re = async (s, e, t) => {
|
|
289
|
-
var i, a, c;
|
|
290
|
-
if (!R(t))
|
|
291
|
-
throw new Error(`Invalid Sui type: ${t}`);
|
|
292
|
-
const n = await M(s, e);
|
|
293
|
-
if (!n)
|
|
294
|
-
throw new Error(`Unable to fetch object fields from token bridge state. Object ID: ${e}`);
|
|
295
|
-
const r = (a = (i = n.token_registry.fields) == null ? void 0 : i.id) == null ? void 0 : a.id;
|
|
296
|
-
if (!r)
|
|
297
|
-
throw new Error("Unable to fetch token registry object ID");
|
|
298
|
-
const o = ie((c = n.token_registry) == null ? void 0 : c.type);
|
|
299
|
-
if (!o)
|
|
300
|
-
throw new Error("Unable to fetch token registry package ID");
|
|
301
|
-
return s.getDynamicFieldObject({
|
|
302
|
-
parentId: r,
|
|
303
|
-
name: {
|
|
304
|
-
type: `${o}::token_registry::Key<${t}>`,
|
|
305
|
-
value: {
|
|
306
|
-
dummy_field: !1
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}, D = async (s, e, t, n) => {
|
|
311
|
-
var d, h, p, y;
|
|
312
|
-
const r = await M(s, e);
|
|
313
|
-
if (!r)
|
|
314
|
-
throw new Error("Unable to fetch object fields from token bridge state");
|
|
315
|
-
const o = (h = (d = r.token_registry) == null ? void 0 : d.fields) == null ? void 0 : h.coin_types, i = (y = (p = o == null ? void 0 : o.fields) == null ? void 0 : p.id) == null ? void 0 : y.id;
|
|
316
|
-
if (!i)
|
|
317
|
-
throw new Error("Unable to fetch coin types");
|
|
318
|
-
const a = ce(o == null ? void 0 : o.type);
|
|
319
|
-
if (!a)
|
|
320
|
-
throw new Error("Unable to get key type");
|
|
321
|
-
const c = await s.getDynamicFieldObject({
|
|
322
|
-
parentId: i,
|
|
323
|
-
name: {
|
|
324
|
-
type: a,
|
|
325
|
-
value: {
|
|
326
|
-
addr: [...t],
|
|
327
|
-
chain: n
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
if (c.error) {
|
|
332
|
-
if (c.error.code === "dynamicFieldNotFound")
|
|
333
|
-
return null;
|
|
334
|
-
throw new Error(`Unexpected getDynamicFieldObject response ${c.error}`);
|
|
335
|
-
}
|
|
336
|
-
const u = N(c);
|
|
337
|
-
if (!u)
|
|
338
|
-
return null;
|
|
339
|
-
if (!F(u))
|
|
340
|
-
throw new Error("What?");
|
|
341
|
-
return "value" in u ? U(u.value) : null;
|
|
342
|
-
};
|
|
343
|
-
class G {
|
|
344
|
-
constructor(e, t, n, r) {
|
|
345
|
-
g(this, "network");
|
|
346
|
-
g(this, "chain");
|
|
347
|
-
g(this, "provider");
|
|
348
|
-
g(this, "contracts");
|
|
349
|
-
g(this, "coreBridgeObjectId");
|
|
350
|
-
g(this, "tokenBridgeObjectId");
|
|
351
|
-
g(this, "chainId");
|
|
352
|
-
this.network = e, this.chain = t, this.provider = n, this.contracts = r, this.chainId = Ee.get(e, t);
|
|
353
|
-
const o = this.contracts.tokenBridge;
|
|
354
|
-
if (!o)
|
|
355
|
-
throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);
|
|
356
|
-
const i = this.contracts.coreBridge;
|
|
357
|
-
if (!i)
|
|
358
|
-
throw new Error(`Wormhole Token Bridge contract for domain ${t} not found`);
|
|
359
|
-
this.tokenBridgeObjectId = o, this.coreBridgeObjectId = i;
|
|
360
|
-
}
|
|
361
|
-
static async fromRpc(e, t) {
|
|
362
|
-
const [n, r] = await I.chainFromRpc(e), o = t[r];
|
|
363
|
-
if (o.network !== n)
|
|
364
|
-
throw new Error(`Network mismatch: ${o.network} != ${n}`);
|
|
365
|
-
return new G(n, r, e, o.contracts);
|
|
366
|
-
}
|
|
367
|
-
async isWrappedAsset(e) {
|
|
368
|
-
try {
|
|
369
|
-
return await this.getOriginalAsset(e), !0;
|
|
370
|
-
} catch {
|
|
371
|
-
return !1;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
async getOriginalAsset(e) {
|
|
375
|
-
let t = e.getCoinType();
|
|
376
|
-
if (!R(t))
|
|
377
|
-
throw new Error(`Invalid Sui type: ${t}`);
|
|
378
|
-
const n = await re(this.provider, this.tokenBridgeObjectId, t), r = N(n);
|
|
379
|
-
if (!r)
|
|
380
|
-
throw L(t);
|
|
381
|
-
if (!F(r))
|
|
382
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
383
|
-
if (!("value" in r))
|
|
384
|
-
throw new Error("Expected a `value` key in fields of MoveStruct");
|
|
385
|
-
const o = r.value;
|
|
386
|
-
if (!b(o))
|
|
387
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
388
|
-
const i = U(o.type);
|
|
389
|
-
if (t = U(t), i.includes(`wrapped_asset::WrappedAsset<${t}>`)) {
|
|
390
|
-
const a = o.fields.info;
|
|
391
|
-
if (!b(a))
|
|
392
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
393
|
-
const c = a.fields.token_address;
|
|
394
|
-
if (!b(c))
|
|
395
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
396
|
-
if (!F(c.fields))
|
|
397
|
-
throw new Error("Expected address data to be a MoveObject");
|
|
398
|
-
if (!("value" in c.fields))
|
|
399
|
-
throw new Error("Expected a `value` key in fields of MoveStruct");
|
|
400
|
-
const u = c.fields.value;
|
|
401
|
-
if (!b(u))
|
|
402
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
403
|
-
const d = new Uint8Array(u.fields.data);
|
|
404
|
-
return {
|
|
405
|
-
chain: _e(Number(a.fields.token_chain)),
|
|
406
|
-
address: new W(d)
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
throw L(t);
|
|
410
|
-
}
|
|
411
|
-
async getTokenUniversalAddress(e) {
|
|
412
|
-
let t = e.getCoinType();
|
|
413
|
-
if (!R(t))
|
|
414
|
-
throw new Error(`Invalid Sui type: ${t}`);
|
|
415
|
-
const n = await re(this.provider, this.tokenBridgeObjectId, t), r = N(n);
|
|
416
|
-
if (!r)
|
|
417
|
-
throw new Error(`Token of type ${t} has not been registered with the token bridge. Has it been attested?`);
|
|
418
|
-
if (!F(r))
|
|
419
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
420
|
-
if (!("value" in r))
|
|
421
|
-
throw new Error("Expected a `value` key in fields of MoveStruct");
|
|
422
|
-
const o = r.value;
|
|
423
|
-
if (!b(o))
|
|
424
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
425
|
-
const i = U(o.type);
|
|
426
|
-
if (t = U(t), i.includes(`native_asset::NativeAsset<${t}>`)) {
|
|
427
|
-
const a = o.fields.token_address;
|
|
428
|
-
if (!b(a))
|
|
429
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
430
|
-
if (!("value" in a.fields))
|
|
431
|
-
throw new Error("Expected a `value` key in fields of MoveStruct");
|
|
432
|
-
const c = a.fields.value;
|
|
433
|
-
if (!b(c))
|
|
434
|
-
throw new Error("Expected fields to be a MoveStruct");
|
|
435
|
-
const u = new Uint8Array(c.fields.data);
|
|
436
|
-
return new W(u);
|
|
437
|
-
}
|
|
438
|
-
throw new Error(`Token of type ${t} is not a native asset`);
|
|
439
|
-
}
|
|
440
|
-
async getTokenNativeAddress(e, t) {
|
|
441
|
-
const n = await D(this.provider, this.tokenBridgeObjectId, t.toUint8Array(), E(e));
|
|
442
|
-
if (!n)
|
|
443
|
-
throw new Error(`Token ${t.toString()} not found in token registry`);
|
|
444
|
-
return new m(n);
|
|
445
|
-
}
|
|
446
|
-
async hasWrappedAsset(e) {
|
|
447
|
-
try {
|
|
448
|
-
return await this.getWrappedAsset(e), !0;
|
|
449
|
-
} catch {
|
|
450
|
-
}
|
|
451
|
-
return !1;
|
|
452
|
-
}
|
|
453
|
-
async getWrappedAsset(e) {
|
|
454
|
-
if (v(e.address))
|
|
455
|
-
throw new Error("Token Address required, 'native' literal not supported");
|
|
456
|
-
const t = await D(this.provider, this.tokenBridgeObjectId, e.address.toUniversalAddress().toUint8Array(), E(e.chain));
|
|
457
|
-
if (!t)
|
|
458
|
-
throw L(Ae(e));
|
|
459
|
-
return Q(this.chain, t);
|
|
460
|
-
}
|
|
461
|
-
async isTransferCompleted(e) {
|
|
462
|
-
var a, c, u, d, h, p, y, k;
|
|
463
|
-
const t = await M(this.provider, this.tokenBridgeObjectId);
|
|
464
|
-
if (!t)
|
|
465
|
-
throw new Error("Unable to fetch object fields from token bridge state");
|
|
466
|
-
const n = (c = (a = t.consumed_vaas) == null ? void 0 : a.fields) == null ? void 0 : c.hashes, r = ce((d = (u = n == null ? void 0 : n.fields) == null ? void 0 : u.items) == null ? void 0 : d.type);
|
|
467
|
-
if (!r)
|
|
468
|
-
throw new Error("Unable to get key type");
|
|
469
|
-
const o = (k = (y = (p = (h = n == null ? void 0 : n.fields) == null ? void 0 : h.items) == null ? void 0 : p.fields) == null ? void 0 : y.id) == null ? void 0 : k.id;
|
|
470
|
-
if (!o)
|
|
471
|
-
throw new Error("Unable to fetch consumed VAAs table");
|
|
472
|
-
const i = await this.provider.getDynamicFieldObject({
|
|
473
|
-
parentId: o,
|
|
474
|
-
name: {
|
|
475
|
-
type: r,
|
|
476
|
-
value: {
|
|
477
|
-
data: [...Oe(e.hash)]
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
if (!i.error)
|
|
482
|
-
return !0;
|
|
483
|
-
if (i.error.code === "dynamicFieldNotFound")
|
|
484
|
-
return !1;
|
|
485
|
-
throw new Error(`Unexpected getDynamicFieldObject response ${i.error}`);
|
|
486
|
-
}
|
|
487
|
-
async *createAttestation(e) {
|
|
488
|
-
const t = 0n, r = e.toString(), o = await this.provider.getCoinMetadata({ coinType: r });
|
|
489
|
-
if (o === null || o.id === null)
|
|
490
|
-
throw new Error(`Coin metadata ID for type ${r} not found`);
|
|
491
|
-
const [i, a] = await this.getPackageIds(), c = new B(), [u] = c.splitCoins(c.gas, [c.pure.u64(t)]), [d] = c.moveCall({
|
|
492
|
-
target: `${a}::attest_token::attest_token`,
|
|
493
|
-
arguments: [c.object(this.tokenBridgeObjectId), c.object(o.id), c.pure.u32(0)],
|
|
494
|
-
typeArguments: [r]
|
|
495
|
-
});
|
|
496
|
-
c.moveCall({
|
|
497
|
-
target: `${i}::publish_message::publish_message`,
|
|
498
|
-
arguments: [
|
|
499
|
-
c.object(this.coreBridgeObjectId),
|
|
500
|
-
u,
|
|
501
|
-
d,
|
|
502
|
-
c.object(O)
|
|
503
|
-
]
|
|
504
|
-
}), yield this.createUnsignedTx(c, "Sui.TokenBridge.CreateAttestation");
|
|
505
|
-
}
|
|
506
|
-
async *submitAttestation(e, t) {
|
|
507
|
-
const [n, r] = await this.getPackageIds(), o = t.toString(), i = Math.min(e.payload.decimals, 8), a = await this.getCoinBuildOutput(n, r, i), c = await Me(a, o);
|
|
508
|
-
yield this.createUnsignedTx(c, "Sui.TokenBridge.PrepareCreateWrapped");
|
|
509
|
-
let u = "", d = "", h = "", p = "", y = "", k = !1;
|
|
510
|
-
for (; !k; ) {
|
|
511
|
-
await new Promise((w) => setTimeout(w, 500));
|
|
512
|
-
const _ = await this.provider.queryTransactionBlocks({
|
|
513
|
-
filter: { FromAddress: o },
|
|
514
|
-
options: { showObjectChanges: !0 },
|
|
515
|
-
limit: 3
|
|
516
|
-
});
|
|
517
|
-
for (const w of _.data)
|
|
518
|
-
if ("objectChanges" in w) {
|
|
519
|
-
for (const f of w.objectChanges)
|
|
520
|
-
Ue(f) && f.packageId !== void 0 ? u = f.packageId : J(f) && f.objectType.includes("WrappedAssetSetup") ? (d = f.objectId, y = f.objectType.split(", ")[1].replace(">", "")) : J(f) && f.objectType.includes("UpgradeCap") ? h = f.objectId : J(f) && f.objectType.includes("CoinMetadata") && (p = f.objectId);
|
|
521
|
-
if (u !== "" && d !== "" && h !== "" && p !== "") {
|
|
522
|
-
k = !0;
|
|
523
|
-
break;
|
|
524
|
-
} else
|
|
525
|
-
u = "", d = "", h = "", p = "";
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
const j = $e(u), l = new B(), [$] = l.moveCall({
|
|
529
|
-
target: `${n}::vaa::parse_and_verify`,
|
|
530
|
-
arguments: [
|
|
531
|
-
l.object(this.coreBridgeObjectId),
|
|
532
|
-
l.pure.vector("u8", K(e)),
|
|
533
|
-
l.object(O)
|
|
534
|
-
]
|
|
535
|
-
}), [x] = l.moveCall({
|
|
536
|
-
target: `${r}::vaa::verify_only_once`,
|
|
537
|
-
arguments: [l.object(this.tokenBridgeObjectId), $]
|
|
538
|
-
});
|
|
539
|
-
l.moveCall({
|
|
540
|
-
target: `${r}::create_wrapped::complete_registration`,
|
|
541
|
-
arguments: [
|
|
542
|
-
l.object(this.tokenBridgeObjectId),
|
|
543
|
-
l.object(p),
|
|
544
|
-
l.object(d),
|
|
545
|
-
l.object(h),
|
|
546
|
-
x
|
|
547
|
-
],
|
|
548
|
-
typeArguments: [j, y]
|
|
549
|
-
}), yield this.createUnsignedTx(l, "Sui.TokenBridge.SubmitAttestation");
|
|
550
|
-
}
|
|
551
|
-
async *transfer(e, t, n, r, o) {
|
|
552
|
-
const i = 0n, a = 0n, u = e.toString(), d = (v(n) ? q : n).toString(), h = await I.getCoins(this.provider, e, d), [p, ...y] = h.filter((w) => le(w.coinType, d));
|
|
553
|
-
if (p === void 0)
|
|
554
|
-
throw new Error(`Coins array doesn't contain any coins of type ${d}`);
|
|
555
|
-
const [k, j] = await this.getPackageIds(), l = new B(), [$] = (() => {
|
|
556
|
-
if (d === q)
|
|
557
|
-
return l.splitCoins(l.gas, [l.pure.u64(r)]);
|
|
558
|
-
{
|
|
559
|
-
const w = l.object(p.coinObjectId);
|
|
560
|
-
return y.length && l.mergeCoins(w, y.map((f) => l.object(f.coinObjectId))), l.splitCoins(w, [l.pure.u64(r)]);
|
|
561
|
-
}
|
|
562
|
-
})(), [x] = l.splitCoins(l.gas, [l.pure.u64(i)]), [_] = l.moveCall({
|
|
563
|
-
target: `${j}::state::verified_asset`,
|
|
564
|
-
arguments: [l.object(this.tokenBridgeObjectId)],
|
|
565
|
-
typeArguments: [d]
|
|
566
|
-
});
|
|
567
|
-
if (o) {
|
|
568
|
-
if (!u)
|
|
569
|
-
throw new Error("senderAddress is required for transfer with payload");
|
|
570
|
-
let w = !1;
|
|
571
|
-
const f = await (async () => {
|
|
572
|
-
const Y = await Ne(this.provider, k, u);
|
|
573
|
-
if (Y !== null)
|
|
574
|
-
return l.object(Y);
|
|
575
|
-
{
|
|
576
|
-
const [fe] = l.moveCall({
|
|
577
|
-
target: `${k}::emitter::new`,
|
|
578
|
-
arguments: [l.object(this.coreBridgeObjectId)]
|
|
579
|
-
});
|
|
580
|
-
return w = !0, fe;
|
|
581
|
-
}
|
|
582
|
-
})(), [A, ue] = l.moveCall({
|
|
583
|
-
target: `${j}::transfer_tokens_with_payload::prepare_transfer`,
|
|
584
|
-
arguments: [
|
|
585
|
-
f,
|
|
586
|
-
_,
|
|
587
|
-
$,
|
|
588
|
-
l.pure.u16(E(t.chain)),
|
|
589
|
-
l.pure.vector("u8", t.address.toUint8Array()),
|
|
590
|
-
l.pure.vector("u8", o),
|
|
591
|
-
l.pure.u32(0)
|
|
592
|
-
],
|
|
593
|
-
typeArguments: [d]
|
|
594
|
-
});
|
|
595
|
-
l.moveCall({
|
|
596
|
-
target: `${j}::coin_utils::return_nonzero`,
|
|
597
|
-
arguments: [ue],
|
|
598
|
-
typeArguments: [d]
|
|
599
|
-
});
|
|
600
|
-
const [ge] = l.moveCall({
|
|
601
|
-
target: `${j}::transfer_tokens_with_payload::transfer_tokens_with_payload`,
|
|
602
|
-
arguments: [l.object(this.tokenBridgeObjectId), A],
|
|
603
|
-
typeArguments: [d]
|
|
604
|
-
});
|
|
605
|
-
l.moveCall({
|
|
606
|
-
target: `${k}::publish_message::publish_message`,
|
|
607
|
-
arguments: [
|
|
608
|
-
l.object(this.coreBridgeObjectId),
|
|
609
|
-
x,
|
|
610
|
-
ge,
|
|
611
|
-
l.object(O)
|
|
612
|
-
]
|
|
613
|
-
}), w && l.transferObjects([f], l.pure.address(u)), yield this.createUnsignedTx(l, "Sui.TokenBridge.TransferWithPayload");
|
|
614
|
-
} else {
|
|
615
|
-
const [w, f] = l.moveCall({
|
|
616
|
-
target: `${j}::transfer_tokens::prepare_transfer`,
|
|
617
|
-
arguments: [
|
|
618
|
-
_,
|
|
619
|
-
$,
|
|
620
|
-
l.pure.u16(E(t.chain)),
|
|
621
|
-
l.pure.vector("u8", t.address.toUint8Array()),
|
|
622
|
-
l.pure.u64(a),
|
|
623
|
-
l.pure.u32(0)
|
|
624
|
-
],
|
|
625
|
-
typeArguments: [d]
|
|
626
|
-
});
|
|
627
|
-
l.moveCall({
|
|
628
|
-
target: `${j}::coin_utils::return_nonzero`,
|
|
629
|
-
arguments: [f],
|
|
630
|
-
typeArguments: [d]
|
|
631
|
-
});
|
|
632
|
-
const [A] = l.moveCall({
|
|
633
|
-
target: `${j}::transfer_tokens::transfer_tokens`,
|
|
634
|
-
arguments: [l.object(this.tokenBridgeObjectId), w],
|
|
635
|
-
typeArguments: [d]
|
|
636
|
-
});
|
|
637
|
-
l.moveCall({
|
|
638
|
-
target: `${k}::publish_message::publish_message`,
|
|
639
|
-
arguments: [
|
|
640
|
-
l.object(this.coreBridgeObjectId),
|
|
641
|
-
x,
|
|
642
|
-
A,
|
|
643
|
-
l.object(O)
|
|
644
|
-
]
|
|
645
|
-
}), yield this.createUnsignedTx(l, "Sui.TokenBridge.Transfer");
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
async *redeem(e, t, n = !0) {
|
|
649
|
-
const r = await D(this.provider, this.tokenBridgeObjectId, t.payload.token.address.toUint8Array(), E(t.payload.token.chain));
|
|
650
|
-
if (!r)
|
|
651
|
-
throw new Error("Unable to fetch token coinType");
|
|
652
|
-
const [o, i] = await this.getPackageIds(), a = new B(), [c] = a.moveCall({
|
|
653
|
-
target: `${o}::vaa::parse_and_verify`,
|
|
654
|
-
arguments: [
|
|
655
|
-
a.object(this.coreBridgeObjectId),
|
|
656
|
-
a.pure.vector("u8", K(t)),
|
|
657
|
-
a.object(O)
|
|
658
|
-
]
|
|
659
|
-
}), [u] = a.moveCall({
|
|
660
|
-
target: `${i}::vaa::verify_only_once`,
|
|
661
|
-
arguments: [a.object(this.tokenBridgeObjectId), c]
|
|
662
|
-
}), [d] = a.moveCall({
|
|
663
|
-
target: `${i}::complete_transfer::authorize_transfer`,
|
|
664
|
-
arguments: [a.object(this.tokenBridgeObjectId), u],
|
|
665
|
-
typeArguments: [r]
|
|
666
|
-
}), [h] = a.moveCall({
|
|
667
|
-
target: `${i}::complete_transfer::redeem_relayer_payout`,
|
|
668
|
-
arguments: [d],
|
|
669
|
-
typeArguments: [r]
|
|
670
|
-
});
|
|
671
|
-
a.moveCall({
|
|
672
|
-
target: `${i}::coin_utils::return_nonzero`,
|
|
673
|
-
arguments: [h],
|
|
674
|
-
typeArguments: [r]
|
|
675
|
-
}), yield this.createUnsignedTx(a, "Sui.TokenBridge.Redeem");
|
|
676
|
-
}
|
|
677
|
-
async getWrappedNative() {
|
|
678
|
-
return Q(this.chain, q);
|
|
679
|
-
}
|
|
680
|
-
async getPackageIds() {
|
|
681
|
-
return Promise.all([
|
|
682
|
-
V(this.provider, this.coreBridgeObjectId),
|
|
683
|
-
V(this.provider, this.tokenBridgeObjectId)
|
|
684
|
-
]);
|
|
685
|
-
}
|
|
686
|
-
async getCoinBuildOutput(e, t, n) {
|
|
687
|
-
var a;
|
|
688
|
-
if (n > 8)
|
|
689
|
-
throw new Error("Decimals is capped at 8");
|
|
690
|
-
const r = (a = await Re(this.provider, this.tokenBridgeObjectId)) == null ? void 0 : a.replace("0x", "");
|
|
691
|
-
if (!r)
|
|
692
|
-
throw new Error(`Original token bridge package ID not found for object ID ${this.tokenBridgeObjectId}`);
|
|
693
|
-
const o = "a11ceb0b060000000901000a020a14031e1704350405392d07669f01088502600ae502050cea02160004010b010c0205020d000002000201020003030c020001000104020700000700010001090801010c020a050600030803040202000302010702080007080100020800080303090002070801010b020209000901010608010105010b0202080008030209000504434f494e095478436f6e7465787408565f5f305f325f3011577261707065644173736574536574757004636f696e0e6372656174655f777261707065640b64756d6d795f6669656c6404696e697414707265706172655f726567697374726174696f6e0f7075626c69635f7472616e736665720673656e646572087472616e736665720a74785f636f6e746578740f76657273696f6e5f636f6e74726f6c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002" + r + "00020106010000000001090b0031" + n.toString(16).padStart(2, "0") + "0a0138000b012e110238010200";
|
|
694
|
-
return {
|
|
695
|
-
modules: [ae.encode(T.decode(o))],
|
|
696
|
-
dependencies: ["0x1", "0x2", t, e].map((c) => oe(c))
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
createUnsignedTx(e, t, n = !1) {
|
|
700
|
-
return new de(e, this.network, this.chain, t, n);
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
class H {
|
|
704
|
-
constructor(e, t, n, r) {
|
|
705
|
-
g(this, "network");
|
|
706
|
-
g(this, "chain");
|
|
707
|
-
g(this, "connection");
|
|
708
|
-
g(this, "contracts");
|
|
709
|
-
g(this, "tokenBridgeRelayerObjectId");
|
|
710
|
-
g(this, "coreBridgeObjectId");
|
|
711
|
-
g(this, "tokenBridgeObjectId");
|
|
712
|
-
g(this, "fields");
|
|
713
|
-
this.network = e, this.chain = t, this.connection = n, this.contracts = r;
|
|
714
|
-
const { tokenBridge: o, tokenBridgeRelayer: i, coreBridge: a } = r;
|
|
715
|
-
if (!o || !i || !a)
|
|
716
|
-
throw new Error(`Some object IDs for ${t} Automatic Token Bridge not found`);
|
|
717
|
-
this.tokenBridgeRelayerObjectId = i, this.tokenBridgeObjectId = o, this.coreBridgeObjectId = a;
|
|
718
|
-
}
|
|
719
|
-
static async fromRpc(e, t) {
|
|
720
|
-
const [n, r] = await I.chainFromRpc(e), o = t[r];
|
|
721
|
-
if (o.network !== n)
|
|
722
|
-
throw new Error(`Network mismatch for chain ${r}: ${o.network} != ${n}`);
|
|
723
|
-
return new H(n, r, e, o.contracts);
|
|
724
|
-
}
|
|
725
|
-
async *transfer(e, t, n, r, o) {
|
|
726
|
-
const a = new m(v(n) ? I.nativeTokenId(this.network, this.chain).address : n).getCoinType(), { coreBridge: c, tokenBridge: u } = await this.getPackageIds(), d = new B(), h = BigInt(0), [p] = d.splitCoins(d.gas, [d.pure.u64(h)]), [y] = await (async () => {
|
|
727
|
-
if (v(n))
|
|
728
|
-
return d.splitCoins(d.gas, [d.pure.u64(r)]);
|
|
729
|
-
{
|
|
730
|
-
const x = await I.getCoins(this.connection, e, a), [_, ...w] = x.filter((A) => A.coinType === a);
|
|
731
|
-
if (_ === void 0)
|
|
732
|
-
throw new Error(`Coins array doesn't contain any coins of type ${a}`);
|
|
733
|
-
const f = d.object(_.coinObjectId);
|
|
734
|
-
return w.length && d.mergeCoins(f, w.map((A) => d.object(A.coinObjectId))), d.splitCoins(f, [d.pure.u64(r)]);
|
|
735
|
-
}
|
|
736
|
-
})(), [k] = d.moveCall({
|
|
737
|
-
target: `${u}::state::verified_asset`,
|
|
738
|
-
arguments: [d.object(this.tokenBridgeObjectId)],
|
|
739
|
-
typeArguments: [a]
|
|
740
|
-
}), j = await this.getPackageId(), [l] = d.moveCall({
|
|
741
|
-
target: `${j}::transfer::transfer_tokens_with_relay`,
|
|
742
|
-
arguments: [
|
|
743
|
-
d.object(this.tokenBridgeRelayerObjectId),
|
|
744
|
-
y,
|
|
745
|
-
k,
|
|
746
|
-
d.pure.u64(o ?? 0n),
|
|
747
|
-
d.pure.u16(E(t.chain)),
|
|
748
|
-
d.pure.address(T.encode(t.address.toUint8Array(), !0)),
|
|
749
|
-
d.pure.u32(123)
|
|
750
|
-
],
|
|
751
|
-
typeArguments: [a]
|
|
752
|
-
}), [$] = d.moveCall({
|
|
753
|
-
target: `${u}::transfer_tokens_with_payload::transfer_tokens_with_payload`,
|
|
754
|
-
arguments: [d.object(this.tokenBridgeObjectId), l],
|
|
755
|
-
typeArguments: [a]
|
|
756
|
-
});
|
|
757
|
-
d.moveCall({
|
|
758
|
-
target: `${c}::publish_message::publish_message`,
|
|
759
|
-
arguments: [
|
|
760
|
-
d.object(this.coreBridgeObjectId),
|
|
761
|
-
p,
|
|
762
|
-
$,
|
|
763
|
-
d.object(O)
|
|
764
|
-
]
|
|
765
|
-
}), yield this.createUnsignedTx(d, "AutomaticTokenBridge.transfer");
|
|
766
|
-
}
|
|
767
|
-
async *redeem(e, t) {
|
|
768
|
-
const { coreBridge: n, tokenBridge: r } = await this.getPackageIds(), { address: o, chain: i } = t.payload.token, a = await D(this.connection, this.tokenBridgeObjectId, o.toUniversalAddress().toUint8Array(), E(i));
|
|
769
|
-
if (!a)
|
|
770
|
-
throw new Error("Unable to fetch token coinType");
|
|
771
|
-
const c = new B(), [u] = c.moveCall({
|
|
772
|
-
target: `${n}::vaa::parse_and_verify`,
|
|
773
|
-
arguments: [
|
|
774
|
-
c.object(this.coreBridgeObjectId),
|
|
775
|
-
c.pure.vector("u8", K(t)),
|
|
776
|
-
c.object(O)
|
|
777
|
-
]
|
|
778
|
-
}), [d] = c.moveCall({
|
|
779
|
-
target: `${r}::vaa::verify_only_once`,
|
|
780
|
-
arguments: [c.object(this.tokenBridgeObjectId), u]
|
|
781
|
-
}), [h] = c.moveCall({
|
|
782
|
-
target: `${r}::complete_transfer_with_payload::authorize_transfer`,
|
|
783
|
-
arguments: [c.object(this.tokenBridgeObjectId), d],
|
|
784
|
-
typeArguments: [a]
|
|
785
|
-
}), p = await this.getPackageId();
|
|
786
|
-
c.moveCall({
|
|
787
|
-
target: `${p}::redeem::complete_transfer`,
|
|
788
|
-
arguments: [c.object(this.tokenBridgeRelayerObjectId), h],
|
|
789
|
-
typeArguments: [a]
|
|
790
|
-
}), yield this.createUnsignedTx(c, "AutomaticTokenBridge.redeem");
|
|
791
|
-
}
|
|
792
|
-
async getRelayerFee(e, t) {
|
|
793
|
-
const n = v(t) ? I.nativeTokenId(this.network, this.chain) : t, r = await this.getTokenInfo(n.toString());
|
|
794
|
-
if (r === null)
|
|
795
|
-
throw new Error("Unsupported token for relay");
|
|
796
|
-
const o = await this.getFields(), i = await this.connection.getDynamicFieldObject({
|
|
797
|
-
parentId: this.tokenBridgeRelayerObjectId,
|
|
798
|
-
name: { type: "vector<u8>", value: Array.from(ne.encode("relayer_fees")) }
|
|
799
|
-
});
|
|
800
|
-
if (!i.data || !i.data.content)
|
|
801
|
-
throw i.error ? new Error("Failed to get relayer fees: " + JSON.stringify(i.error)) : new Error("Unable to compute relayer fee");
|
|
802
|
-
const { content: a } = i.data;
|
|
803
|
-
if (!b(a) || !Fe(a.fields.id))
|
|
804
|
-
throw new Error("Unable to compute relayer fee");
|
|
805
|
-
const c = await this.connection.getDynamicFieldObject({
|
|
806
|
-
parentId: a.fields.id.id,
|
|
807
|
-
name: { type: "u16", value: E(e) }
|
|
808
|
-
});
|
|
809
|
-
if (!c.data || !c.data.content)
|
|
810
|
-
throw c.error ? new Error("Failed to get relayer fees: " + JSON.stringify(i.error)) : new Error("Unable to compute relayer fee");
|
|
811
|
-
const { content: u } = c.data;
|
|
812
|
-
if (!b(u))
|
|
813
|
-
throw new Error("Unable to compute relayer fee");
|
|
814
|
-
const d = await I.getDecimals(this.chain, this.connection, t.toString()), h = r.swap_rate, p = o.relayer_fee_precision, y = o.swap_rate_precision, k = u.fields.value;
|
|
815
|
-
return 10n ** BigInt(d) * BigInt(k) * BigInt(y) / (BigInt(h) * BigInt(p));
|
|
816
|
-
}
|
|
817
|
-
async maxSwapAmount(e) {
|
|
818
|
-
var c, u;
|
|
819
|
-
const n = (v(e) ? I.nativeTokenId(this.network, this.chain) : e).toString(), r = await this.connection.getCoinMetadata({ coinType: n });
|
|
820
|
-
if (!r)
|
|
821
|
-
throw new Error("metadata is null");
|
|
822
|
-
const o = await this.getPackageId(), i = new B();
|
|
823
|
-
i.moveCall({
|
|
824
|
-
// Calculates the max number of tokens the recipient can convert to native
|
|
825
|
-
// Sui. The max amount of native assets the contract will swap with the
|
|
826
|
-
// recipient is governed by the `max_native_swap_amount` variable.
|
|
827
|
-
target: `${o}::redeem::calculate_max_swap_amount_in`,
|
|
828
|
-
arguments: [i.object(this.tokenBridgeRelayerObjectId), i.pure.u8(r.decimals)],
|
|
829
|
-
typeArguments: [n]
|
|
830
|
-
});
|
|
831
|
-
const a = await this.connection.devInspectTransactionBlock({
|
|
832
|
-
transactionBlock: i,
|
|
833
|
-
sender: T.encode(new Uint8Array(32))
|
|
834
|
-
});
|
|
835
|
-
if (!a.results || a.results.length == 0 || !((c = a.results[0]) != null && c.returnValues) || ((u = a.results[0]) == null ? void 0 : u.returnValues.length) !== 1)
|
|
836
|
-
throw Error("swap rate not set");
|
|
837
|
-
return X.decode(new Uint8Array(a.results[0].returnValues[0][0].toReversed()));
|
|
838
|
-
}
|
|
839
|
-
async nativeTokenAmount(e, t) {
|
|
840
|
-
var u, d;
|
|
841
|
-
const r = (v(e) ? I.nativeTokenId(this.network, this.chain) : e).toString(), o = await this.connection.getCoinMetadata({ coinType: r });
|
|
842
|
-
if (!o)
|
|
843
|
-
throw new Error("metadata is null");
|
|
844
|
-
const i = await this.getPackageId(), a = new B();
|
|
845
|
-
a.moveCall({
|
|
846
|
-
// Calculates the amount of native Sui that the recipient will receive
|
|
847
|
-
// for swapping the `to_native_amount` of tokens.
|
|
848
|
-
target: `${i}::redeem::calculate_native_swap_amount_out`,
|
|
849
|
-
arguments: [
|
|
850
|
-
a.object(this.tokenBridgeRelayerObjectId),
|
|
851
|
-
a.pure.u64(t),
|
|
852
|
-
a.pure.u8(o.decimals)
|
|
853
|
-
],
|
|
854
|
-
typeArguments: [r]
|
|
855
|
-
});
|
|
856
|
-
const c = await this.connection.devInspectTransactionBlock({
|
|
857
|
-
transactionBlock: a,
|
|
858
|
-
sender: T.encode(new Uint8Array(32))
|
|
859
|
-
});
|
|
860
|
-
if (!c.results || c.results.length == 0 || !((u = c.results[0]) != null && u.returnValues) || ((d = c.results[0]) == null ? void 0 : d.returnValues.length) !== 1)
|
|
861
|
-
throw Error("swap rate not set");
|
|
862
|
-
return X.decode(new Uint8Array(c.results[0].returnValues[0][0].toReversed()));
|
|
863
|
-
}
|
|
864
|
-
async getRegisteredTokens() {
|
|
865
|
-
const t = (await this.getFields()).registered_tokens.fields.id.id;
|
|
866
|
-
return (await this.connection.getDynamicFields({
|
|
867
|
-
parentId: t
|
|
868
|
-
})).data.map((o) => {
|
|
869
|
-
const { address: i, module: a, name: c } = Se(o.objectType);
|
|
870
|
-
return new m([i, a, c].join(P));
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
async isRegisteredToken(e) {
|
|
874
|
-
const t = new m(v(e) ? I.nativeTokenId(this.network, this.chain).address : e).unwrap();
|
|
875
|
-
try {
|
|
876
|
-
return await this.getTokenInfo(t) !== null;
|
|
877
|
-
} catch (n) {
|
|
878
|
-
console.error(n);
|
|
879
|
-
}
|
|
880
|
-
return !1;
|
|
881
|
-
}
|
|
882
|
-
async getTokenInfo(e) {
|
|
883
|
-
var c;
|
|
884
|
-
const t = await this.getFields(), r = new m(t.registered_tokens.type).getPackageId(), o = t.registered_tokens.fields.id.id, i = new m(e), a = le(z, i.unwrap()) ? z : i.getCoinType();
|
|
885
|
-
try {
|
|
886
|
-
const u = await this.connection.getDynamicFieldObject({
|
|
887
|
-
parentId: o,
|
|
888
|
-
name: {
|
|
889
|
-
type: `${r}::registered_tokens::Key<${a}>`,
|
|
890
|
-
value: { dummy_field: !1 }
|
|
891
|
-
}
|
|
892
|
-
});
|
|
893
|
-
if (u.error)
|
|
894
|
-
throw new Error("Failed to get token info: " + JSON.stringify(u.error));
|
|
895
|
-
if (!u.data || !u.data.content)
|
|
896
|
-
throw new Error("Failed to get token info: " + JSON.stringify(u));
|
|
897
|
-
const { content: d } = u.data;
|
|
898
|
-
return b(d) && b(d.fields.value) ? d.fields.value.fields : null;
|
|
899
|
-
} catch (u) {
|
|
900
|
-
if ((u == null ? void 0 : u.code) === -32e3 && ((c = u.message) != null && c.includes("RPC Error")))
|
|
901
|
-
return console.error(u), null;
|
|
902
|
-
throw u;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
async getFields() {
|
|
906
|
-
if (!this.fields) {
|
|
907
|
-
const e = await M(this.connection, this.tokenBridgeRelayerObjectId);
|
|
908
|
-
if (e === null)
|
|
909
|
-
throw new Error("Failed to get fields from token bridge relayer state");
|
|
910
|
-
this.fields = e;
|
|
911
|
-
}
|
|
912
|
-
return this.fields;
|
|
913
|
-
}
|
|
914
|
-
async getPackageId() {
|
|
915
|
-
const e = await this.getFields();
|
|
916
|
-
return new m(e.registered_tokens.type).getPackageId();
|
|
917
|
-
}
|
|
918
|
-
async getPackageIds() {
|
|
919
|
-
const [e, t] = await Promise.all([
|
|
920
|
-
V(this.connection, this.coreBridgeObjectId),
|
|
921
|
-
V(this.connection, this.tokenBridgeObjectId)
|
|
922
|
-
]);
|
|
923
|
-
return { coreBridge: e, tokenBridge: t };
|
|
924
|
-
}
|
|
925
|
-
createUnsignedTx(e, t, n = !1) {
|
|
926
|
-
return new de(e, this.network, this.chain, t, n);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
se("Sui", "TokenBridge", G);
|
|
930
|
-
se("Sui", "AutomaticTokenBridge", H);
|
|
931
|
-
export {
|
|
932
|
-
H as SuiAutomaticTokenBridge,
|
|
933
|
-
G as SuiTokenBridge,
|
|
934
|
-
D as getTokenCoinType,
|
|
935
|
-
re as getTokenFromTokenRegistry
|
|
936
|
-
};
|