@wormhole-foundation/sdk-aptos 0.5.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/address.d.ts +27 -0
- package/dist/cjs/address.d.ts.map +1 -0
- package/dist/cjs/address.js +84 -0
- package/dist/cjs/address.js.map +1 -0
- package/dist/cjs/chain.d.ts +5 -0
- package/dist/cjs/chain.d.ts.map +1 -0
- package/dist/cjs/chain.js +8 -0
- package/dist/cjs/chain.js.map +1 -0
- package/dist/cjs/constants.d.ts +3 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +6 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/platform.d.ts +26 -0
- package/dist/cjs/platform.d.ts.map +1 -0
- package/dist/cjs/platform.js +111 -0
- package/dist/cjs/platform.js.map +1 -0
- package/dist/cjs/signer.d.ts +15 -0
- package/dist/cjs/signer.d.ts.map +1 -0
- package/dist/cjs/signer.js +61 -0
- package/dist/cjs/signer.js.map +1 -0
- package/dist/cjs/types.d.ts +30 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +22 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/unsignedTransaction.d.ts +12 -0
- package/dist/cjs/unsignedTransaction.d.ts.map +1 -0
- package/dist/cjs/unsignedTransaction.js +19 -0
- package/dist/cjs/unsignedTransaction.js.map +1 -0
- package/dist/esm/address.d.ts +27 -0
- package/dist/esm/address.d.ts.map +1 -0
- package/dist/esm/address.js +79 -0
- package/dist/esm/address.js.map +1 -0
- package/dist/esm/chain.d.ts +5 -0
- package/dist/esm/chain.d.ts.map +1 -0
- package/dist/esm/chain.js +4 -0
- package/dist/esm/chain.js.map +1 -0
- package/dist/esm/constants.d.ts +3 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +3 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/platform.d.ts +26 -0
- package/dist/esm/platform.d.ts.map +1 -0
- package/dist/esm/platform.js +107 -0
- package/dist/esm/platform.js.map +1 -0
- package/dist/esm/signer.d.ts +15 -0
- package/dist/esm/signer.d.ts.map +1 -0
- package/dist/esm/signer.js +56 -0
- package/dist/esm/signer.js.map +1 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +17 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/unsignedTransaction.d.ts +12 -0
- package/dist/esm/unsignedTransaction.d.ts.map +1 -0
- package/dist/esm/unsignedTransaction.js +15 -0
- package/dist/esm/unsignedTransaction.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Address, Platform, UniversalAddress } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AnyAptosAddress } from "./types";
|
|
3
|
+
export declare const AptosZeroAddress = "0x";
|
|
4
|
+
export declare function ensureFullAptosAddress(address: string): string;
|
|
5
|
+
export declare class AptosAddress implements Address {
|
|
6
|
+
static readonly byteSize = 32;
|
|
7
|
+
readonly platform: Platform;
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly address: Uint8Array;
|
|
10
|
+
readonly module: string | undefined;
|
|
11
|
+
constructor(address: AnyAptosAddress);
|
|
12
|
+
unwrap(): string;
|
|
13
|
+
toString(): string;
|
|
14
|
+
toNative(): this;
|
|
15
|
+
toUint8Array(): Uint8Array;
|
|
16
|
+
toUniversalAddress(): UniversalAddress;
|
|
17
|
+
static instanceof(address: any): address is AptosAddress;
|
|
18
|
+
equals(other: AptosAddress | UniversalAddress): boolean;
|
|
19
|
+
}
|
|
20
|
+
declare module "@wormhole-foundation/sdk-connect" {
|
|
21
|
+
namespace WormholeRegistry {
|
|
22
|
+
interface PlatformToNativeAddressMapping {
|
|
23
|
+
Aptos: AptosAddress;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,gBAAgB,EAGjB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,EAAE,eAAe,EAA+B,MAAM,SAAS,CAAC;AAEvE,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAIrC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,UAMrD;AAED,qBAAa,YAAa,YAAW,OAAO;IAC1C,MAAM,CAAC,QAAQ,CAAC,QAAQ,MAAM;IAC9B,SAAgB,QAAQ,EAAE,QAAQ,CAA2B;IAE7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAY;IAGjC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAG7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAExB,OAAO,EAAE,eAAe;IAyBpC,MAAM,IAAI,MAAM;IAKhB,QAAQ,IAAI,MAAM;IAGlB,QAAQ;IAGR,YAAY;IAGZ,kBAAkB;IAIlB,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,YAAY;IAIxD,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,gBAAgB,GAAG,OAAO;CAOxD;AAED,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAiB,gBAAgB,CAAC;QAChC,UAAU,8BAA8B;YACtC,KAAK,EAAE,YAAY,CAAC;SACrB;KACF;CACF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosAddress = exports.ensureFullAptosAddress = exports.AptosZeroAddress = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const platform_1 = require("./platform");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
exports.AptosZeroAddress = "0x";
|
|
9
|
+
// Sometimes Aptos addresses will be trimmed of leading 0s
|
|
10
|
+
// add them back if necessary
|
|
11
|
+
function ensureFullAptosAddress(address) {
|
|
12
|
+
if (address.length % 2 !== 0 || address.length < 66) {
|
|
13
|
+
address = address.startsWith("0x") ? address.slice(2) : address;
|
|
14
|
+
return "0x" + address.padStart(64, "0");
|
|
15
|
+
}
|
|
16
|
+
return address;
|
|
17
|
+
}
|
|
18
|
+
exports.ensureFullAptosAddress = ensureFullAptosAddress;
|
|
19
|
+
class AptosAddress {
|
|
20
|
+
static byteSize = 32;
|
|
21
|
+
platform = platform_1.AptosPlatform._platform;
|
|
22
|
+
type = "Native";
|
|
23
|
+
// Full 32 bytes of Address
|
|
24
|
+
address;
|
|
25
|
+
// Optional module and contract name
|
|
26
|
+
module;
|
|
27
|
+
constructor(address) {
|
|
28
|
+
if (AptosAddress.instanceof(address)) {
|
|
29
|
+
this.address = address.address;
|
|
30
|
+
this.module = address.module;
|
|
31
|
+
}
|
|
32
|
+
else if (sdk_connect_1.UniversalAddress.instanceof(address)) {
|
|
33
|
+
this.address = address.toUint8Array();
|
|
34
|
+
}
|
|
35
|
+
else if (typeof address === "string") {
|
|
36
|
+
// If we've got an address of the form `0x1234...::module::...` then
|
|
37
|
+
// stuff anything after the first `::` into the module field
|
|
38
|
+
// and continue processing the address
|
|
39
|
+
if ((0, types_1.isValidAptosType)(address)) {
|
|
40
|
+
const chunks = address.split(constants_1.APTOS_SEPARATOR);
|
|
41
|
+
this.module = chunks.slice(1).join(constants_1.APTOS_SEPARATOR);
|
|
42
|
+
address = chunks[0];
|
|
43
|
+
}
|
|
44
|
+
address = ensureFullAptosAddress(address);
|
|
45
|
+
if (!sdk_connect_1.encoding.hex.valid(address))
|
|
46
|
+
throw new Error("Invalid Aptos address: " + address);
|
|
47
|
+
this.address = sdk_connect_1.encoding.hex.decode(address);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.address = address;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
unwrap() {
|
|
54
|
+
const addr = sdk_connect_1.encoding.hex.encode(this.address).replace(/^0+/, "");
|
|
55
|
+
const module = this.module ? constants_1.APTOS_SEPARATOR + this.module : "";
|
|
56
|
+
return `0x${addr}${module}`;
|
|
57
|
+
}
|
|
58
|
+
toString() {
|
|
59
|
+
return this.unwrap();
|
|
60
|
+
}
|
|
61
|
+
toNative() {
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
toUint8Array() {
|
|
65
|
+
return this.address;
|
|
66
|
+
}
|
|
67
|
+
toUniversalAddress() {
|
|
68
|
+
return new sdk_connect_1.UniversalAddress(this.toUint8Array());
|
|
69
|
+
}
|
|
70
|
+
static instanceof(address) {
|
|
71
|
+
return address.platform === platform_1.AptosPlatform._platform;
|
|
72
|
+
}
|
|
73
|
+
equals(other) {
|
|
74
|
+
if (AptosAddress.instanceof(other)) {
|
|
75
|
+
return other.unwrap() === this.unwrap();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return this.toUniversalAddress().equals(other);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AptosAddress = AptosAddress;
|
|
83
|
+
(0, sdk_connect_1.registerNative)(types_1._platform, AptosAddress);
|
|
84
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":";;;AAAA,kEAM0C;AAE1C,2CAA8C;AAC9C,yCAA2C;AAC3C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,UAAU,CAAC,KAAK,CAAC,EAAE;YAClC,OAAO,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;SACzC;aAAM;YACL,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChD;IACH,CAAC;;AAjEH,oCAkEC;AAUD,IAAA,4BAAc,EAAC,iBAAS,EAAE,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,UAAU,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;CAAG"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosChain = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
class AptosChain extends sdk_connect_1.ChainContext {
|
|
6
|
+
}
|
|
7
|
+
exports.AptosChain = AptosChain;
|
|
8
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/chain.ts"],"names":[],"mappings":";;;AAAA,kEAAyE;AAGzE,MAAa,UAAqD,SAAQ,0BAAkB;CAAG;AAA/F,gCAA+F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,+BAA+B,CAAC;AACvD,eAAO,MAAM,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,4BAA4B,CAAC;AAC1C,QAAA,eAAe,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
__exportStar(require("./address"), exports);
|
|
18
|
+
__exportStar(require("./platform"), exports);
|
|
19
|
+
__exportStar(require("./chain"), exports);
|
|
20
|
+
__exportStar(require("./unsignedTransaction"), exports);
|
|
21
|
+
__exportStar(require("./constants"), exports);
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
|
+
__exportStar(require("./signer"), exports);
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,6CAA2B;AAC3B,0CAAwB;AACxB,wDAAsC;AACtC,8CAA4B;AAC5B,0CAAwB;AACxB,2CAAyB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Chain, ChainsConfig, Network, PlatformContext, StaticPlatformMethods, Balances, SignedTx, TokenId, TxHash } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AptosClient } from "aptos";
|
|
3
|
+
import { AptosChain } from "./chain";
|
|
4
|
+
import { AptosChains, AptosPlatformType } from "./types";
|
|
5
|
+
import { AnyAptosAddress } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @category Aptos
|
|
8
|
+
*/
|
|
9
|
+
export declare class AptosPlatform<N extends Network> extends PlatformContext<N, AptosPlatformType> implements StaticPlatformMethods<AptosPlatformType, typeof AptosPlatform> {
|
|
10
|
+
static _platform: "Aptos";
|
|
11
|
+
constructor(network: N, config?: ChainsConfig<N, AptosPlatformType>);
|
|
12
|
+
getRpc<C extends AptosChains>(chain: C): AptosClient;
|
|
13
|
+
getChain<C extends AptosChains>(chain: C, rpc?: AptosClient): AptosChain<N, C>;
|
|
14
|
+
static nativeTokenId<N extends Network, C extends AptosChains>(network: N, chain: C): TokenId<C>;
|
|
15
|
+
static isNativeTokenId<N extends Network, C extends AptosChains>(network: N, chain: C, tokenId: TokenId): boolean;
|
|
16
|
+
static isSupportedChain(chain: Chain): boolean;
|
|
17
|
+
static getDecimals(chain: Chain, rpc: AptosClient, token: AnyAptosAddress): Promise<number>;
|
|
18
|
+
static getBalance(chain: Chain, rpc: AptosClient, walletAddress: string, token: AnyAptosAddress): Promise<bigint | null>;
|
|
19
|
+
static getBalances(chain: Chain, rpc: AptosClient, walletAddress: string, tokens: AnyAptosAddress[]): Promise<Balances>;
|
|
20
|
+
static sendWait(chain: Chain, rpc: AptosClient, stxns: SignedTx[]): Promise<TxHash[]>;
|
|
21
|
+
static getLatestBlock(rpc: AptosClient): Promise<number>;
|
|
22
|
+
static getLatestFinalizedBlock(rpc: AptosClient): Promise<number>;
|
|
23
|
+
static chainFromChainId(chainId: string | bigint): [Network, AptosChains];
|
|
24
|
+
static chainFromRpc(rpc: AptosClient): Promise<[Network, AptosChains]>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,OAAO,EACP,eAAe,EACf,qBAAqB,EAIrB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,MAAM,EAIP,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAa,MAAM,SAAS,CAAC;AAKpE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C;;GAEG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,OAAO,CAC1C,SAAQ,eAAe,CAAC,CAAC,EAAE,iBAAiB,CAC5C,YAAW,qBAAqB,CAAC,iBAAiB,EAAE,OAAO,aAAa,CAAC;IAEzE,MAAM,CAAC,SAAS,UAAa;gBAEjB,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,CAAC,CAAC,EAAE,iBAAiB,CAAC;IAInE,MAAM,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,GAAG,WAA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MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC;WAa5D,YAAY,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;CAK7E"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosPlatform = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const aptos_1 = require("aptos");
|
|
6
|
+
const chain_1 = require("./chain");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
const aptos_2 = require("aptos");
|
|
9
|
+
const address_1 = require("./address");
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* @category Aptos
|
|
13
|
+
*/
|
|
14
|
+
class AptosPlatform extends sdk_connect_1.PlatformContext {
|
|
15
|
+
static _platform = types_1._platform;
|
|
16
|
+
constructor(network, config) {
|
|
17
|
+
super(network, config ?? (0, sdk_connect_1.networkPlatformConfigs)(network, AptosPlatform._platform));
|
|
18
|
+
}
|
|
19
|
+
getRpc(chain) {
|
|
20
|
+
if (chain in this.config)
|
|
21
|
+
return new aptos_1.AptosClient(this.config[chain].rpc);
|
|
22
|
+
throw new Error("No configuration available for chain: " + chain);
|
|
23
|
+
}
|
|
24
|
+
getChain(chain, rpc) {
|
|
25
|
+
if (chain in this.config)
|
|
26
|
+
return new chain_1.AptosChain(chain, this);
|
|
27
|
+
throw new Error("No configuration available for chain: " + chain);
|
|
28
|
+
}
|
|
29
|
+
static nativeTokenId(network, chain) {
|
|
30
|
+
if (!this.isSupportedChain(chain))
|
|
31
|
+
throw new Error(`invalid chain: ${chain}`);
|
|
32
|
+
return sdk_connect_1.Wormhole.tokenId(chain, constants_1.APTOS_COIN);
|
|
33
|
+
}
|
|
34
|
+
static isNativeTokenId(network, chain, tokenId) {
|
|
35
|
+
if (!this.isSupportedChain(chain))
|
|
36
|
+
return false;
|
|
37
|
+
if (tokenId.chain !== chain)
|
|
38
|
+
return false;
|
|
39
|
+
const native = this.nativeTokenId(network, chain);
|
|
40
|
+
return native == tokenId;
|
|
41
|
+
}
|
|
42
|
+
static isSupportedChain(chain) {
|
|
43
|
+
const platform = (0, sdk_connect_1.chainToPlatform)(chain);
|
|
44
|
+
return platform === AptosPlatform._platform;
|
|
45
|
+
}
|
|
46
|
+
static async getDecimals(chain, rpc, token) {
|
|
47
|
+
if ((0, sdk_connect_1.isNative)(token))
|
|
48
|
+
return sdk_connect_1.decimals.nativeDecimals(AptosPlatform._platform);
|
|
49
|
+
const tokenAddr = token.toString();
|
|
50
|
+
const coinType = `0x1::coin::CoinInfo<${tokenAddr}>`;
|
|
51
|
+
const decimals = (await rpc.getAccountResource(tokenAddr.split(constants_1.APTOS_SEPARATOR)[0], coinType)).data.decimals;
|
|
52
|
+
return decimals;
|
|
53
|
+
}
|
|
54
|
+
static async getBalance(chain, rpc, walletAddress, token) {
|
|
55
|
+
const tokenAddress = (0, sdk_connect_1.isNative)(token) ? constants_1.APTOS_COIN : token.toString();
|
|
56
|
+
const cc = new aptos_2.CoinClient(rpc);
|
|
57
|
+
try {
|
|
58
|
+
const balance = await cc.checkBalance(walletAddress, {
|
|
59
|
+
coinType: tokenAddress,
|
|
60
|
+
});
|
|
61
|
+
return balance;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
if ((e instanceof aptos_2.Types.ApiError || e.errorCode === "resource_not_found") &&
|
|
65
|
+
e.status === 404) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
static async getBalances(chain, rpc, walletAddress, tokens) {
|
|
72
|
+
const balancesArr = await Promise.all(tokens.map(async (token) => {
|
|
73
|
+
const balance = await this.getBalance(chain, rpc, walletAddress, token);
|
|
74
|
+
const address = (0, sdk_connect_1.isNative)(token) ? "native" : new address_1.AptosAddress(token).toString();
|
|
75
|
+
return { [address]: balance };
|
|
76
|
+
}));
|
|
77
|
+
return balancesArr.reduce((obj, item) => Object.assign(obj, item), {});
|
|
78
|
+
}
|
|
79
|
+
static async sendWait(chain, rpc, stxns) {
|
|
80
|
+
// TODO: concurrent
|
|
81
|
+
const txhashes = [];
|
|
82
|
+
for (const stxn of stxns) {
|
|
83
|
+
const pendingTx = await rpc.submitTransaction(stxn);
|
|
84
|
+
const res = await rpc.waitForTransactionWithResult(pendingTx.hash);
|
|
85
|
+
txhashes.push(res.hash);
|
|
86
|
+
}
|
|
87
|
+
return txhashes;
|
|
88
|
+
}
|
|
89
|
+
static async getLatestBlock(rpc) {
|
|
90
|
+
const li = await rpc.getLedgerInfo();
|
|
91
|
+
return Number(li.block_height);
|
|
92
|
+
}
|
|
93
|
+
static async getLatestFinalizedBlock(rpc) {
|
|
94
|
+
const li = await rpc.getLedgerInfo();
|
|
95
|
+
return Number(li.block_height);
|
|
96
|
+
}
|
|
97
|
+
static chainFromChainId(chainId) {
|
|
98
|
+
const netChain = sdk_connect_1.nativeChainIds.platformNativeChainIdToNetworkChain(AptosPlatform._platform, BigInt(chainId));
|
|
99
|
+
if (!netChain)
|
|
100
|
+
throw new Error(`No matching chainId to determine network and chain: ${chainId}`);
|
|
101
|
+
const [network, chain] = netChain;
|
|
102
|
+
return [network, chain];
|
|
103
|
+
}
|
|
104
|
+
static async chainFromRpc(rpc) {
|
|
105
|
+
const conn = rpc;
|
|
106
|
+
const ci = await conn.getChainId();
|
|
107
|
+
return this.chainFromChainId(ci.toString());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.AptosPlatform = AptosPlatform;
|
|
111
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":";;;AAAA,kEAgB0C;AAC1C,iCAAoC;AACpC,mCAAqC;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Client } from "aptos";
|
|
3
|
+
import { AptosChains } from "./types";
|
|
4
|
+
export declare function getAptosSigner(rpc: RpcConnection<"Aptos">, privateKey: string): Promise<Signer>;
|
|
5
|
+
export declare class AptosSigner<N extends Network, C extends AptosChains> implements SignAndSendSigner<N, C> {
|
|
6
|
+
private _chain;
|
|
7
|
+
private _account;
|
|
8
|
+
private _rpc;
|
|
9
|
+
constructor(_chain: C, _account: AptosAccount, _rpc: AptosClient);
|
|
10
|
+
chain(): C;
|
|
11
|
+
address(): string;
|
|
12
|
+
signAndSend(tx: UnsignedTransaction[]): Promise<TxHash[]>;
|
|
13
|
+
private _simSignSend;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,mBAAmB,EAEpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,WAAW,EAA0B,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,wBAAsB,cAAc,CAClC,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,EAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED,qBAAa,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAC/D,YAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;IAGhC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;gBAFJ,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,WAAW;IAG3B,KAAK;IAIL,OAAO,IAAI,MAAM;IAIX,WAAW,CAAC,EAAE,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YA6BjD,YAAY;CAgB3B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosSigner = exports.getAptosSigner = void 0;
|
|
4
|
+
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
|
|
5
|
+
const aptos_1 = require("aptos");
|
|
6
|
+
const platform_1 = require("./platform");
|
|
7
|
+
// returns a SignOnlySigner for the Aptos platform
|
|
8
|
+
async function getAptosSigner(rpc, privateKey) {
|
|
9
|
+
const [_, chain] = await platform_1.AptosPlatform.chainFromRpc(rpc);
|
|
10
|
+
return new AptosSigner(chain, new aptos_1.AptosAccount(sdk_connect_1.encoding.hex.decode(privateKey)), rpc);
|
|
11
|
+
}
|
|
12
|
+
exports.getAptosSigner = getAptosSigner;
|
|
13
|
+
class AptosSigner {
|
|
14
|
+
_chain;
|
|
15
|
+
_account;
|
|
16
|
+
_rpc;
|
|
17
|
+
constructor(_chain, _account, _rpc) {
|
|
18
|
+
this._chain = _chain;
|
|
19
|
+
this._account = _account;
|
|
20
|
+
this._rpc = _rpc;
|
|
21
|
+
}
|
|
22
|
+
chain() {
|
|
23
|
+
return this._chain;
|
|
24
|
+
}
|
|
25
|
+
address() {
|
|
26
|
+
return this._account.address().hex();
|
|
27
|
+
}
|
|
28
|
+
async signAndSend(tx) {
|
|
29
|
+
const txhashes = [];
|
|
30
|
+
for (const txn of tx) {
|
|
31
|
+
const { description, transaction } = txn;
|
|
32
|
+
console.log(`Signing: ${description} for ${this.address()}`);
|
|
33
|
+
// overwriting `max_gas_amount` and `gas_unit_price` defaults
|
|
34
|
+
// rest of defaults are defined here: https://aptos-labs.github.io/ts-sdk-doc/classes/AptosClient.html#generateTransaction
|
|
35
|
+
const customOpts = {
|
|
36
|
+
gas_unit_price: "100",
|
|
37
|
+
max_gas_amount: "30000",
|
|
38
|
+
expiration_timestamp_secs: (BigInt(Date.now() + 8 * 60 * 60 * 1000) / 1000n).toString(),
|
|
39
|
+
};
|
|
40
|
+
const tx = await this._rpc.generateTransaction(this._account.address(), transaction, customOpts);
|
|
41
|
+
const { hash } = await this._simSignSend(tx);
|
|
42
|
+
txhashes.push(hash);
|
|
43
|
+
}
|
|
44
|
+
return txhashes;
|
|
45
|
+
}
|
|
46
|
+
async _simSignSend(rawTx) {
|
|
47
|
+
// simulate transaction
|
|
48
|
+
await this._rpc.simulateTransaction(this._account, rawTx).then((sims) => sims.forEach((tx) => {
|
|
49
|
+
if (!tx.success) {
|
|
50
|
+
throw new Error(`Transaction failed: ${tx.vm_status}\n${JSON.stringify(tx, null, 2)}`);
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
// sign & submit transaction
|
|
54
|
+
return this._rpc
|
|
55
|
+
.signTransaction(this._account, rawTx)
|
|
56
|
+
.then((signedTx) => this._rpc.submitTransaction(signedTx))
|
|
57
|
+
.then((pendingTx) => this._rpc.waitForTransactionWithResult(pendingTx.hash));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.AptosSigner = AptosSigner;
|
|
61
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":";;;AAAA,kEAQ0C;AAC1C,iCAA0E;AAC1E,yCAA2C;AAG3C,kDAAkD;AAC3C,KAAK,UAAU,cAAc,CAClC,GAA2B,EAC3B,UAAkB;IAElB,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,wBAAa,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACzD,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,oBAAY,CAAC,sBAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACxF,CAAC;AAND,wCAMC;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qC;QAC9D,uBAAuB;QACvB,MAAM,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CACtE,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YAClB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE;gBACf,MAAM,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;aACxF;QACH,CAAC,CAAC,CACH,CAAC;QAEF,4BAA4B;QAC5B,OAAO,IAAI,CAAC,IAAI;aACb,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;aACrC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;aACzD,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACjF,CAAC;CACF;AA9DD,kCA8DC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PlatformToChains, UniversalOrNative } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
export declare const unusedNonce = 0;
|
|
3
|
+
export declare const unusedArbiterFee = 0n;
|
|
4
|
+
export declare const _platform: "Aptos";
|
|
5
|
+
export type AptosPlatformType = typeof _platform;
|
|
6
|
+
export type AptosChains = PlatformToChains<AptosPlatformType>;
|
|
7
|
+
export type UniversalOrAptos = UniversalOrNative<AptosChains>;
|
|
8
|
+
export type AnyAptosAddress = UniversalOrAptos | string | Uint8Array;
|
|
9
|
+
export type CurrentCoinBalancesResponse = {
|
|
10
|
+
data: {
|
|
11
|
+
current_coin_balances: CoinBalance[];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type CoinBalance = {
|
|
15
|
+
coin_type: string;
|
|
16
|
+
amount: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Test if given string is a valid fully qualified type of moduleAddress::moduleName::structName.
|
|
20
|
+
* @param str String to test
|
|
21
|
+
* @returns Whether or not given string is a valid type
|
|
22
|
+
*/
|
|
23
|
+
export declare const isValidAptosType: (str: string) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns module address from given fully qualified type/module address.
|
|
26
|
+
* @param str FQT or module address
|
|
27
|
+
* @returns Module address
|
|
28
|
+
*/
|
|
29
|
+
export declare const coalesceModuleAddress: (str: string) => string;
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGvF,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,eAAO,MAAM,SAAS,EAAE,OAAiB,CAAC;AAC1C,MAAM,MAAM,iBAAiB,GAAG,OAAO,SAAS,CAAC;AACjD,MAAM,MAAM,WAAW,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAC9D,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,MAAM,GAAG,UAAU,CAAC;AAErE,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE;QAAE,qBAAqB,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAAoD,CAAC;AAEpG;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,KAAG,MAAwC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.coalesceModuleAddress = exports.isValidAptosType = exports._platform = exports.unusedArbiterFee = exports.unusedNonce = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
exports.unusedNonce = 0;
|
|
6
|
+
exports.unusedArbiterFee = 0n;
|
|
7
|
+
exports._platform = "Aptos";
|
|
8
|
+
/**
|
|
9
|
+
* Test if given string is a valid fully qualified type of moduleAddress::moduleName::structName.
|
|
10
|
+
* @param str String to test
|
|
11
|
+
* @returns Whether or not given string is a valid type
|
|
12
|
+
*/
|
|
13
|
+
const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str);
|
|
14
|
+
exports.isValidAptosType = isValidAptosType;
|
|
15
|
+
/**
|
|
16
|
+
* Returns module address from given fully qualified type/module address.
|
|
17
|
+
* @param str FQT or module address
|
|
18
|
+
* @returns Module address
|
|
19
|
+
*/
|
|
20
|
+
const coalesceModuleAddress = (str) => str.split(constants_1.APTOS_SEPARATOR)[0];
|
|
21
|
+
exports.coalesceModuleAddress = coalesceModuleAddress;
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAEjC,QAAA,WAAW,GAAG,CAAC,CAAC;AAChB,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEtB,QAAA,SAAS,GAAY,OAAO,CAAC;AAe1C;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAAvF,QAAA,gBAAgB,oBAAuE;AAEpG;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,2BAAe,CAAC,CAAC,CAAC,CAAE,CAAC;AAAhF,QAAA,qBAAqB,yBAA2D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Network, UnsignedTransaction } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { Types } from "aptos";
|
|
3
|
+
import { AptosChains } from "./types";
|
|
4
|
+
export declare class AptosUnsignedTransaction<N extends Network, C extends AptosChains> implements UnsignedTransaction<N, C> {
|
|
5
|
+
readonly transaction: Types.EntryFunctionPayload;
|
|
6
|
+
readonly network: N;
|
|
7
|
+
readonly chain: C;
|
|
8
|
+
readonly description: string;
|
|
9
|
+
readonly parallelizable: boolean;
|
|
10
|
+
constructor(transaction: Types.EntryFunctionPayload, network: N, chain: C, description: string, parallelizable?: boolean);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=unsignedTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsignedTransaction.d.ts","sourceRoot":"","sources":["../../src/unsignedTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,wBAAwB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAC5E,YAAW,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC;IAGlC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,oBAAoB;IAChD,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,QAAQ,CAAC,cAAc,EAAE,OAAO;gBAJvB,WAAW,EAAE,KAAK,CAAC,oBAAoB,EACvC,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,CAAC,EACR,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,OAAe;CAE3C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AptosUnsignedTransaction = void 0;
|
|
4
|
+
class AptosUnsignedTransaction {
|
|
5
|
+
transaction;
|
|
6
|
+
network;
|
|
7
|
+
chain;
|
|
8
|
+
description;
|
|
9
|
+
parallelizable;
|
|
10
|
+
constructor(transaction, network, chain, description, parallelizable = false) {
|
|
11
|
+
this.transaction = transaction;
|
|
12
|
+
this.network = network;
|
|
13
|
+
this.chain = chain;
|
|
14
|
+
this.description = description;
|
|
15
|
+
this.parallelizable = parallelizable;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.AptosUnsignedTransaction = AptosUnsignedTransaction;
|
|
19
|
+
//# sourceMappingURL=unsignedTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsignedTransaction.js","sourceRoot":"","sources":["../../src/unsignedTransaction.ts"],"names":[],"mappings":";;;AAIA,MAAa,wBAAwB;IAIxB;IACA;IACA;IACA;IACA;IALX,YACW,WAAuC,EACvC,OAAU,EACV,KAAQ,EACR,WAAmB,EACnB,iBAA0B,KAAK;QAJ/B,gBAAW,GAAX,WAAW,CAA4B;QACvC,YAAO,GAAP,OAAO,CAAG;QACV,UAAK,GAAL,KAAK,CAAG;QACR,gBAAW,GAAX,WAAW,CAAQ;QACnB,mBAAc,GAAd,cAAc,CAAiB;IACvC,CAAC;CACL;AAVD,4DAUC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Address, Platform, UniversalAddress } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AnyAptosAddress } from "./types";
|
|
3
|
+
export declare const AptosZeroAddress = "0x";
|
|
4
|
+
export declare function ensureFullAptosAddress(address: string): string;
|
|
5
|
+
export declare class AptosAddress implements Address {
|
|
6
|
+
static readonly byteSize = 32;
|
|
7
|
+
readonly platform: Platform;
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly address: Uint8Array;
|
|
10
|
+
readonly module: string | undefined;
|
|
11
|
+
constructor(address: AnyAptosAddress);
|
|
12
|
+
unwrap(): string;
|
|
13
|
+
toString(): string;
|
|
14
|
+
toNative(): this;
|
|
15
|
+
toUint8Array(): Uint8Array;
|
|
16
|
+
toUniversalAddress(): UniversalAddress;
|
|
17
|
+
static instanceof(address: any): address is AptosAddress;
|
|
18
|
+
equals(other: AptosAddress | UniversalAddress): boolean;
|
|
19
|
+
}
|
|
20
|
+
declare module "@wormhole-foundation/sdk-connect" {
|
|
21
|
+
namespace WormholeRegistry {
|
|
22
|
+
interface PlatformToNativeAddressMapping {
|
|
23
|
+
Aptos: AptosAddress;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,gBAAgB,EAGjB,MAAM,kCAAkC,CAAC;AAI1C,OAAO,EAAE,eAAe,EAA+B,MAAM,SAAS,CAAC;AAEvE,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAIrC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,UAMrD;AAED,qBAAa,YAAa,YAAW,OAAO;IAC1C,MAAM,CAAC,QAAQ,CAAC,QAAQ,MAAM;IAC9B,SAAgB,QAAQ,EAAE,QAAQ,CAA2B;IAE7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAY;IAGjC,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAG7B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;gBAExB,OAAO,EAAE,eAAe;IAyBpC,MAAM,IAAI,MAAM;IAKhB,QAAQ,IAAI,MAAM;IAGlB,QAAQ;IAGR,YAAY;IAGZ,kBAAkB;IAIlB,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,YAAY;IAIxD,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,gBAAgB,GAAG,OAAO;CAOxD;AAED,OAAO,QAAQ,kCAAkC,CAAC;IAChD,UAAiB,gBAAgB,CAAC;QAChC,UAAU,8BAA8B;YACtC,KAAK,EAAE,YAAY,CAAC;SACrB;KACF;CACF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { UniversalAddress, encoding, registerNative, } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { APTOS_SEPARATOR } from "./constants";
|
|
3
|
+
import { AptosPlatform } from "./platform";
|
|
4
|
+
import { isValidAptosType, _platform } from "./types";
|
|
5
|
+
export const AptosZeroAddress = "0x";
|
|
6
|
+
// Sometimes Aptos addresses will be trimmed of leading 0s
|
|
7
|
+
// add them back if necessary
|
|
8
|
+
export function ensureFullAptosAddress(address) {
|
|
9
|
+
if (address.length % 2 !== 0 || address.length < 66) {
|
|
10
|
+
address = address.startsWith("0x") ? address.slice(2) : address;
|
|
11
|
+
return "0x" + address.padStart(64, "0");
|
|
12
|
+
}
|
|
13
|
+
return address;
|
|
14
|
+
}
|
|
15
|
+
export class AptosAddress {
|
|
16
|
+
static byteSize = 32;
|
|
17
|
+
platform = AptosPlatform._platform;
|
|
18
|
+
type = "Native";
|
|
19
|
+
// Full 32 bytes of Address
|
|
20
|
+
address;
|
|
21
|
+
// Optional module and contract name
|
|
22
|
+
module;
|
|
23
|
+
constructor(address) {
|
|
24
|
+
if (AptosAddress.instanceof(address)) {
|
|
25
|
+
this.address = address.address;
|
|
26
|
+
this.module = address.module;
|
|
27
|
+
}
|
|
28
|
+
else if (UniversalAddress.instanceof(address)) {
|
|
29
|
+
this.address = address.toUint8Array();
|
|
30
|
+
}
|
|
31
|
+
else if (typeof address === "string") {
|
|
32
|
+
// If we've got an address of the form `0x1234...::module::...` then
|
|
33
|
+
// stuff anything after the first `::` into the module field
|
|
34
|
+
// and continue processing the address
|
|
35
|
+
if (isValidAptosType(address)) {
|
|
36
|
+
const chunks = address.split(APTOS_SEPARATOR);
|
|
37
|
+
this.module = chunks.slice(1).join(APTOS_SEPARATOR);
|
|
38
|
+
address = chunks[0];
|
|
39
|
+
}
|
|
40
|
+
address = ensureFullAptosAddress(address);
|
|
41
|
+
if (!encoding.hex.valid(address))
|
|
42
|
+
throw new Error("Invalid Aptos address: " + address);
|
|
43
|
+
this.address = encoding.hex.decode(address);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.address = address;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
unwrap() {
|
|
50
|
+
const addr = encoding.hex.encode(this.address).replace(/^0+/, "");
|
|
51
|
+
const module = this.module ? APTOS_SEPARATOR + this.module : "";
|
|
52
|
+
return `0x${addr}${module}`;
|
|
53
|
+
}
|
|
54
|
+
toString() {
|
|
55
|
+
return this.unwrap();
|
|
56
|
+
}
|
|
57
|
+
toNative() {
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
toUint8Array() {
|
|
61
|
+
return this.address;
|
|
62
|
+
}
|
|
63
|
+
toUniversalAddress() {
|
|
64
|
+
return new UniversalAddress(this.toUint8Array());
|
|
65
|
+
}
|
|
66
|
+
static instanceof(address) {
|
|
67
|
+
return address.platform === AptosPlatform._platform;
|
|
68
|
+
}
|
|
69
|
+
equals(other) {
|
|
70
|
+
if (AptosAddress.instanceof(other)) {
|
|
71
|
+
return other.unwrap() === this.unwrap();
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return this.toUniversalAddress().equals(other);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
registerNative(_platform, AptosAddress);
|
|
79
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,EAChB,QAAQ,EACR,cAAc,GACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAmB,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEvE,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,0DAA0D;AAC1D,6BAA6B;AAC7B,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,EAAE,EAAE;QACnD,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QAChE,OAAO,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;KACzC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,OAAO,YAAY;IACvB,MAAM,CAAU,QAAQ,GAAG,EAAE,CAAC;IACd,QAAQ,GAAa,aAAa,CAAC,SAAS,CAAC;IAEpD,IAAI,GAAW,QAAQ,CAAC;IAEjC,2BAA2B;IAClB,OAAO,CAAa;IAE7B,oCAAoC;IAC3B,MAAM,CAAqB;IAEpC,YAAY,OAAwB;QAClC,IAAI,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YACpC,IAAI,CAAC,OAAO,GAAG,OAA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C;IACD,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IACD,QAAQ;QACN,OAAO,IAAI,CAAC;IACd,CAAC;IACD,YAAY;QACV,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,kBAAkB;QAChB,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,OAAY;QAC5B,OAAO,OAAO,CAAC,QAAQ,KAAK,aAAa,CAAC,SAAS,CAAC;IACtD,CAAC;IAED,MAAM,CAAC,KAAsC;QAC3C,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YAClC,OAAO,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;SACzC;aAAM;YACL,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;SAChD;IACH,CAAC;;AAWH,cAAc,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,UAAU,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAAE,SAAQ,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/chain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAW,MAAM,kCAAkC,CAAC;AAGzE,MAAM,OAAO,UAAqD,SAAQ,YAAkB;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,+BAA+B,CAAC;AACvD,eAAO,MAAM,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Chain, ChainsConfig, Network, PlatformContext, StaticPlatformMethods, Balances, SignedTx, TokenId, TxHash } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AptosClient } from "aptos";
|
|
3
|
+
import { AptosChain } from "./chain";
|
|
4
|
+
import { AptosChains, AptosPlatformType } from "./types";
|
|
5
|
+
import { AnyAptosAddress } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* @category Aptos
|
|
8
|
+
*/
|
|
9
|
+
export declare class AptosPlatform<N extends Network> extends PlatformContext<N, AptosPlatformType> implements StaticPlatformMethods<AptosPlatformType, typeof AptosPlatform> {
|
|
10
|
+
static _platform: "Aptos";
|
|
11
|
+
constructor(network: N, config?: ChainsConfig<N, AptosPlatformType>);
|
|
12
|
+
getRpc<C extends AptosChains>(chain: C): AptosClient;
|
|
13
|
+
getChain<C extends AptosChains>(chain: C, rpc?: AptosClient): AptosChain<N, C>;
|
|
14
|
+
static nativeTokenId<N extends Network, C extends AptosChains>(network: N, chain: C): TokenId<C>;
|
|
15
|
+
static isNativeTokenId<N extends Network, C extends AptosChains>(network: N, chain: C, tokenId: TokenId): boolean;
|
|
16
|
+
static isSupportedChain(chain: Chain): boolean;
|
|
17
|
+
static getDecimals(chain: Chain, rpc: AptosClient, token: AnyAptosAddress): Promise<number>;
|
|
18
|
+
static getBalance(chain: Chain, rpc: AptosClient, walletAddress: string, token: AnyAptosAddress): Promise<bigint | null>;
|
|
19
|
+
static getBalances(chain: Chain, rpc: AptosClient, walletAddress: string, tokens: AnyAptosAddress[]): Promise<Balances>;
|
|
20
|
+
static sendWait(chain: Chain, rpc: AptosClient, stxns: SignedTx[]): Promise<TxHash[]>;
|
|
21
|
+
static getLatestBlock(rpc: AptosClient): Promise<number>;
|
|
22
|
+
static getLatestFinalizedBlock(rpc: AptosClient): Promise<number>;
|
|
23
|
+
static chainFromChainId(chainId: string | bigint): [Network, AptosChains];
|
|
24
|
+
static chainFromRpc(rpc: AptosClient): Promise<[Network, AptosChains]>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,OAAO,EACP,eAAe,EACf,qBAAqB,EAIrB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,MAAM,EAIP,MAAM,kCAAkC,CAAC;AAC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AE,WAAW,EAChB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;WAmBZ,WAAW,CACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,WAAW,EAChB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,eAAe,EAAE,GACxB,OAAO,CAAC,QAAQ,CAAC;WAWP,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;WAW9E,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;WAKjD,uBAAuB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvE,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,EAAE,WAAW,CAAC;WAa5D,YAAY,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;CAK7E"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PlatformContext, Wormhole, isNative, networkPlatformConfigs, chainToPlatform, nativeChainIds, decimals as nativeDecimals, } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AptosClient } from "aptos";
|
|
3
|
+
import { AptosChain } from "./chain";
|
|
4
|
+
import { _platform } from "./types";
|
|
5
|
+
import { CoinClient, Types } from "aptos";
|
|
6
|
+
import { AptosAddress } from "./address";
|
|
7
|
+
import { APTOS_COIN, APTOS_SEPARATOR } from "./constants";
|
|
8
|
+
/**
|
|
9
|
+
* @category Aptos
|
|
10
|
+
*/
|
|
11
|
+
export class AptosPlatform extends PlatformContext {
|
|
12
|
+
static _platform = _platform;
|
|
13
|
+
constructor(network, config) {
|
|
14
|
+
super(network, config ?? networkPlatformConfigs(network, AptosPlatform._platform));
|
|
15
|
+
}
|
|
16
|
+
getRpc(chain) {
|
|
17
|
+
if (chain in this.config)
|
|
18
|
+
return new AptosClient(this.config[chain].rpc);
|
|
19
|
+
throw new Error("No configuration available for chain: " + chain);
|
|
20
|
+
}
|
|
21
|
+
getChain(chain, rpc) {
|
|
22
|
+
if (chain in this.config)
|
|
23
|
+
return new AptosChain(chain, this);
|
|
24
|
+
throw new Error("No configuration available for chain: " + chain);
|
|
25
|
+
}
|
|
26
|
+
static nativeTokenId(network, chain) {
|
|
27
|
+
if (!this.isSupportedChain(chain))
|
|
28
|
+
throw new Error(`invalid chain: ${chain}`);
|
|
29
|
+
return Wormhole.tokenId(chain, APTOS_COIN);
|
|
30
|
+
}
|
|
31
|
+
static isNativeTokenId(network, chain, tokenId) {
|
|
32
|
+
if (!this.isSupportedChain(chain))
|
|
33
|
+
return false;
|
|
34
|
+
if (tokenId.chain !== chain)
|
|
35
|
+
return false;
|
|
36
|
+
const native = this.nativeTokenId(network, chain);
|
|
37
|
+
return native == tokenId;
|
|
38
|
+
}
|
|
39
|
+
static isSupportedChain(chain) {
|
|
40
|
+
const platform = chainToPlatform(chain);
|
|
41
|
+
return platform === AptosPlatform._platform;
|
|
42
|
+
}
|
|
43
|
+
static async getDecimals(chain, rpc, token) {
|
|
44
|
+
if (isNative(token))
|
|
45
|
+
return nativeDecimals.nativeDecimals(AptosPlatform._platform);
|
|
46
|
+
const tokenAddr = token.toString();
|
|
47
|
+
const coinType = `0x1::coin::CoinInfo<${tokenAddr}>`;
|
|
48
|
+
const decimals = (await rpc.getAccountResource(tokenAddr.split(APTOS_SEPARATOR)[0], coinType)).data.decimals;
|
|
49
|
+
return decimals;
|
|
50
|
+
}
|
|
51
|
+
static async getBalance(chain, rpc, walletAddress, token) {
|
|
52
|
+
const tokenAddress = isNative(token) ? APTOS_COIN : token.toString();
|
|
53
|
+
const cc = new CoinClient(rpc);
|
|
54
|
+
try {
|
|
55
|
+
const balance = await cc.checkBalance(walletAddress, {
|
|
56
|
+
coinType: tokenAddress,
|
|
57
|
+
});
|
|
58
|
+
return balance;
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
if ((e instanceof Types.ApiError || e.errorCode === "resource_not_found") &&
|
|
62
|
+
e.status === 404) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
throw e;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static async getBalances(chain, rpc, walletAddress, tokens) {
|
|
69
|
+
const balancesArr = await Promise.all(tokens.map(async (token) => {
|
|
70
|
+
const balance = await this.getBalance(chain, rpc, walletAddress, token);
|
|
71
|
+
const address = isNative(token) ? "native" : new AptosAddress(token).toString();
|
|
72
|
+
return { [address]: balance };
|
|
73
|
+
}));
|
|
74
|
+
return balancesArr.reduce((obj, item) => Object.assign(obj, item), {});
|
|
75
|
+
}
|
|
76
|
+
static async sendWait(chain, rpc, stxns) {
|
|
77
|
+
// TODO: concurrent
|
|
78
|
+
const txhashes = [];
|
|
79
|
+
for (const stxn of stxns) {
|
|
80
|
+
const pendingTx = await rpc.submitTransaction(stxn);
|
|
81
|
+
const res = await rpc.waitForTransactionWithResult(pendingTx.hash);
|
|
82
|
+
txhashes.push(res.hash);
|
|
83
|
+
}
|
|
84
|
+
return txhashes;
|
|
85
|
+
}
|
|
86
|
+
static async getLatestBlock(rpc) {
|
|
87
|
+
const li = await rpc.getLedgerInfo();
|
|
88
|
+
return Number(li.block_height);
|
|
89
|
+
}
|
|
90
|
+
static async getLatestFinalizedBlock(rpc) {
|
|
91
|
+
const li = await rpc.getLedgerInfo();
|
|
92
|
+
return Number(li.block_height);
|
|
93
|
+
}
|
|
94
|
+
static chainFromChainId(chainId) {
|
|
95
|
+
const netChain = nativeChainIds.platformNativeChainIdToNetworkChain(AptosPlatform._platform, BigInt(chainId));
|
|
96
|
+
if (!netChain)
|
|
97
|
+
throw new Error(`No matching chainId to determine network and chain: ${chainId}`);
|
|
98
|
+
const [network, chain] = netChain;
|
|
99
|
+
return [network, chain];
|
|
100
|
+
}
|
|
101
|
+
static async chainFromRpc(rpc) {
|
|
102
|
+
const conn = rpc;
|
|
103
|
+
const ci = await conn.getChainId();
|
|
104
|
+
return this.chainFromChainId(ci.toString());
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,eAAe,EAEf,QAAQ,EACR,QAAQ,EACR,sBAAsB,EAKtB,eAAe,EACf,cAAc,EACd,QAAQ,IAAI,cAAc,GAC3B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAkC,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG1D;;GAEG;AACH,MAAM,OAAO,aACX,SAAQ,eAAqC;IAG7C,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;IAE7B,YAAY,OAAU,EAAE,MAA2C;QACjE,KAAK,CAAC,OAAO,EAAE,MAAM,IAAI,sBAAsB,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,CAAwB,KAAQ;QACpC,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,CAAC;QAC1E,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,KAAK,CAAC,CAAC;IACpE,CAAC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C,SAAS,EACvB,MAAM,CAAC,OAAO,CAAC,CAChB,CAAC;QAEF,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,uDAAuD,OAAO,EAAE,CAAC,CAAC;QAEpF,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,QAAQ,CAAC;QAClC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,GAAgB;QACxC,MAAM,IAAI,GAAG,GAAkB,CAAC;QAChC,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACnC,OAAO,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Network, RpcConnection, SignAndSendSigner, Signer, TxHash, UnsignedTransaction } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AptosAccount, AptosClient } from "aptos";
|
|
3
|
+
import { AptosChains } from "./types";
|
|
4
|
+
export declare function getAptosSigner(rpc: RpcConnection<"Aptos">, privateKey: string): Promise<Signer>;
|
|
5
|
+
export declare class AptosSigner<N extends Network, C extends AptosChains> implements SignAndSendSigner<N, C> {
|
|
6
|
+
private _chain;
|
|
7
|
+
private _account;
|
|
8
|
+
private _rpc;
|
|
9
|
+
constructor(_chain: C, _account: AptosAccount, _rpc: AptosClient);
|
|
10
|
+
chain(): C;
|
|
11
|
+
address(): string;
|
|
12
|
+
signAndSend(tx: UnsignedTransaction[]): Promise<TxHash[]>;
|
|
13
|
+
private _simSignSend;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,MAAM,EACN,MAAM,EACN,mBAAmB,EAEpB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,WAAW,EAA0B,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,wBAAsB,cAAc,CAClC,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,EAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED,qBAAa,WAAW,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAC/D,YAAW,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;IAGhC,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,IAAI;gBAFJ,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,WAAW;IAG3B,KAAK;IAIL,OAAO,IAAI,MAAM;IAIX,WAAW,CAAC,EAAE,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;YA6BjD,YAAY;CAgB3B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { encoding, } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { AptosAccount } from "aptos";
|
|
3
|
+
import { AptosPlatform } from "./platform";
|
|
4
|
+
// returns a SignOnlySigner for the Aptos platform
|
|
5
|
+
export async function getAptosSigner(rpc, privateKey) {
|
|
6
|
+
const [_, chain] = await AptosPlatform.chainFromRpc(rpc);
|
|
7
|
+
return new AptosSigner(chain, new AptosAccount(encoding.hex.decode(privateKey)), rpc);
|
|
8
|
+
}
|
|
9
|
+
export class AptosSigner {
|
|
10
|
+
_chain;
|
|
11
|
+
_account;
|
|
12
|
+
_rpc;
|
|
13
|
+
constructor(_chain, _account, _rpc) {
|
|
14
|
+
this._chain = _chain;
|
|
15
|
+
this._account = _account;
|
|
16
|
+
this._rpc = _rpc;
|
|
17
|
+
}
|
|
18
|
+
chain() {
|
|
19
|
+
return this._chain;
|
|
20
|
+
}
|
|
21
|
+
address() {
|
|
22
|
+
return this._account.address().hex();
|
|
23
|
+
}
|
|
24
|
+
async signAndSend(tx) {
|
|
25
|
+
const txhashes = [];
|
|
26
|
+
for (const txn of tx) {
|
|
27
|
+
const { description, transaction } = txn;
|
|
28
|
+
console.log(`Signing: ${description} for ${this.address()}`);
|
|
29
|
+
// overwriting `max_gas_amount` and `gas_unit_price` defaults
|
|
30
|
+
// rest of defaults are defined here: https://aptos-labs.github.io/ts-sdk-doc/classes/AptosClient.html#generateTransaction
|
|
31
|
+
const customOpts = {
|
|
32
|
+
gas_unit_price: "100",
|
|
33
|
+
max_gas_amount: "30000",
|
|
34
|
+
expiration_timestamp_secs: (BigInt(Date.now() + 8 * 60 * 60 * 1000) / 1000n).toString(),
|
|
35
|
+
};
|
|
36
|
+
const tx = await this._rpc.generateTransaction(this._account.address(), transaction, customOpts);
|
|
37
|
+
const { hash } = await this._simSignSend(tx);
|
|
38
|
+
txhashes.push(hash);
|
|
39
|
+
}
|
|
40
|
+
return txhashes;
|
|
41
|
+
}
|
|
42
|
+
async _simSignSend(rawTx) {
|
|
43
|
+
// simulate transaction
|
|
44
|
+
await this._rpc.simulateTransaction(this._account, rawTx).then((sims) => sims.forEach((tx) => {
|
|
45
|
+
if (!tx.success) {
|
|
46
|
+
throw new Error(`Transaction failed: ${tx.vm_status}\n${JSON.stringify(tx, null, 2)}`);
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
// sign & submit transaction
|
|
50
|
+
return this._rpc
|
|
51
|
+
.signTransaction(this._account, rawTx)
|
|
52
|
+
.then((signedTx) => this._rpc.submitTransaction(signedTx))
|
|
53
|
+
.then((pendingTx) => this._rpc.waitForTransactionWithResult(pendingTx.hash));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AAI,CAAC,4BAA4B,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACjF,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PlatformToChains, UniversalOrNative } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
export declare const unusedNonce = 0;
|
|
3
|
+
export declare const unusedArbiterFee = 0n;
|
|
4
|
+
export declare const _platform: "Aptos";
|
|
5
|
+
export type AptosPlatformType = typeof _platform;
|
|
6
|
+
export type AptosChains = PlatformToChains<AptosPlatformType>;
|
|
7
|
+
export type UniversalOrAptos = UniversalOrNative<AptosChains>;
|
|
8
|
+
export type AnyAptosAddress = UniversalOrAptos | string | Uint8Array;
|
|
9
|
+
export type CurrentCoinBalancesResponse = {
|
|
10
|
+
data: {
|
|
11
|
+
current_coin_balances: CoinBalance[];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type CoinBalance = {
|
|
15
|
+
coin_type: string;
|
|
16
|
+
amount: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Test if given string is a valid fully qualified type of moduleAddress::moduleName::structName.
|
|
20
|
+
* @param str String to test
|
|
21
|
+
* @returns Whether or not given string is a valid type
|
|
22
|
+
*/
|
|
23
|
+
export declare const isValidAptosType: (str: string) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns module address from given fully qualified type/module address.
|
|
26
|
+
* @param str FQT or module address
|
|
27
|
+
* @returns Module address
|
|
28
|
+
*/
|
|
29
|
+
export declare const coalesceModuleAddress: (str: string) => string;
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGvF,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC,eAAO,MAAM,SAAS,EAAE,OAAiB,CAAC;AAC1C,MAAM,MAAM,iBAAiB,GAAG,OAAO,SAAS,CAAC;AACjD,MAAM,MAAM,WAAW,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;AAC9D,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,MAAM,GAAG,UAAU,CAAC;AAErE,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE;QAAE,qBAAqB,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAAoD,CAAC;AAEpG;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAS,MAAM,KAAG,MAAwC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { APTOS_SEPARATOR } from "./constants";
|
|
2
|
+
export const unusedNonce = 0;
|
|
3
|
+
export const unusedArbiterFee = 0n;
|
|
4
|
+
export const _platform = "Aptos";
|
|
5
|
+
/**
|
|
6
|
+
* Test if given string is a valid fully qualified type of moduleAddress::moduleName::structName.
|
|
7
|
+
* @param str String to test
|
|
8
|
+
* @returns Whether or not given string is a valid type
|
|
9
|
+
*/
|
|
10
|
+
export const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str);
|
|
11
|
+
/**
|
|
12
|
+
* Returns module address from given fully qualified type/module address.
|
|
13
|
+
* @param str FQT or module address
|
|
14
|
+
* @returns Module address
|
|
15
|
+
*/
|
|
16
|
+
export const coalesceModuleAddress = (str) => str.split(APTOS_SEPARATOR)[0];
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,MAAM,CAAC,MAAM,SAAS,GAAY,OAAO,CAAC;AAe1C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEpG;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Network, UnsignedTransaction } from "@wormhole-foundation/sdk-connect";
|
|
2
|
+
import { Types } from "aptos";
|
|
3
|
+
import { AptosChains } from "./types";
|
|
4
|
+
export declare class AptosUnsignedTransaction<N extends Network, C extends AptosChains> implements UnsignedTransaction<N, C> {
|
|
5
|
+
readonly transaction: Types.EntryFunctionPayload;
|
|
6
|
+
readonly network: N;
|
|
7
|
+
readonly chain: C;
|
|
8
|
+
readonly description: string;
|
|
9
|
+
readonly parallelizable: boolean;
|
|
10
|
+
constructor(transaction: Types.EntryFunctionPayload, network: N, chain: C, description: string, parallelizable?: boolean);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=unsignedTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsignedTransaction.d.ts","sourceRoot":"","sources":["../../src/unsignedTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,wBAAwB,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,WAAW,CAC5E,YAAW,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC;IAGlC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,oBAAoB;IAChD,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnB,QAAQ,CAAC,KAAK,EAAE,CAAC;IACjB,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,QAAQ,CAAC,cAAc,EAAE,OAAO;gBAJvB,WAAW,EAAE,KAAK,CAAC,oBAAoB,EACvC,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,CAAC,EACR,WAAW,EAAE,MAAM,EACnB,cAAc,GAAE,OAAe;CAE3C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class AptosUnsignedTransaction {
|
|
2
|
+
transaction;
|
|
3
|
+
network;
|
|
4
|
+
chain;
|
|
5
|
+
description;
|
|
6
|
+
parallelizable;
|
|
7
|
+
constructor(transaction, network, chain, description, parallelizable = false) {
|
|
8
|
+
this.transaction = transaction;
|
|
9
|
+
this.network = network;
|
|
10
|
+
this.chain = chain;
|
|
11
|
+
this.description = description;
|
|
12
|
+
this.parallelizable = parallelizable;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=unsignedTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unsignedTransaction.js","sourceRoot":"","sources":["../../src/unsignedTransaction.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,wBAAwB;IAIxB;IACA;IACA;IACA;IACA;IALX,YACW,WAAuC,EACvC,OAAU,EACV,KAAQ,EACR,WAAmB,EACnB,iBAA0B,KAAK;QAJ/B,gBAAW,GAAX,WAAW,CAA4B;QACvC,YAAO,GAAP,OAAO,CAAG;QACV,UAAK,GAAL,KAAK,CAAG;QACR,gBAAW,GAAX,WAAW,CAAQ;QACnB,mBAAc,GAAd,cAAc,CAAiB;IACvC,CAAC;CACL"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wormhole-foundation/sdk-aptos",
|
|
3
|
+
"version": "0.5.0-alpha.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/wormhole-foundation/connect-sdk/issues"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/wormhole-foundation/connect-sdk#readme",
|
|
12
|
+
"directories": {
|
|
13
|
+
"test": "__tests__"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"main": "./dist/cjs/index.js",
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"module": "./dist/esm/index.js",
|
|
19
|
+
"author": "",
|
|
20
|
+
"description": "SDK for Solana, used in conjunction with @wormhole-foundation/sdk",
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/cjs",
|
|
23
|
+
"dist/esm"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"wormhole",
|
|
27
|
+
"sdk",
|
|
28
|
+
"typescript",
|
|
29
|
+
"connect",
|
|
30
|
+
"solana"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": true,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build:cjs": "tsc -p ./tsconfig.cjs.json",
|
|
38
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
39
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
40
|
+
"rebuild": "npm run clean && npm run build",
|
|
41
|
+
"clean": "rm -rf ./dist && rm -rf ./.turbo",
|
|
42
|
+
"lint": "npm run prettier && eslint --fix",
|
|
43
|
+
"test": "jest --config ./jest.config.ts",
|
|
44
|
+
"prettier": "prettier --write ./src"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@wormhole-foundation/sdk-connect": "0.5.0-alpha.0",
|
|
48
|
+
"aptos": "1.5.0"
|
|
49
|
+
}
|
|
50
|
+
}
|