Skip to content

Commit

Permalink
squiggle
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Dec 27, 2023
1 parent 7056e86 commit 1862b5f
Show file tree
Hide file tree
Showing 24 changed files with 896 additions and 1,857 deletions.
18 changes: 13 additions & 5 deletions core/base/src/utils/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ export const b58 = {
export const bignum = {
decode: (input: string | Uint8Array) =>
typeof input === "string" ? BigInt(input) : BigInt(hex.encode(input, true)),
encode: (input: bigint, prefix: boolean = false) => (prefix ? "0x" : "") + input.toString(16),
encode: (input: bigint, prefix: boolean = false) => bignum.toString(input, prefix),
toString: (input: bigint, prefix: boolean = false) => {
let str = input.toString(16);
str = str.length % 2 === 1 ? (str = "0" + str) : str;
if (prefix) return "0x" + str;
return str;
},
toBytes: (input: bigint, length?: number) => {
const b = hex.decode(bignum.toString(input));
if (!length) return b;
return bytes.zpad(b, length);
},
};

export const bytes = {
encode: (value: string | bigint): Uint8Array =>
typeof value === "bigint"
? bytes.encode(bignum.encode(value))
: new TextEncoder().encode(value),
encode: (value: string): Uint8Array => new TextEncoder().encode(value),
decode: (value: Uint8Array): string => new TextDecoder().decode(value),
equals: (lhs: Uint8Array, rhs: Uint8Array): boolean =>
lhs.length === rhs.length && lhs.every((v, i) => v === rhs[i]),
Expand Down
15 changes: 7 additions & 8 deletions examples/src/algoTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import "@wormhole-foundation/connect-sdk-solana-tokenbridge";
const wh = new Wormhole("Testnet", [AlgorandPlatform, SolanaPlatform, EvmPlatform]);

// Grab chain Contexts -- these hold a reference to a cached rpc client
const sendChain = wh.getChain("Avalanche");
const rcvChain = wh.getChain("Algorand");
const sendChain = wh.getChain("Algorand");
const rcvChain = wh.getChain("Avalanche");

// shortcut to allow transferring native gas token
const token: TokenId | "native" = "native";
Expand Down Expand Up @@ -64,7 +64,7 @@ import "@wormhole-foundation/connect-sdk-solana-tokenbridge";

// Set this to the transfer txid of the initiating transaction to recover a token transfer
// and attempt to fetch details about its progress.
let recoverTxid = "0x191ffc4682aa0713d1010cff9fa5921c7941871cc9bd0ef431b7154d719825fa";
let recoverTxid = undefined;
// recoverTxid =
// "2daoPz9KyVkG8WGztfatMRx3EKbiRSUVGKAoCST9286eGrzXg5xowafBUUKfd3JrHzvd4AwoH57ujWaJ72k6oiCY";

Expand All @@ -87,12 +87,11 @@ import "@wormhole-foundation/connect-sdk-solana-tokenbridge";
txid: recoverTxid,
});

// Log out the results
console.log(xfer);

if (xfer.getTransferState() <= TransferState.DestinationInitiated) {
console.log(await xfer.completeTransfer(destination.signer));
}
// Log out the results
// if (xfer.getTransferState() <= TransferState.DestinationInitiated) {
// console.log(await xfer.completeTransfer(destination.signer));
// }
})();

async function tokenTransfer<N extends Network>(
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions platforms/algorand/__tests__/unit/address.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AlgorandAddress } from "../../src";

describe("Algorand Address Tests", () => {
describe("Parse Address", () => {
test("An address parses", () => {
let address = new AlgorandAddress(
"6XHBAFTDDSGTD4AOR67SLCCY7HAQGYBUWCVP2DYPIE7HI7G7IPNOEYM6XE",
);
expect(address).toBeTruthy();
});

test("An invalid address is rejected", () => {
expect(() => new AlgorandAddress("bogusybogusybogus")).toThrow();
});
});
});
17 changes: 17 additions & 0 deletions platforms/algorand/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { JestConfigWithTsJest } from "ts-jest";

const jestConfig: JestConfigWithTsJest = {
preset: "ts-jest",
verbose: true,
modulePathIgnorePatterns: ["mocks"],
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
isolatedModules: true,
},
],
},
};

export default jestConfig;
3 changes: 2 additions & 1 deletion platforms/algorand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"rebuild": "npm run clean && npm run build:cjs && npm run build:esm",
"clean": "rm -rf ./dist && rm -f ./*.tsbuildinfo",
"lint": "npm run prettier && eslint --fix",
"prettier": "prettier --write ./src"
"prettier": "prettier --write ./src",
"test": "jest --config ./jest.config.ts"
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.5",
Expand Down
3 changes: 2 additions & 1 deletion platforms/algorand/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"dependencies": {
"@wormhole-foundation/connect-sdk": "^0.3.0-beta.5",
"@wormhole-foundation/connect-sdk-algorand": "^0.3.0-beta.5"
"@wormhole-foundation/connect-sdk-algorand": "^0.3.0-beta.5",
"@wormhole-foundation/connect-sdk-algorand-core": "^0.3.0-beta.5"
}
}
Loading

0 comments on commit 1862b5f

Please sign in to comment.