@pbgtoken/rwa-contract 1.0.2 → 1.0.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.
@@ -2,10 +2,184 @@ import type { IntLike } from "@helios-lang/codec-utils";
2
2
  import type { Cast, CastConfig, UserFunc } from "@helios-lang/contract-utils";
3
3
  import type { Address, AssetClass, MintingPolicyHash, PubKeyHash, ScriptHash, TxInput, TxOutputId } from "@helios-lang/ledger";
4
4
  import type { UplcData, UplcProgram } from "@helios-lang/uplc";
5
+ export declare const one_to_one_asset: {
6
+ $name: "one_to_one_asset";
7
+ $purpose: "mixed";
8
+ $currentScriptIndex: 0;
9
+ $sourceCode: string;
10
+ $dependencies: readonly [];
11
+ $hashDependencies: never[];
12
+ $dependsOnOwnHash: boolean;
13
+ $Redeemer: (config: CastConfig) => Cast<{
14
+ Other: {
15
+ redeemer: UplcData;
16
+ };
17
+ } | {
18
+ Spending: {
19
+ redeemer: UplcData;
20
+ };
21
+ }, {
22
+ Other: {
23
+ redeemer: UplcData;
24
+ };
25
+ } | {
26
+ Spending: {
27
+ redeemer: UplcData;
28
+ };
29
+ }>;
30
+ $Datum: (config: CastConfig) => Cast<UplcData, UplcData>;
31
+ $types: {
32
+ State: (config: CastConfig) => Cast<{
33
+ supply: bigint;
34
+ type: string;
35
+ account: number[];
36
+ name: string;
37
+ description: string;
38
+ decimals: bigint;
39
+ ticker: string;
40
+ url: string;
41
+ logo: string;
42
+ }, {
43
+ supply: IntLike;
44
+ type: string;
45
+ account: number[];
46
+ name: string;
47
+ description: string;
48
+ decimals: IntLike;
49
+ ticker: string;
50
+ url: string;
51
+ logo: string;
52
+ }>;
53
+ Cip68Extra: (config: CastConfig) => Cast<{
54
+ Unused: {};
55
+ }, {
56
+ Unused: {};
57
+ }>;
58
+ Metadata: (config: CastConfig) => Cast<{
59
+ Cip68: {
60
+ state: {
61
+ supply: bigint;
62
+ type: string;
63
+ account: number[];
64
+ name: string;
65
+ description: string;
66
+ decimals: bigint;
67
+ ticker: string;
68
+ url: string;
69
+ logo: string;
70
+ };
71
+ version: bigint;
72
+ extra: {
73
+ Unused: {};
74
+ };
75
+ };
76
+ }, {
77
+ Cip68: {
78
+ state: {
79
+ supply: IntLike;
80
+ type: string;
81
+ account: number[];
82
+ name: string;
83
+ description: string;
84
+ decimals: IntLike;
85
+ ticker: string;
86
+ url: string;
87
+ logo: string;
88
+ };
89
+ version: IntLike;
90
+ extra: {
91
+ Unused: {};
92
+ };
93
+ };
94
+ }>;
95
+ Redeemer: (config: CastConfig) => Cast<{
96
+ reserves: bigint;
97
+ }, {
98
+ reserves: IntLike;
99
+ }>;
100
+ };
101
+ $functions: {
102
+ "Metadata::state": (uplc: UplcProgram, config: CastConfig) => UserFunc<{
103
+ self: {
104
+ Cip68: {
105
+ state: {
106
+ supply: IntLike;
107
+ type: string;
108
+ account: number[];
109
+ name: string;
110
+ description: string;
111
+ decimals: IntLike;
112
+ ticker: string;
113
+ url: string;
114
+ logo: string;
115
+ };
116
+ version: IntLike;
117
+ extra: {
118
+ Unused: {};
119
+ };
120
+ };
121
+ };
122
+ }, {
123
+ supply: bigint;
124
+ type: string;
125
+ account: number[];
126
+ name: string;
127
+ description: string;
128
+ decimals: bigint;
129
+ ticker: string;
130
+ url: string;
131
+ logo: string;
132
+ }>;
133
+ SEED_ID: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, TxOutputId>;
134
+ ORACLE_KEYS: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, PubKeyHash[]>;
135
+ TYPE: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
136
+ ACCOUNT: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, number[]>;
137
+ TICKER: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
138
+ NAME: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
139
+ DESCRIPTION: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
140
+ DECIMALS: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, bigint>;
141
+ URL: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
142
+ LOGO: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, string>;
143
+ ticker_bytes: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, number[]>;
144
+ user_token_name: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, number[]>;
145
+ ref_token_name: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, number[]>;
146
+ own_hash: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, ScriptHash>;
147
+ own_mph: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, MintingPolicyHash>;
148
+ own_address: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, Address>;
149
+ ref_token_asset_class: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, AssetClass>;
150
+ user_token_asset_class: (uplc: UplcProgram, config: CastConfig) => UserFunc<{}, AssetClass>;
151
+ validate_initialization: (uplc: UplcProgram, config: CastConfig) => UserFunc<{
152
+ $scriptContext: UplcData;
153
+ }, void>;
154
+ signed_by_quorum: (uplc: UplcProgram, config: CastConfig) => UserFunc<{
155
+ $scriptContext: UplcData;
156
+ }, boolean>;
157
+ validate_state_change: (uplc: UplcProgram, config: CastConfig) => UserFunc<{
158
+ $scriptContext: UplcData;
159
+ redeemer: {
160
+ reserves: IntLike;
161
+ };
162
+ input: TxInput;
163
+ }, void>;
164
+ main: (uplc: UplcProgram, config: CastConfig) => UserFunc<{
165
+ $scriptContext: UplcData;
166
+ $datum?: UplcData;
167
+ args: {
168
+ Other: {
169
+ redeemer: UplcData;
170
+ };
171
+ } | {
172
+ Spending: {
173
+ redeemer: UplcData;
174
+ };
175
+ };
176
+ }, void>;
177
+ };
178
+ };
5
179
  export declare const tokenized_account: {
6
180
  $name: "tokenized_account";
7
181
  $purpose: "mixed";
8
- $currentScriptIndex: 0;
182
+ $currentScriptIndex: 1;
9
183
  $sourceCode: string;
10
184
  $dependencies: readonly [];
11
185
  $hashDependencies: never[];
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ const { createDefaultPreset } = require("ts-jest");
2
+
3
+ const tsJestTransformCfg = createDefaultPreset().transform;
4
+
5
+ /** @type {import("jest").Config} **/
6
+ module.exports = {
7
+ testEnvironment: "node",
8
+ transform: {
9
+ ...tsJestTransformCfg,
10
+ },
11
+ testMatch: ["**/tests/**/*.test.ts"],
12
+ };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@pbgtoken/rwa-contract",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
6
  "type": "module",
7
+ "types": "./dist/index.d.ts",
8
8
  "license": "AGPL-version-3.0",
9
9
  "private": false,
10
10
  "engines": {
@@ -24,6 +24,7 @@
24
24
  "url": "https://github.com/christianschmitz"
25
25
  },
26
26
  "scripts": {
27
+ "test": "jest",
27
28
  "build": "npm run build:validators && npm run build:types && npm run build:bundle",
28
29
  "build:bundle": "node ./esbuild.js",
29
30
  "build:types": "npx tsc --declaration --emitDeclarationOnly",
@@ -37,6 +38,12 @@
37
38
  "@helios-lang/tx-utils": "^0.6.13",
38
39
  "@helios-lang/type-utils": "^0.3.0",
39
40
  "esbuild": "^0.25.4",
41
+ "ethers": "^6.14.1",
40
42
  "typescript": "^5.8.3"
43
+ },
44
+ "devDependencies": {
45
+ "@types/jest": "^29.5.14",
46
+ "jest": "^29.7.0",
47
+ "ts-jest": "^29.3.4"
41
48
  }
42
49
  }
