@wormhole-foundation/sdk-aptos-tokenbridge 0.5.0-alpha.2 → 0.5.0-alpha.4
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/cjs/foreignAddress.d.ts +39 -0
- package/dist/cjs/foreignAddress.d.ts.map +1 -0
- package/dist/cjs/foreignAddress.js +21 -0
- package/dist/cjs/foreignAddress.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/tokenBridge.d.ts +42 -0
- package/dist/cjs/tokenBridge.d.ts.map +1 -0
- package/dist/cjs/tokenBridge.js +217 -0
- package/dist/cjs/tokenBridge.js.map +1 -0
- package/dist/cjs/types.d.ts +81 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/foreignAddress.d.ts +2 -2
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +17 -8
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { layout } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
declare const foreignAddressSeedLayout: readonly [{
|
|
3
|
+
readonly binary: "bytes";
|
|
4
|
+
readonly size: 32;
|
|
5
|
+
readonly custom: {
|
|
6
|
+
to: (val: Uint8Array) => import("@wormhole-foundation/sdk-connect").UniversalAddress;
|
|
7
|
+
from: (val: import("@wormhole-foundation/sdk-connect").UniversalAddress) => Uint8Array;
|
|
8
|
+
};
|
|
9
|
+
readonly name: "tokenBridgeAddress";
|
|
10
|
+
}, {
|
|
11
|
+
readonly custom: {
|
|
12
|
+
to: (val: number) => "Solana" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Algorand" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Btc" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Dymension" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky";
|
|
13
|
+
from: (val: "Solana" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Algorand" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Near" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Sui" | "Aptos" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Btc" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Dymension" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky") => number;
|
|
14
|
+
};
|
|
15
|
+
readonly binary: "uint";
|
|
16
|
+
readonly size: 2;
|
|
17
|
+
readonly name: "chain";
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "domainSeparator";
|
|
20
|
+
readonly binary: "bytes";
|
|
21
|
+
readonly custom: Uint8Array;
|
|
22
|
+
readonly omit: true;
|
|
23
|
+
}, {
|
|
24
|
+
readonly binary: "bytes";
|
|
25
|
+
readonly size: 32;
|
|
26
|
+
readonly custom: {
|
|
27
|
+
to: (val: Uint8Array) => import("@wormhole-foundation/sdk-connect").UniversalAddress;
|
|
28
|
+
from: (val: import("@wormhole-foundation/sdk-connect").UniversalAddress) => Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
readonly name: "tokenId";
|
|
31
|
+
}, {
|
|
32
|
+
readonly name: "domainSeparator";
|
|
33
|
+
readonly binary: "bytes";
|
|
34
|
+
readonly custom: Uint8Array;
|
|
35
|
+
readonly omit: true;
|
|
36
|
+
}];
|
|
37
|
+
export declare const serializeForeignAddressSeeds: (data: layout.LayoutToType<typeof foreignAddressSeedLayout>) => Uint8Array;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=foreignAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreignAddress.d.ts","sourceRoot":"","sources":["../../src/foreignAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAe,MAAM,kCAAkC,CAAC;AAGjF,QAAA,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYI,CAAC;AAEnC,eAAO,MAAM,4BAA4B,SACjC,OAAO,YAAY,CAAC,+BAA+B,CAAC,KACzD,UAAoE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeForeignAddressSeeds = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const sdk_aptos_1 = require("@wormhole-foundation/sdk-aptos");
|
|
6
|
+
const foreignAddressSeedLayout = [
|
|
7
|
+
{ name: "tokenBridgeAddress", ...sdk_connect_1.layoutItems.universalAddressItem },
|
|
8
|
+
{ name: "chain", ...sdk_connect_1.layoutItems.chainItem() },
|
|
9
|
+
{
|
|
10
|
+
name: "domainSeparator",
|
|
11
|
+
binary: "bytes",
|
|
12
|
+
custom: sdk_connect_1.encoding.bytes.encode(sdk_aptos_1.APTOS_SEPARATOR),
|
|
13
|
+
omit: true,
|
|
14
|
+
},
|
|
15
|
+
{ name: "tokenId", ...sdk_connect_1.layoutItems.universalAddressItem },
|
|
16
|
+
// from https://github.com/aptos-labs/aptos-core/blob/25696fd266498d81d346fe86e01c330705a71465/aptos-move/framework/aptos-framework/sources/account.move#L90-L95
|
|
17
|
+
{ name: "domainSeparator", binary: "bytes", custom: new Uint8Array([0xff]), omit: true },
|
|
18
|
+
];
|
|
19
|
+
const serializeForeignAddressSeeds = (data) => sdk_connect_1.layout.serializeLayout(foreignAddressSeedLayout, data);
|
|
20
|
+
exports.serializeForeignAddressSeeds = serializeForeignAddressSeeds;
|
|
21
|
+
//# sourceMappingURL=foreignAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foreignAddress.js","sourceRoot":"","sources":["../../src/foreignAddress.ts"],"names":[],"mappings":";;;AAAA,kEAAiF;AACjF,8DAAiE;AAEjE,MAAM,wBAAwB,GAAG;IAC/B,EAAE,IAAI,EAAE,oBAAoB,EAAE,GAAG,yBAAW,CAAC,oBAAoB,EAAE;IACnE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,yBAAW,CAAC,SAAS,EAAE,EAAE;IAC7C;QACE,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,OAAO;QACf,MAAM,EAAE,sBAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,2BAAe,CAAC;QAC9C,IAAI,EAAE,IAAI;KACX;IACD,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,yBAAW,CAAC,oBAAoB,EAAE;IACxD,gKAAgK;IAChK,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE;CACxD,CAAC;AAE5B,MAAM,4BAA4B,GAAG,CAC1C,IAA0D,EAC9C,EAAE,CAAC,oBAAM,CAAC,eAAe,CAAC,wBAAwB,EAAE,IAAI,CAAC,CAAC;AAF3D,QAAA,4BAA4B,gCAE+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
18
|
+
const tokenBridge_js_1 = require("./tokenBridge.js");
|
|
19
|
+
(0, sdk_connect_1.registerProtocol)("Aptos", "TokenBridge", tokenBridge_js_1.AptosTokenBridge);
|
|
20
|
+
__exportStar(require("./tokenBridge.js"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAoE;AACpE,qDAAoD;AAEpD,IAAA,8BAAgB,EAAC,OAAO,EAAE,aAAa,EAAE,iCAAgB,CAAC,CAAC;AAE3D,mDAAiC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ChainAddress, ChainId, ChainsConfig, Contracts, Network, TokenBridge, TokenId } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import type { AnyAptosAddress, AptosChains, AptosPlatformType } from "@wormhole-foundation/sdk-aptos";
|
|
3
|
+
import { AptosUnsignedTransaction } from "@wormhole-foundation/sdk-aptos";
|
|
4
|
+
import type { AptosClient } from "aptos";
|
|
5
|
+
export declare class AptosTokenBridge<N extends Network, C extends AptosChains> implements TokenBridge<N, C> {
|
|
6
|
+
readonly network: N;
|
|
7
|
+
readonly chain: C;
|
|
8
|
+
readonly connection: AptosClient;
|
|
9
|
+
readonly contracts: Contracts;
|
|
10
|
+
readonly chainId: ChainId;
|
|
11
|
+
readonly tokenBridgeAddress: string;
|
|
12
|
+
readonly coreAddress: string;
|
|
13
|
+
private constructor();
|
|
14
|
+
static fromRpc<N extends Network>(connection: AptosClient, config: ChainsConfig<N, AptosPlatformType>): Promise<AptosTokenBridge<N, AptosChains>>;
|
|
15
|
+
isWrappedAsset(token: AnyAptosAddress): Promise<boolean>;
|
|
16
|
+
getOriginalAsset(token: AnyAptosAddress): Promise<TokenId>;
|
|
17
|
+
hasWrappedAsset(token: TokenId): Promise<boolean>;
|
|
18
|
+
getWrappedAsset(token: TokenId): Promise<import("@wormhole-foundation/sdk-connect").ChainToPlatform<C> extends infer T ? T extends import("@wormhole-foundation/sdk-connect").ChainToPlatform<C> ? T extends "Aptos" ? import("@wormhole-foundation/sdk-connect").WormholeRegistry.PlatformToNativeAddressMapping[T] : never : never : never>;
|
|
19
|
+
isTransferCompleted(vaa: TokenBridge.TransferVAA): Promise<boolean>;
|
|
20
|
+
getWrappedNative(): Promise<import("@wormhole-foundation/sdk-connect").ChainToPlatform<C> extends infer T ? T extends import("@wormhole-foundation/sdk-connect").ChainToPlatform<C> ? T extends "Aptos" ? import("@wormhole-foundation/sdk-connect").WormholeRegistry.PlatformToNativeAddressMapping[T] : never : never : never>;
|
|
21
|
+
createAttestation(token: AnyAptosAddress, payer?: AnyAptosAddress): AsyncGenerator<AptosUnsignedTransaction<N, C>>;
|
|
22
|
+
submitAttestation(vaa: TokenBridge.AttestVAA, payer?: AnyAptosAddress): AsyncGenerator<AptosUnsignedTransaction<N, C>>;
|
|
23
|
+
transfer(sender: AnyAptosAddress, recipient: ChainAddress, token: AnyAptosAddress, amount: bigint, payload?: Uint8Array): AsyncGenerator<AptosUnsignedTransaction<N, C>>;
|
|
24
|
+
redeem(sender: AnyAptosAddress, vaa: TokenBridge.TransferVAA, unwrapNative?: boolean): AsyncGenerator<AptosUnsignedTransaction<N, C>>;
|
|
25
|
+
getAssetFullyQualifiedType(tokenId: TokenId): Promise<string | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Given a hash, returns the fully qualified type by querying the corresponding TypeInfo.
|
|
28
|
+
* @param address Hash of fully qualified type
|
|
29
|
+
* @returns The fully qualified type associated with the given hash
|
|
30
|
+
*/
|
|
31
|
+
getTypeFromExternalAddress(address: string): Promise<string | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Derive the module address for an asset defined by the given origin chain and address.
|
|
34
|
+
* @param tokenBridgeAddress Address of token bridge (32 bytes)
|
|
35
|
+
* @param originChain Chain ID of chain that original asset is from
|
|
36
|
+
* @param originAddress Native address of asset
|
|
37
|
+
* @returns The module address for the given asset
|
|
38
|
+
*/
|
|
39
|
+
static getForeignAssetAddress(chain: AptosChains, tokenBridgeAddress: string, tokenId: TokenId): string;
|
|
40
|
+
private createUnsignedTx;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=tokenBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenBridge.d.ts","sourceRoot":"","sources":["../../src/tokenBridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,SAAS,EACT,OAAO,EACP,WAAW,EACX,OAAO,EACR,MAAM,kCAAkC,CAAC;AAY1C,OAAO,KAAK,EACV,e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C;IAe1C,iBAAiB,CACtB,GAAG,EAAE,WAAW,CAAC,SAAS,EAC1B,KAAK,CAAC,EAAE,eAAe,GACtB,cAAc,CAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAuB1C,QAAQ,CACb,MAAM,EAAE,eAAe,EACvB,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,GACnB,cAAc,CAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IA6B1C,MAAM,CACX,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,WAAW,CAAC,WAAW,EAC5B,YAAY,GAAE,OAAc,GAC3B,cAAc,CAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAkB3C,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAmB1E;;;;OAIG;IACG,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA8BzE;;;;;;OAMG;IACH,MAAM,CAAC,sBAAsB,CAC3B,KAAK,EAAE,WAAW,EAClB,kBAAkB,EAAE,MAAM,EAC1B,OAAO,EAAE,OAAO,GACf,MAAM;IAWT,OAAO,CAAC,gBAAgB;CAazB"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosTokenBridge = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const sdk_aptos_1 = require("@wormhole-foundation/sdk-aptos");
|
|
6
|
+
const foreignAddress_js_1 = require("./foreignAddress.js");
|
|
7
|
+
class AptosTokenBridge {
|
|
8
|
+
network;
|
|
9
|
+
chain;
|
|
10
|
+
connection;
|
|
11
|
+
contracts;
|
|
12
|
+
chainId;
|
|
13
|
+
tokenBridgeAddress;
|
|
14
|
+
coreAddress;
|
|
15
|
+
constructor(network, chain, connection, contracts) {
|
|
16
|
+
this.network = network;
|
|
17
|
+
this.chain = chain;
|
|
18
|
+
this.connection = connection;
|
|
19
|
+
this.contracts = contracts;
|
|
20
|
+
this.chainId = (0, sdk_connect_1.toChainId)(chain);
|
|
21
|
+
const tokenBridgeAddress = contracts.tokenBridge;
|
|
22
|
+
if (!tokenBridgeAddress)
|
|
23
|
+
throw new Error(`TokenBridge contract Address for chain ${chain} not found`);
|
|
24
|
+
this.tokenBridgeAddress = tokenBridgeAddress;
|
|
25
|
+
const coreBridgeAddress = contracts.coreBridge;
|
|
26
|
+
if (!coreBridgeAddress)
|
|
27
|
+
throw new Error(`CoreBridge contract Address for chain ${chain} not found`);
|
|
28
|
+
this.coreAddress = coreBridgeAddress;
|
|
29
|
+
}
|
|
30
|
+
static async fromRpc(connection, config) {
|
|
31
|
+
const [network, chain] = await sdk_aptos_1.AptosPlatform.chainFromRpc(connection);
|
|
32
|
+
const conf = config[chain];
|
|
33
|
+
if (conf.network !== network)
|
|
34
|
+
throw new Error("Network mismatch " + conf.network + " !== " + network);
|
|
35
|
+
return new AptosTokenBridge(network, chain, connection, conf.contracts);
|
|
36
|
+
}
|
|
37
|
+
async isWrappedAsset(token) {
|
|
38
|
+
try {
|
|
39
|
+
await this.getOriginalAsset(token);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch (_) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async getOriginalAsset(token) {
|
|
47
|
+
const fqt = token.toString().split(sdk_aptos_1.APTOS_SEPARATOR);
|
|
48
|
+
let originInfo;
|
|
49
|
+
originInfo = (await this.connection.getAccountResource(fqt[0], `${this.tokenBridgeAddress}::state::OriginInfo`)).data;
|
|
50
|
+
if (!originInfo)
|
|
51
|
+
throw sdk_connect_1.ErrNotWrapped;
|
|
52
|
+
// wrapped asset
|
|
53
|
+
const chain = (0, sdk_connect_1.toChain)(parseInt(originInfo.token_chain.number));
|
|
54
|
+
const address = new sdk_connect_1.UniversalAddress(originInfo.token_address.external_address);
|
|
55
|
+
return { chain, address };
|
|
56
|
+
}
|
|
57
|
+
async hasWrappedAsset(token) {
|
|
58
|
+
try {
|
|
59
|
+
await this.getWrappedAsset(token);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (_) { }
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
async getWrappedAsset(token) {
|
|
66
|
+
const assetFullyQualifiedType = await this.getAssetFullyQualifiedType(token);
|
|
67
|
+
if (!assetFullyQualifiedType)
|
|
68
|
+
throw new Error("Invalid asset address.");
|
|
69
|
+
// check to see if we can get origin info from asset address
|
|
70
|
+
await this.connection.getAccountResource((0, sdk_aptos_1.coalesceModuleAddress)(assetFullyQualifiedType), `${this.tokenBridgeAddress}::state::OriginInfo`);
|
|
71
|
+
// if successful, we can just return the computed address
|
|
72
|
+
return (0, sdk_connect_1.toNative)(this.chain, assetFullyQualifiedType);
|
|
73
|
+
}
|
|
74
|
+
async isTransferCompleted(vaa) {
|
|
75
|
+
const state = (await this.connection.getAccountResource(this.tokenBridgeAddress, `${this.tokenBridgeAddress}::state::State`)).data;
|
|
76
|
+
const handle = state.consumed_vaas.elems.handle;
|
|
77
|
+
// check if vaa hash is in consumed_vaas
|
|
78
|
+
try {
|
|
79
|
+
// when accessing Set<T>, key is type T and value is 0
|
|
80
|
+
await this.connection.getTableItem(handle, {
|
|
81
|
+
key_type: "vector<u8>",
|
|
82
|
+
value_type: "u8",
|
|
83
|
+
key: vaa.hash,
|
|
84
|
+
});
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async getWrappedNative() {
|
|
92
|
+
return (0, sdk_connect_1.toNative)(this.chain, sdk_aptos_1.APTOS_COIN);
|
|
93
|
+
}
|
|
94
|
+
async *createAttestation(token, payer) {
|
|
95
|
+
const tokenId = { chain: this.chain, address: new sdk_aptos_1.AptosAddress(token) };
|
|
96
|
+
const assetType = await this.getAssetFullyQualifiedType(tokenId);
|
|
97
|
+
if (!assetType)
|
|
98
|
+
throw new Error("Invalid asset address.");
|
|
99
|
+
yield this.createUnsignedTx({
|
|
100
|
+
function: `${this.tokenBridgeAddress}::attest_token::attest_token_entry`,
|
|
101
|
+
type_arguments: [assetType],
|
|
102
|
+
arguments: [],
|
|
103
|
+
}, "Aptos.AttestToken");
|
|
104
|
+
}
|
|
105
|
+
async *submitAttestation(vaa, payer) {
|
|
106
|
+
yield this.createUnsignedTx({
|
|
107
|
+
function: `${this.tokenBridgeAddress}::wrapped::create_wrapped_coin_type`,
|
|
108
|
+
type_arguments: [],
|
|
109
|
+
arguments: [(0, sdk_connect_1.serialize)(vaa)],
|
|
110
|
+
}, "Aptos.CreateWrappedCoinType");
|
|
111
|
+
const assetType = await this.getAssetFullyQualifiedType(vaa.payload.token);
|
|
112
|
+
if (!assetType)
|
|
113
|
+
throw new Error("Invalid asset address.");
|
|
114
|
+
yield this.createUnsignedTx({
|
|
115
|
+
function: `${this.tokenBridgeAddress}::wrapped::create_wrapped_coin`,
|
|
116
|
+
type_arguments: [assetType],
|
|
117
|
+
arguments: [(0, sdk_connect_1.serialize)(vaa)],
|
|
118
|
+
}, "Aptos.CreateWrappedCoin");
|
|
119
|
+
}
|
|
120
|
+
async *transfer(sender, recipient, token, amount, payload) {
|
|
121
|
+
// TODO
|
|
122
|
+
const fee = 0n;
|
|
123
|
+
const nonce = 0n;
|
|
124
|
+
const fullyQualifiedType = (0, sdk_connect_1.isNative)(token) ? sdk_aptos_1.APTOS_COIN : token.toString();
|
|
125
|
+
const dstAddress = recipient.address.toUniversalAddress().toUint8Array();
|
|
126
|
+
const dstChain = (0, sdk_connect_1.toChainId)(recipient.chain);
|
|
127
|
+
if (payload) {
|
|
128
|
+
yield this.createUnsignedTx({
|
|
129
|
+
function: `${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_with_payload_entry`,
|
|
130
|
+
type_arguments: [fullyQualifiedType],
|
|
131
|
+
arguments: [amount, dstChain, dstAddress, nonce, payload],
|
|
132
|
+
}, "Aptos.TransferTokensWithPayload");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
yield this.createUnsignedTx({
|
|
136
|
+
function: `${this.tokenBridgeAddress}::transfer_tokens::transfer_tokens_entry`,
|
|
137
|
+
type_arguments: [fullyQualifiedType],
|
|
138
|
+
arguments: [amount, dstChain, dstAddress, fee, nonce],
|
|
139
|
+
}, "Aptos.TransferTokens");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async *redeem(sender, vaa, unwrapNative = true) {
|
|
143
|
+
const assetType = vaa.payload.token.chain === this.chain
|
|
144
|
+
? await this.getTypeFromExternalAddress(vaa.payload.token.address.toString())
|
|
145
|
+
: await this.getAssetFullyQualifiedType(vaa.payload.token);
|
|
146
|
+
if (!assetType)
|
|
147
|
+
throw new Error("Invalid asset address.");
|
|
148
|
+
yield this.createUnsignedTx({
|
|
149
|
+
function: `${this.tokenBridgeAddress}::complete_transfer::submit_vaa_and_register_entry`,
|
|
150
|
+
type_arguments: [assetType],
|
|
151
|
+
arguments: [(0, sdk_connect_1.serialize)(vaa)],
|
|
152
|
+
}, "Aptos.CompleteTransfer");
|
|
153
|
+
}
|
|
154
|
+
async getAssetFullyQualifiedType(tokenId) {
|
|
155
|
+
// native asset
|
|
156
|
+
if (tokenId.chain === this.chain) {
|
|
157
|
+
// originAddress should be of form address::module::type
|
|
158
|
+
if (!(0, sdk_aptos_1.isValidAptosType)(tokenId.address.toString())) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
return tokenId.address.toString();
|
|
162
|
+
}
|
|
163
|
+
// non-native asset, derive unique address
|
|
164
|
+
const wrappedAssetAddress = AptosTokenBridge.getForeignAssetAddress(this.chain, this.tokenBridgeAddress, tokenId);
|
|
165
|
+
return `${wrappedAssetAddress}::coin::T`;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Given a hash, returns the fully qualified type by querying the corresponding TypeInfo.
|
|
169
|
+
* @param address Hash of fully qualified type
|
|
170
|
+
* @returns The fully qualified type associated with the given hash
|
|
171
|
+
*/
|
|
172
|
+
async getTypeFromExternalAddress(address) {
|
|
173
|
+
try {
|
|
174
|
+
// get handle
|
|
175
|
+
const state = (await this.connection.getAccountResource(this.tokenBridgeAddress, `${this.tokenBridgeAddress}::state::State`)).data;
|
|
176
|
+
const { handle } = state.native_infos;
|
|
177
|
+
// get type info
|
|
178
|
+
const typeInfo = await this.connection.getTableItem(handle, {
|
|
179
|
+
key_type: `${this.tokenBridgeAddress}::token_hash::TokenHash`,
|
|
180
|
+
value_type: "0x1::type_info::TypeInfo",
|
|
181
|
+
key: { hash: address },
|
|
182
|
+
});
|
|
183
|
+
return typeInfo
|
|
184
|
+
? [
|
|
185
|
+
typeInfo.account_address,
|
|
186
|
+
sdk_connect_1.encoding.hex.decode(typeInfo.module_name),
|
|
187
|
+
sdk_connect_1.encoding.hex.decode(typeInfo.struct_name),
|
|
188
|
+
].join(sdk_aptos_1.APTOS_SEPARATOR)
|
|
189
|
+
: null;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Derive the module address for an asset defined by the given origin chain and address.
|
|
197
|
+
* @param tokenBridgeAddress Address of token bridge (32 bytes)
|
|
198
|
+
* @param originChain Chain ID of chain that original asset is from
|
|
199
|
+
* @param originAddress Native address of asset
|
|
200
|
+
* @returns The module address for the given asset
|
|
201
|
+
*/
|
|
202
|
+
static getForeignAssetAddress(chain, tokenBridgeAddress, tokenId) {
|
|
203
|
+
if ((0, sdk_connect_1.isNative)(tokenId.address))
|
|
204
|
+
throw new Error("Invalid token address");
|
|
205
|
+
const data = (0, foreignAddress_js_1.serializeForeignAddressSeeds)({
|
|
206
|
+
chain: tokenId.chain,
|
|
207
|
+
tokenBridgeAddress: new sdk_aptos_1.AptosAddress(tokenBridgeAddress).toUniversalAddress(),
|
|
208
|
+
tokenId: tokenId.address.toUniversalAddress(),
|
|
209
|
+
});
|
|
210
|
+
return sdk_connect_1.encoding.hex.encode((0, sdk_connect_1.sha3_256)(data), true);
|
|
211
|
+
}
|
|
212
|
+
createUnsignedTx(txReq, description, parallelizable = false) {
|
|
213
|
+
return new sdk_aptos_1.AptosUnsignedTransaction(txReq, this.network, this.chain, description, parallelizable);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.AptosTokenBridge = AptosTokenBridge;
|
|
217
|
+
//# sourceMappingURL=tokenBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenBridge.js","sourceRoot":"","sources":["../../src/tokenBridge.ts"],"names":[],"mappings":";;;AASA,kEAU0C;AAM1C,8DAQwC;AAExC,2DAAmE;AAGnE,MAAa,gBAAgB;IAShB;IACA;IACA;IACA;IATF,OAAO,CAAU;IAEjB,kBAAkB,CAAS;IAC3B,WAAW,CAAS;IAE7B,YACW,OAAU,EACV,KAAQ,EACR,UAAuB,EACvB,SAAoB;QAHpB,YAAO,GAAP,OAAO,CAAG;QACV,UAAK,GAAL,KAAK,CAAG;QACR,eAAU,GAAV,UAAU,CAAa;QACvB,cAAS,GAAT,SAAS,CAAW;QAE7B,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAS,EAAC,KAAK,CAAC,CAAC;QAEhC,MAAM,kBAAkB,GAAG,SAAS,CAAC,WAAW,CAAC;QACjD,IAAI,CAAC,kBAAkB;YACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,YAAY,CAAC,CAAC;QAC/E,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAE7C,MAAM,iBAAiB,GAAG,SAAS,CAAC,UAAU,CAAC;QAC/C,IAAI,CAAC,iBAAiB;YACp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O,EAAE,OAAO,CAAC,OAAO,CAAC,kBAAkB,EAAE;SAC9C,CAAC,CAAC;QACH,OAAO,sBAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAA,sBAAQ,EAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAEO,gBAAgB,CACtB,KAAiC,EACjC,WAAmB,EACnB,iBAA0B,KAAK;QAE/B,OAAO,IAAI,oCAAwB,CACjC,KAAK,EACL,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,KAAK,EACV,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC;CACF;AArTD,4CAqTC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { TokenTypes } from "aptos";
|
|
2
|
+
export type TokenBridgeState = {
|
|
3
|
+
consumed_vaas: {
|
|
4
|
+
elems: {
|
|
5
|
+
handle: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
emitter_cap: {
|
|
9
|
+
emitter: string;
|
|
10
|
+
sequence: string;
|
|
11
|
+
};
|
|
12
|
+
governance_chain_id: {
|
|
13
|
+
number: string;
|
|
14
|
+
};
|
|
15
|
+
governance_contract: {
|
|
16
|
+
external_address: string;
|
|
17
|
+
};
|
|
18
|
+
native_infos: {
|
|
19
|
+
handle: string;
|
|
20
|
+
};
|
|
21
|
+
registered_emitters: {
|
|
22
|
+
handle: string;
|
|
23
|
+
};
|
|
24
|
+
signer_cap: {
|
|
25
|
+
account: string;
|
|
26
|
+
};
|
|
27
|
+
wrapped_infos: {
|
|
28
|
+
handle: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type OriginInfo = {
|
|
32
|
+
token_address: {
|
|
33
|
+
external_address: string;
|
|
34
|
+
};
|
|
35
|
+
token_chain: {
|
|
36
|
+
number: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export type CreateTokenDataEvent = {
|
|
40
|
+
version: string;
|
|
41
|
+
guid: {
|
|
42
|
+
creation_number: string;
|
|
43
|
+
account_address: string;
|
|
44
|
+
};
|
|
45
|
+
sequence_number: string;
|
|
46
|
+
type: "0x3::token::CreateTokenDataEvent";
|
|
47
|
+
data: {
|
|
48
|
+
description: string;
|
|
49
|
+
id: TokenTypes.TokenDataId;
|
|
50
|
+
maximum: string;
|
|
51
|
+
mutability_config: {
|
|
52
|
+
description: boolean;
|
|
53
|
+
maximum: boolean;
|
|
54
|
+
properties: boolean;
|
|
55
|
+
royalty: boolean;
|
|
56
|
+
uri: boolean;
|
|
57
|
+
};
|
|
58
|
+
name: string;
|
|
59
|
+
property_keys: [string];
|
|
60
|
+
property_types: [string];
|
|
61
|
+
property_values: [string];
|
|
62
|
+
royalty_payee_address: string;
|
|
63
|
+
royalty_points_denominator: string;
|
|
64
|
+
royalty_points_numerator: string;
|
|
65
|
+
uri: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type DepositEvent = {
|
|
69
|
+
version: string;
|
|
70
|
+
guid: {
|
|
71
|
+
creation_number: string;
|
|
72
|
+
account_address: string;
|
|
73
|
+
};
|
|
74
|
+
sequence_number: string;
|
|
75
|
+
type: "0x3::token::DepositEvent";
|
|
76
|
+
data: {
|
|
77
|
+
amount: string;
|
|
78
|
+
id: TokenTypes.TokenId;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAExC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa,EAAE;QACb,KAAK,EAAE;YACL,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,CAAC;IACF,WAAW,EAAE;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,mBAAmB,EA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BAA0B,EAAE,MAAM,CAAC;QACnC,wBAAwB,EAAE,MAAM,CAAC;QACjC,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QACJ,eAAe,EAAE,MAAM,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,0BAA0B,CAAC;IACjC,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC;KACxB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -9,8 +9,8 @@ declare const foreignAddressSeedLayout: readonly [{
|
|
|
9
9
|
readonly name: "tokenBridgeAddress";
|
|
10
10
|
}, {
|
|
11
11
|
readonly custom: {
|
|
12
|
-
to: (val: number) => "Solana" | "
|
|
13
|
-
from: (val: "Solana" | "
|
|
12
|
+
to: (val: number) => "Solana" | "Algorand" | "Near" | "Sui" | "Aptos" | "Btc" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Dymension" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky";
|
|
13
|
+
from: (val: "Solana" | "Algorand" | "Near" | "Sui" | "Aptos" | "Btc" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Dymension" | "Sepolia" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky") => number;
|
|
14
14
|
};
|
|
15
15
|
readonly binary: "uint";
|
|
16
16
|
readonly size: 2;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { registerProtocol } from "@wormhole-foundation/sdk-connect";
|
|
2
2
|
import { AptosTokenBridge } from "./tokenBridge.js";
|
|
3
3
|
registerProtocol("Aptos", "TokenBridge", AptosTokenBridge);
|
|
4
|
-
export
|
|
4
|
+
export * from "./tokenBridge.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAE3D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC;AAE3D,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wormhole-foundation/sdk-aptos-tokenbridge",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"types": "./dist/esm/index.d.ts",
|
|
19
19
|
"description": "SDK for Solana, used in conjunction with @wormhole-foundation/sdk",
|
|
20
20
|
"files": [
|
|
21
|
-
"dist/esm"
|
|
21
|
+
"dist/esm",
|
|
22
|
+
"dist/cjs"
|
|
22
23
|
],
|
|
23
24
|
"keywords": [
|
|
24
25
|
"wormhole",
|
|
@@ -33,19 +34,27 @@
|
|
|
33
34
|
"sideEffects": true,
|
|
34
35
|
"scripts": {
|
|
35
36
|
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
|
36
|
-
"build": "
|
|
37
|
+
"build": "npm run build:esm && npm run build:cjs",
|
|
37
38
|
"rebuild": "npm run clean && npm run build",
|
|
38
39
|
"clean": "rm -rf ./dist && rm -rf ./.turbo",
|
|
39
40
|
"lint": "npm run prettier && eslint --fix ./src --ext .ts",
|
|
40
|
-
"prettier": "prettier --write ./src"
|
|
41
|
+
"prettier": "prettier --write ./src",
|
|
42
|
+
"build:esm": "tsc -p ./tsconfig.esm.json"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"nock": "^13.3.3"
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
|
-
"@wormhole-foundation/sdk-connect": "0.5.0-alpha.
|
|
47
|
-
"@wormhole-foundation/sdk-aptos": "0.5.0-alpha.
|
|
48
|
-
"@wormhole-foundation/sdk-aptos-core": "0.5.0-alpha.
|
|
48
|
+
"@wormhole-foundation/sdk-connect": "0.5.0-alpha.4",
|
|
49
|
+
"@wormhole-foundation/sdk-aptos": "0.5.0-alpha.4",
|
|
50
|
+
"@wormhole-foundation/sdk-aptos-core": "0.5.0-alpha.4"
|
|
49
51
|
},
|
|
50
|
-
"type": "module"
|
|
52
|
+
"type": "module",
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"import": "./dist/esm/index.js",
|
|
56
|
+
"types": "./dist/esm/index.d.ts",
|
|
57
|
+
"require": "./dist/cjs/index.js"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
51
60
|
}
|