@@ -0,0 +1,25 @@
1
+ import { makeBSCAccountProvider } from "../src/BSCAccountProvider";
2
+ import { makeCoinGeckoProvider } from "../src/CoinGeckoProvider";
3
+ import { TEST_DATA } from "./const";
4
+
5
+ const priceProvider = makeCoinGeckoProvider();
6
+
7
+ describe("BSCAccountProvider", () => {
8
+ const provider = makeBSCAccountProvider(TEST_DATA.bnbAddress, priceProvider, TEST_DATA.alchemyApiKey);
9
+
10
+ test("should return balance as a number", async () => {
11
+ const balance = await provider.balance;
12
+ expect(typeof balance).toBe("number");
13
+ });
14
+
15
+ test("should return transfer history as array", async () => {
16
+ const transfers = await provider.transferHistory;
17
+ expect(Array.isArray(transfers)).toBe(true);
18
+ });
19
+
20
+ test("should calculate deposits in USD from transfer IDs", async () => {
21
+ const transfers = await provider.transferHistory;
22
+ const depositUsd = await provider.deposits(transfers);
23
+ expect(typeof depositUsd).toBe("number");
24
+ });
25
+ });
@@ -0,0 +1,26 @@
1
+ import { makeBinanceAccountProvider } from "../src/BinanceAccountProvider";
2
+ import { makeCoinGeckoProvider } from "../src/CoinGeckoProvider";
3
+ import { TEST_DATA } from "./const";
4
+
5
+ const priceProvider = makeCoinGeckoProvider();
6
+
7
+ describe("BinanceAccountProvider", () => {
8
+ const provider = makeBinanceAccountProvider(TEST_DATA.binanceApiKey, priceProvider);
9
+
10
+ test("should return a USD balance", async () => {
11
+ const usdBalance = await provider.balance;
12
+ expect(typeof usdBalance).toBe("number");
13
+ expect(usdBalance).toBeGreaterThanOrEqual(0);
14
+ });
15
+
16
+ test("should return an array of transfer history", async () => {
17
+ const transfers = await provider.transferHistory;
18
+ expect(Array.isArray(transfers)).toBe(true);
19
+ });
20
+
21
+ test("should calculate deposits in USD from transfer IDs", async () => {
22
+ const transfers = await provider.transferHistory;
23
+ const depositUsd = await provider.deposits(transfers);
24
+ expect(typeof depositUsd).toBe("number");
25
+ });
26
+ });
@@ -0,0 +1,28 @@
1
+ import { makeBitcoinWalletProvider } from "../src/BitcoinWalletProvider";
2
+ import { makeCoinGeckoProvider } from "../src/CoinGeckoProvider";
3
+ import { TEST_DATA } from "./const";
4
+
5
+ const priceProvider = makeCoinGeckoProvider();
6
+
7
+ describe("BitcoinWalletProvider", () => {
8
+ const provider = makeBitcoinWalletProvider(TEST_DATA.btcAddress, priceProvider);
9
+
10
+ test("should return a valid Sats balance", async () => {
11
+ const sats = await provider.getSats();
12
+ expect(typeof sats).toBe("number");
13
+ console.log(sats)
14
+ expect(sats).toBeGreaterThanOrEqual(0);
15
+ });
16
+
17
+ test("should return an array for transfer history", async () => {
18
+ const transfers = await provider.transferHistory;
19
+ console.log(transfers)
20
+ expect(Array.isArray(transfers)).toBe(true);
21
+ });
22
+
23
+ test("should calculate USD deposits correctly", async () => {
24
+ const transfers = await provider.transferHistory;
25
+ const deposits = await provider.deposits(transfers);
26
+ expect(typeof deposits).toBe("number");
27
+ });
28
+ });
@@ -0,0 +1,25 @@
1
+ import { makeEthereumERC20AccountProvider } from "../src/EthereumERC20AccountProvider";
2
+ import { makeCoinGeckoProvider } from "../src/CoinGeckoProvider";
3
+ import { TEST_DATA } from "./const";
4
+
5
+ const priceProvider = makeCoinGeckoProvider();
6
+
7
+ describe("EthereumERC20AccountProvider", () => {
8
+ const provider = makeEthereumERC20AccountProvider(TEST_DATA.ethAddress, priceProvider, TEST_DATA.alchemyApiKey, TEST_DATA.usdtContract);
9
+
10
+ test("should return balance as a number", async () => {
11
+ const balance = await provider.balance;
12
+ expect(typeof balance).toBe("number");
13
+ });
14
+
15
+ test("should return transfer history as array", async () => {
16
+ const transfers = await provider.transferHistory;
17
+ expect(Array.isArray(transfers)).toBe(true);
18
+ });
19
+
20
+ test("should calculate deposits in USD from transfer IDs", async () => {
21
+ const transfers = await provider.transferHistory;
22
+ const depositUsd = await provider.deposits(transfers);
23
+ expect(typeof depositUsd).toBe("number");
24
+ });
25
+ });
package/tests/const.ts ADDED
@@ -0,0 +1,16 @@
1
+ export const TEST_DATA = {
2
+ // Ethereum ERC-20
3
+ ethAddress: "0xd31F13827c798d8f457313C2A7bA5f764e4842D8",
4
+ usdtContract: "0xdAC17F958D2ee523a2206206994597C13D831ec7" as `0x${string}`, // USDT contract on Ethereum
5
+ infuraRpc: process.env.INFURA_RPC_URL || "https://1rpc.io/eth",
6
+ alchemyApiKey: process.env.ALCHEMY_API_KEY || "",
7
+
8
+ // Binance Smart Chain
9
+ bnbAddress: "0xd31f13827c798d8f457313c2a7ba5f764e4842d8",
10
+
11
+ // Bitcoin
12
+ btcAddress: "bc1q23ztqjmh9a32z8j4rstg035y3c3vpfe0la3nck",
13
+
14
+ // Binance Account API
15
+ binanceApiKey: process.env.BINANCE_API_KEY || "",
16
+ }