├── js
├── .gitignore
├── print_tx.js
├── create_atas.sh
├── print_ata.js
├── print_subscr.js
├── package.json
├── print_key.js
├── check_key.js
├── print_root.js
├── activate.js
├── print_drop.js
├── close_allowance.js
├── date.js
├── close_subscr.js
├── info.js
├── store_metadata.js
├── prev
│ ├── fund_swap_token.js
│ └── subscribe_swap_create.js
├── allowance.js
├── merchant_receive.js
├── merchant_payment.js
├── merchant_payment_swap.js
├── update_subscr.js
├── update_subscr_swap.js
├── subscribe.js
└── subscribe_swap.js
├── Cargo.toml
├── .gitignore
├── programs
└── token-agent
│ ├── Xargo.toml
│ └── Cargo.toml
├── Anchor.toml
├── tests
├── subscribe.js
└── token-agent.js
├── migrations
└── deploy.js
├── README.md
└── Cargo.lock
/js/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [workspace]
2 | members = [
3 | "programs/*"
4 | ]
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .anchor
2 | .DS_Store
3 | target
4 | **/*.rs.bk
5 | *.swp
6 | *.swo
7 | node_modules/*
8 |
--------------------------------------------------------------------------------
/programs/token-agent/Xargo.toml:
--------------------------------------------------------------------------------
1 | [target.bpfel-unknown-unknown.dependencies.std]
2 | features = []
3 |
--------------------------------------------------------------------------------
/Anchor.toml:
--------------------------------------------------------------------------------
1 | [registry]
2 | url = "https://anchor.projectserum.com"
3 |
4 | [provider]
5 | cluster = "devnet"
6 | wallet = "/Users/mfrager/.config/solana/id.json"
7 |
8 | [scripts]
9 | test = "mocha -t 1000000 tests/"
10 |
--------------------------------------------------------------------------------
/js/print_tx.js:
--------------------------------------------------------------------------------
1 | const anchor = require('@project-serum/anchor')
2 | const provider = anchor.Provider.env()
3 | anchor.setProvider(provider)
4 |
5 | async function main() {
6 | let sig = process.argv[2]
7 | let pt = await provider.connection.getParsedTransaction(sig, 'confirmed')
8 | console.log(pt)
9 | }
10 |
11 | main()
12 |
--------------------------------------------------------------------------------
/js/create_atas.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ROOT=/Users/mfrager/Build/solana/data
4 |
5 | KEY_TOKEN_USDV=$ROOT/export/key-usdv-token-1.json
6 |
7 | TOKEN_USDV=$(solana-keygen pubkey $KEY_TOKEN_USDV)
8 | TOKEN_AGENT_ROOT=$(node print_root.js)
9 |
10 | # Token Agent / USDV
11 | echo 'ATA: Token Agent USDV'
12 | spl-token create-account $TOKEN_USDV --owner $TOKEN_AGENT_ROOT
13 |
--------------------------------------------------------------------------------
/js/print_ata.js:
--------------------------------------------------------------------------------
1 | const { PublicKey } = require('@solana/web3.js')
2 | const { associatedTokenAddress } = require('../../js/atellix-common')
3 |
4 | async function main() {
5 | let mint = new PublicKey(process.argv[2])
6 | let owner = new PublicKey(process.argv[3])
7 | let ata = await associatedTokenAddress(owner, mint)
8 | console.log(ata.pubkey)
9 | }
10 |
11 | main()
12 |
--------------------------------------------------------------------------------
/tests/subscribe.js:
--------------------------------------------------------------------------------
1 | const anchor = require('@project-serum/anchor');
2 |
3 | describe('token-agent', () => {
4 |
5 | // Configure the client to use the local cluster.
6 | anchor.setProvider(anchor.Provider.env());
7 |
8 | it('Is initialized!', async () => {
9 | // Add your test here.
10 | const program = anchor.workspace.TokenAgent;
11 | const tx = await program.rpc.initialize();
12 | console.log("Your transaction signature", tx);
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/migrations/deploy.js:
--------------------------------------------------------------------------------
1 |
2 | // Migrations are an early feature. Currently, they're nothing more than this
3 | // single deploy script that's invoked from the CLI, injecting a provider
4 | // configured from the workspace's Anchor.toml.
5 |
6 | const anchor = require("@project-serum/anchor");
7 |
8 | module.exports = async function (provider) {
9 | // Configure client to use the provider.
10 | anchor.setProvider(provider);
11 |
12 | // Add your deploy script here.
13 | }
14 |
--------------------------------------------------------------------------------
/tests/token-agent.js:
--------------------------------------------------------------------------------
1 | const anchor = require('@project-serum/anchor');
2 |
3 | describe('token-agent', () => {
4 |
5 | // Configure the client to use the local cluster.
6 | anchor.setProvider(anchor.Provider.env());
7 |
8 | it('Is initialized!', async () => {
9 | // Add your test here.
10 | const program = anchor.workspace.TokenAgent;
11 | const tx = await program.rpc.initialize();
12 | console.log("Your transaction signature", tx);
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/js/print_subscr.js:
--------------------------------------------------------------------------------
1 | const { PublicKey } = require('@solana/web3.js')
2 | const anchor = require('@project-serum/anchor')
3 | const provider = anchor.AnchorProvider.env()
4 | anchor.setProvider(provider)
5 |
6 | const tokenAgent = anchor.workspace.TokenAgent
7 |
8 | async function main() {
9 | var subscrData = new PublicKey('4xFJN6iE7wAfc57aZ7iqVr88aqo1c6nvTdXZrjz7Yujj')
10 | var act = await tokenAgent.account.subscrData.fetch(subscrData)
11 | console.log(act)
12 | }
13 |
14 | main()
15 |
--------------------------------------------------------------------------------
/js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "token-agent-test-clients",
3 | "version": "1.0.0",
4 | "description": "Test clients for token-agent Solana program",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "@project-serum/anchor": "^0.24.2",
13 | "@solana/spl-token": "^0.1.8",
14 | "base32.js": "^0.1.0",
15 | "bs58": "^5.0.0",
16 | "luxon": "^2.0.2",
17 | "moment-strftime": "^0.5.0",
18 | "uuid": "^8.3.2"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/js/print_key.js:
--------------------------------------------------------------------------------
1 | /*const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")*/
8 | const bs58 = require('bs58')
9 |
10 | const anchor = require('@project-serum/anchor')
11 | const provider = anchor.Provider.env()
12 | //const provider = anchor.Provider.local()
13 | anchor.setProvider(provider)
14 | //console.log(tokenAgent)
15 |
16 |
17 | async function main() {
18 | let k = provider.wallet.payer.secretKey
19 | console.log(k)
20 | console.log(bs58.encode(k))
21 | }
22 |
23 | main().then(() => process.exit(0)).catch(error => {
24 | console.log(error)
25 | })
26 |
--------------------------------------------------------------------------------
/programs/token-agent/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "token-agent"
3 | version = "0.1.0"
4 | description = "Created with Anchor"
5 | edition = "2018"
6 |
7 | [lib]
8 | crate-type = ["cdylib", "lib"]
9 | name = "token_agent"
10 |
11 | [features]
12 | no-entrypoint = []
13 | no-idl = []
14 | no-log-ix-name = []
15 | cpi = ["no-entrypoint"]
16 | default = ["no-log-ix-name"]
17 |
18 | [dependencies]
19 | spl-associated-token-account = "1.0.5"
20 | anchor-lang = "0.25.0"
21 | anchor-spl = "0.25.0"
22 | solana-program = "1.10.29"
23 | num_enum = "0.5.4"
24 | bytemuck = "1.7.2"
25 | arrayref = "0.3.6"
26 | chrono = { version = "0.4.19", features = ["alloc"], default-features = false }
27 | net-authority = { version = "0.1.0", path = "/Users/mfrager/Build/solana/net-authority/programs/net-authority", features = ["cpi"] }
28 | swap-contract = { version = "0.1.0", path = "/Users/mfrager/Build/solana/swap-contract/programs/swap-contract", features = ["cpi"] }
29 | token-delegate = { version = "1.0.0", path = "/Users/mfrager/Build/solana/token-delegate/programs/token-delegate", features = ["cpi"] }
30 |
--------------------------------------------------------------------------------
/js/check_key.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 |
14 | function importSecretKey(keyStr) {
15 | var dec = new base32.Decoder({ type: "crockford" })
16 | var spec = dec.write(keyStr).finalize()
17 | return Keypair.fromSecretKey(new Uint8Array(spec))
18 | }
19 |
20 | async function main() {
21 | var root = importSecretKey('q116ksdz3f4gt7ed10jfmern8r7sj9bqnqqfvc6j1xq72zxgz9be2ptr58n5z1rtktjz2gx1sj0xfxjkjgh70ajyxnjc7fh9v3tfh7r')
22 | console.log(root.publicKey.toString())
23 | }
24 |
25 | main().then(() => process.exit(0)).catch(error => {
26 | console.log(error)
27 | })
28 |
--------------------------------------------------------------------------------
/js/print_root.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | async function programAddress(inputs, program) {
18 | const addr = await PublicKey.findProgramAddress(inputs, program)
19 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
20 | return res
21 | }
22 |
23 |
24 | async function main() {
25 | var root = await programAddress([tokenAgentPK.toBuffer()], tokenAgentPK)
26 | console.log(root.pubkey)
27 | }
28 |
29 | main().then(() => process.exit(0)).catch(error => {
30 | console.log(error)
31 | })
32 |
--------------------------------------------------------------------------------
/js/activate.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require('luxon')
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const { promisify } = require('util')
7 | const exec = promisify(require('child_process').exec)
8 | const fs = require('fs').promises
9 | const base32 = require("base32.js")
10 | const anchor = require('@project-serum/anchor')
11 | const { associatedTokenAddress, programAddress, exportSecretKey, jsonFileRead, jsonFileWrite } = require('../../js/atellix-common')
12 |
13 | const provider = anchor.Provider.env()
14 | //const provider = anchor.Provider.local()
15 | anchor.setProvider(provider)
16 | const tokenAgent = anchor.workspace.TokenAgent
17 | const tokenAgentPK = tokenAgent.programId
18 |
19 | async function main() {
20 | const netData = await jsonFileRead('../../data/net.json')
21 | netData['tokenAgentProgram'] = tokenAgentPK.toString()
22 | await jsonFileWrite('../../data/net.json', netData)
23 | }
24 |
25 | console.log('Begin')
26 | main().then(() => console.log('Success')).catch(error => {
27 | console.log(error)
28 | })
29 |
--------------------------------------------------------------------------------
/js/print_drop.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | async function programAddress(inputs, program) {
18 | const addr = await PublicKey.findProgramAddress(inputs, program)
19 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
20 | return res
21 | }
22 |
23 | async function main() {
24 | var merchantPK = new PublicKey('2cxhShPFPqqPyZngmLEoujX173J6JT1gSHd9wvpATV5r')
25 | var drop = await programAddress([merchantPK.toBuffer()], tokenAgentPK)
26 | console.log('Merchant Drop: ' + drop.pubkey)
27 | }
28 |
29 | console.log('Begin')
30 | main().then(() => console.log('Success')).catch(error => {
31 | console.log(error)
32 | })
33 |
--------------------------------------------------------------------------------
/js/close_allowance.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | async function main() {
18 | const allowanceData = new PublicKey('25NNEHFiEpRL7JosvruvXYH8Supgd8iuKtfhyEdP62YQ')
19 |
20 | /*var act = await tokenAgent.account.tokenAllowance.fetch(allowanceData)
21 | console.log('Initial Allowance Data')
22 | console.log(act)*/
23 |
24 | console.log('Close Allowance')
25 | let txsig = await tokenAgent.rpc.closeAllowance(
26 | {
27 | accounts: {
28 | allowanceData: allowanceData,
29 | userKey: provider.wallet.publicKey,
30 | feeRecipient: provider.wallet.publicKey,
31 | },
32 | }
33 | )
34 | console.log(txsig)
35 | }
36 |
37 | console.log('Begin')
38 | main().then(() => console.log('Success')).catch(error => {
39 | console.log(error)
40 | })
41 |
--------------------------------------------------------------------------------
/js/date.js:
--------------------------------------------------------------------------------
1 | const { DateTime } = require("luxon")
2 | var dt0 = DateTime.now().setZone('utc')
3 |
4 | console.log('ISO')
5 | console.log(dt0.toISO())
6 |
7 | console.log('Day')
8 | console.log(dt0.toFormat('yyyyLLdd'))
9 | var dt1 = DateTime.fromSeconds(Math.floor(dt0.toSeconds())).setZone('utc')
10 | console.log(dt1.minus({ hours: dt1.hour, minutes: dt1.minute, seconds: dt1.second }).toISO())
11 |
12 | console.log('Week')
13 | console.log(dt0.toFormat("yyyy'w'WW"))
14 | var dt2 = DateTime.fromSeconds(Math.floor(dt0.toSeconds())).setZone('utc')
15 | dt2 = dt2.minus({ days: dt2.weekday - 1, hours: dt2.hour, minutes: dt2.minute, seconds: dt2.second })
16 | console.log(dt2.toISO() + ' w' + dt2.toFormat('WW'))
17 |
18 | console.log('Month')
19 | console.log(dt0.toFormat('yyyyLL'))
20 | var dt3 = DateTime.fromSeconds(Math.floor(dt0.toSeconds())).setZone('utc')
21 | console.log(dt3.minus({ days: dt3.day - 1, hours: dt3.hour, minutes: dt3.minute, seconds: dt3.second }).toISO())
22 |
23 | console.log('Quarter')
24 | console.log(dt0.toFormat('yyyy') + 'q' + dt0.quarter)
25 | var dt4 = DateTime.fromObject({year: dt0.year, month: ((dt0.quarter - 1) * 3) + 1, day: 1, hour: 0, minute: 0, second: 0}).setZone('utc')
26 | console.log(dt4.toISO() + ' q' + dt4.quarter)
27 |
28 | console.log('Year')
29 | console.log(dt0.toFormat('yyyy'))
30 | var dt5 = DateTime.fromSeconds(Math.floor(dt0.toSeconds())).setZone('utc')
31 | console.log(dt5.minus({ months: dt5.month - 1, days: dt5.day - 1, hours: dt5.hour, minutes: dt5.minute, seconds: dt5.second }).toISO())
32 |
33 |
--------------------------------------------------------------------------------
/js/close_subscr.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | async function main() {
18 | const subscrData = new PublicKey('9SmeJPYfufJyGbJQvvLmkEPnDmF5QAA5JqQ79Ltcnf92')
19 |
20 | var act = await tokenAgent.account.subscrData.fetch(subscrData)
21 | console.log('Initial Subscription Data')
22 | console.log(act)
23 |
24 | console.log('Close Subscription')
25 | let txsig = await tokenAgent.rpc.closeSubscription(
26 | {
27 | accounts: {
28 | //subscrData: new PublicKey('Fxg4sFxmiWFPaxS7Xtgnk4J83grzcky9ZpMd6GyutEPd'),
29 | subscrData: subscrData,
30 | userKey: provider.wallet.publicKey,
31 | feeRecipient: provider.wallet.publicKey,
32 | },
33 | }
34 | )
35 | console.log(txsig)
36 | }
37 |
38 | console.log('Begin')
39 | main().then(() => console.log('Success')).catch(error => {
40 | console.log(error)
41 | })
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 | ## About This Program
14 |
15 | The Token Agent program manages recurring subscriptions (a.k.a. "rebilling") and delegation of tokens to specific accounts.
16 |
17 | Note: This program requires the "userAgent" account for each user be registered to the SPL token as the delegate in order to facilitate the later transfer of tokens on the user's behalf. For this reason, we recommend that other programs leave this setting in place. This Token Agent program provides a way to re-delegate token allowances to any number of accounts via a "TokenAllowance".
18 |
19 | Recurring Subscriptions Features:
20 | * Automatic token swapping (pay in one token, merchant gets a different token swapped at current prices).
21 | * No double-billing
22 | * Max budget
23 | * Dynamic payment amount
24 | * Ability to update subscription parameters
25 | * User able to cancel subscription(s) directly
26 |
27 | Features:
28 | * Recurring subscriptions
29 | * Delegate allowances to any number of accounts
30 |
31 | This contract also adds the ability to create "TokenAllowance" accounts. The allowances enable a specific number of tokens to be delegated to be transfer later by a specific 3rd-party user. This program also include more fined-grained access controls than the SPL Token program, including time-based access, and limiting the recipient to a pre-defined account.
32 |
33 | ### Built With
34 |
35 | * Rust
36 | * Javascript
37 | * [Anchor](https://project-serum.github.io/anchor/getting-started/introduction.html)
38 |
39 |
40 | ## License
41 |
42 | Distributed under the MIT License.
43 |
--------------------------------------------------------------------------------
/js/info.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs) {
28 | const addr = await PublicKey.findProgramAddress(inputs, tokenAgentPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var act = await tokenAgent.account.subscrData.fetch(new PublicKey('2C3DzW6SBAQ4U7SRRe6g51j2Lbpt3GY4Byef9BeoF7LT'))
41 | console.log('User Key: ' + act.userKey.toString())
42 | console.log('User Agent: ' + act.userAgent.toString())
43 | console.log('Budget: ' + act.budget.toString())
44 | console.log(act)
45 | }
46 |
47 | console.log('Begin')
48 | main().then(() => console.log('Success')).catch(error => {
49 | console.log(error)
50 | })
51 |
--------------------------------------------------------------------------------
/js/store_metadata.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const { promisify } = require('util')
7 | const exec = promisify(require('child_process').exec)
8 | const fs = require('fs').promises
9 | const base32 = require("base32.js")
10 | const anchor = require('@project-serum/anchor')
11 | const { associatedTokenAddress, programAddress, exportSecretKey, jsonFileRead, jsonFileWrite } = require('../../js/atellix-common')
12 |
13 | const provider = anchor.Provider.env()
14 | //const provider = anchor.Provider.local()
15 | anchor.setProvider(provider)
16 | const tokenAgent = anchor.workspace.TokenAgent
17 | const tokenAgentPK = tokenAgent.programId
18 |
19 | async function main() {
20 | var jsres = await exec('solana program show --output json ' + tokenAgentPK.toString())
21 | var res = JSON.parse(jsres.stdout)
22 | const programData = res.programdataAddress
23 |
24 | const infoData = await programAddress([tokenAgentPK.toBuffer(), Buffer.from('metadata', 'utf8')], tokenAgentPK)
25 | const infoBytes = 584
26 | const infoRent = await provider.connection.getMinimumBalanceForRentExemption(infoBytes)
27 | console.log('Program Metadata')
28 | console.log((new PublicKey(infoData.pubkey)).toString(), infoBytes, infoRent)
29 |
30 | console.log('Create Metadata')
31 | await tokenAgent.rpc.storeMetadata(
32 | "Token Agent",
33 | "Atellix Network",
34 | "https://atellix.network/",
35 | "https://github.com/atellix/token-agent",
36 | "",
37 | {
38 | accounts: {
39 | program: tokenAgentPK,
40 | programAdmin: provider.wallet.publicKey,
41 | programData: new PublicKey(programData),
42 | programInfo: new PublicKey(infoData.pubkey),
43 | systemProgram: SystemProgram.programId
44 | }
45 | }
46 | )
47 | }
48 |
49 | console.log('Begin')
50 | main().then(() => console.log('Success')).catch(error => {
51 | console.log(error)
52 | })
53 |
--------------------------------------------------------------------------------
/js/prev/fund_swap_token.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | //console.log(netData)
48 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
49 |
50 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
51 | const agentToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint)
52 | const tokenAccount = new PublicKey(agentToken.pubkey)
53 |
54 | console.log('Fund Token: Token Agent PDA (USDV)')
55 | await tokenAgent.rpc.fundToken(
56 | agentToken.nonce,
57 | {
58 | accounts: {
59 | ascTokenAccount: SPL_ASSOCIATED_TOKEN,
60 | },
61 | remainingAccounts: [
62 | { pubkey: provider.wallet.publicKey, isWritable: true, isSigner: true },
63 | { pubkey: tokenMint, isWritable: false, isSigner: false },
64 | { pubkey: new PublicKey(rootKey.pubkey), isWritable: false, isSigner: false },
65 | { pubkey: tokenAccount, isWritable: true, isSigner: false },
66 | { pubkey: TOKEN_PROGRAM_ID, isWritable: false, isSigner: false },
67 | { pubkey: SystemProgram.programId, isWritable: false, isSigner: false },
68 | { pubkey: SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
69 | ]
70 | }
71 | )
72 | }
73 |
74 | console.log('Begin')
75 | main().then(() => console.log('Success')).catch(error => {
76 | console.log(error)
77 | })
78 |
--------------------------------------------------------------------------------
/js/allowance.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const base32 = require("base32.js")
7 | const { importSecretKey, exportSecretKey } = require('../../js/atellix-common')
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs) {
28 | const addr = await PublicKey.findProgramAddress(inputs, tokenAgentPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | async function main() {
34 | const tokenAccount = new PublicKey('AL95HoRjCnaWm2R8GFWoCdoFaPTDCqt7yrxQ69z4DCMD')
35 | const tokenRecipient = new PublicKey('ABNZWLmf3BZnKVfU7pzJnfCrWVQcJvGZG85feF7E19L3')
36 |
37 | var managerPK
38 | if (false) {
39 | managerPK = anchor.web3.Keypair.generate()
40 | } else {
41 | managerPK = importSecretKey('3h9y0bjxfj204gsf5rr9913hpkvwyvreatp65tc89mb7p7cm7wk250d9k60p3q9jgv65azenq853wfp1zztccbr5h4jyc97d7g13138')
42 | }
43 |
44 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
45 | let allowanceSpec = [
46 | tokenAccount.toBuffer(),
47 | managerPK.publicKey.toBuffer(),
48 | ]
49 | const userAllowance = await programAddress(allowanceSpec)
50 | console.log('User Allowance: ' + userAllowance['pubkey'])
51 | console.log('Manager Public Key: ' + managerPK.publicKey.toString())
52 |
53 | if (false) {
54 | console.log('Create Allowance')
55 | let tx = new anchor.web3.Transaction()
56 | tx.add(tokenAgent.transaction.createAllowance(
57 | true, // Link token
58 | rootKey.nonce, // Root key nonce
59 | userAllowance.nonce, // Allowance nonce
60 | new anchor.BN(100 * 10000), // Amount
61 | new anchor.BN(0), // Start time, or 0 for none
62 | new anchor.BN(0), // Expire time, or 0 for none
63 | {
64 | accounts: {
65 | allowanceData: new PublicKey(userAllowance.pubkey),
66 | userKey: provider.wallet.publicKey,
67 | rootKey: new PublicKey(rootKey.pubkey),
68 | delegateKey: managerPK.publicKey,
69 | tokenAccount: tokenAccount,
70 | tokenProgram: TOKEN_PROGRAM_ID,
71 | systemProgram: SystemProgram.programId,
72 | },
73 | //remainingAccounts: [],
74 | }
75 | ))
76 | console.log(tx)
77 | console.log(await provider.send(tx))
78 | }
79 | if (false) {
80 | console.log('Perform Delegated Transfer')
81 | console.log(await tokenAgent.rpc.delegatedTransfer(
82 | rootKey.nonce, // Root key nonce
83 | userAllowance.nonce, // Allowance nonce
84 | new anchor.BN(50 * 10000), // Amount
85 | {
86 | signers: [managerPK],
87 | accounts: {
88 | allowanceData: new PublicKey(userAllowance.pubkey),
89 | userKey: provider.wallet.publicKey,
90 | rootKey: new PublicKey(rootKey.pubkey),
91 | tokenAccount: tokenAccount, // From
92 | tokenRecipient: tokenRecipient, // To
93 | delegateKey: managerPK.publicKey,
94 | tokenProgram: TOKEN_PROGRAM_ID,
95 | },
96 | }
97 | ))
98 | }
99 | if (true) {
100 | console.log('Update Allowance')
101 | console.log(await tokenAgent.rpc.updateAllowance(
102 | true, // Link token
103 | rootKey.nonce, // Root key nonce
104 | userAllowance.nonce, // Allowance nonce
105 | new anchor.BN(10 * 10000), // Amount
106 | new anchor.BN(0), // Start time, or 0 for none
107 | new anchor.BN(0), // Expire time, or 0 for none
108 | {
109 | accounts: {
110 | allowanceData: new PublicKey(userAllowance.pubkey),
111 | userKey: provider.wallet.publicKey,
112 | rootKey: new PublicKey(rootKey.pubkey),
113 | delegateKey: managerPK.publicKey,
114 | tokenAccount: tokenAccount,
115 | tokenProgram: TOKEN_PROGRAM_ID,
116 | },
117 | }
118 | ))
119 | }
120 | if (true) {
121 | console.log('Perform Delegated Transfer 2')
122 | console.log(await tokenAgent.rpc.delegatedTransfer(
123 | rootKey.nonce, // Root key nonce
124 | userAllowance.nonce, // Allowance nonce
125 | new anchor.BN(30 * 10000), // Amount
126 | {
127 | signers: [managerPK],
128 | accounts: {
129 | allowanceData: new PublicKey(userAllowance.pubkey),
130 | userKey: provider.wallet.publicKey,
131 | rootKey: new PublicKey(rootKey.pubkey),
132 | tokenAccount: tokenAccount, // From
133 | tokenRecipient: tokenRecipient, // To
134 | delegateKey: managerPK.publicKey,
135 | tokenProgram: TOKEN_PROGRAM_ID,
136 | },
137 | }
138 | ))
139 | }
140 | }
141 |
142 | console.log('Begin')
143 | main().then(() => console.log('Success')).catch(error => {
144 | console.log(error)
145 | })
146 |
--------------------------------------------------------------------------------
/js/merchant_receive.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | //console.log(netData)
48 | const netAuth = new PublicKey(netData.netAuthorityProgram)
49 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
50 |
51 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
52 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
53 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
54 |
55 | const merchantPK = new PublicKey(netData.merchant1)
56 | const merchantAP = new PublicKey(netData.merchantApproval1)
57 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
58 | const merchantApprovalSK = importSecretKey(netData.merchantApproval1_secret)
59 | const feesPK = new PublicKey(netData.fees1)
60 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
61 |
62 | const merchantDrop = await associatedTokenAddress(merchantApprovalSK.publicKey, tokenMint)
63 | const tokenAccount = new PublicKey(merchantDrop.pubkey)
64 |
65 | console.log('Token Account Mint: ' + tokenMint.toString())
66 | console.log('Token Account Owner (1): ' + merchantApprovalSK.publicKey.toString())
67 | console.log('Token Account Owner (2): ' + merchantAP.toString())
68 | console.log('Token Account Assoc: ' + tokenAccount.toString())
69 |
70 | console.log('Merchant Account: ' + merchantPK.toString())
71 | console.log('Merchant Token: ' + merchantTK.pubkey)
72 |
73 | /* var spjs
74 | try {
75 | spjs = await fs.readFile('../../data/swap.json')
76 | } catch (error) {
77 | console.error('File Error: ', error)
78 | }
79 | const swapCache = JSON.parse(spjs.toString())
80 |
81 | var djs
82 | try {
83 | djs = await fs.readFile('../../data/swap-usdv-wsol.json')
84 | } catch (error) {
85 | console.error('File Error: ', error)
86 | }
87 | const swapSpec = JSON.parse(djs.toString())
88 |
89 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
90 | const tokenMint1 = new PublicKey(swapSpec.tokenMint1)
91 | const tokenMint2 = new PublicKey(swapSpec.tokenMint2)
92 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
93 | const swapDataPK = new PublicKey(swapSpec.swapData)
94 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
95 |
96 | const swapRootData = await programAddress([swapContractPK.toBuffer()], swapContractPK)
97 | const tkiData1 = await programAddress([tokenMint1.toBuffer()], swapContractPK)
98 | const tkiData2 = await programAddress([tokenMint2.toBuffer()], swapContractPK)
99 | const tokData1 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint1)
100 | const tokData2 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint2)
101 |
102 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
103 |
104 | console.log('User Token 1: ' + userToken1.pubkey)
105 | console.log('Payment Token: ' + tokenAccount.toString()) */
106 |
107 | var l1 = tokenAgent.addEventListener('PaymentEvent', (evt, slot) => {
108 | console.log('PaymentEvent - Slot: ' + slot)
109 | console.log(evt.eventHash.toString())
110 | console.log(evt)
111 | })
112 |
113 | const transactId = uuidv4()
114 | console.log('Merchant Receive: ' + transactId)
115 | let apires = await tokenAgent.rpc.merchantReceive(
116 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
117 | rootKey.nonce, // inp_root_nonce
118 | netRoot.nonce, // inp_net_nonce
119 | new anchor.BN(1234), // inp_payment_id
120 | new anchor.BN(2.5 * (10**4)), // inp_amount
121 | false, // inp_swap
122 | 0, // inp_swap_root_nonce
123 | 0, // inp_swap_inb_nonce
124 | 0, // inp_swap_out_nonce
125 | 0, // inp_swap_dst_nonce
126 | {
127 | accounts: {
128 | netAuth: netAuth,
129 | netRoot: new PublicKey(netRoot.pubkey),
130 | netRbac: netRBAC,
131 | rootKey: new PublicKey(rootKey.pubkey),
132 | merchantKey: merchantPK,
133 | merchantApproval: merchantAP,
134 | merchantToken: new PublicKey(merchantTK.pubkey),
135 | userKey: new PublicKey('HbZ5uaxfS7Xfs3HU4fssLo8TBG1ZB1mqnSFWKr325Mtd'),
136 | tokenProgram: TOKEN_PROGRAM_ID,
137 | tokenMint: tokenMint,
138 | tokenAccount: tokenAccount,
139 | feesAccount: new PublicKey(feesTK.pubkey),
140 | },
141 | signers: [merchantApprovalSK],
142 | }
143 | )
144 | console.log(apires)
145 | }
146 |
147 | console.log('Begin')
148 | main().then(() => console.log('Success')).catch(error => {
149 | console.log(error)
150 | })
151 |
--------------------------------------------------------------------------------
/js/merchant_payment.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | console.log(netData)
48 | const netAuth = new PublicKey(netData.netAuthorityProgram)
49 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
50 | const walletToken = await associatedTokenAddress(provider.wallet.publicKey, tokenMint)
51 | const tokenAccount = new PublicKey(walletToken.pubkey)
52 |
53 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
54 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
55 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
56 |
57 | const merchantAP = new PublicKey(netData.merchantApproval1)
58 | const merchantPK = new PublicKey(netData.merchant1_dest)
59 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
60 | const feesPK = new PublicKey(netData.fees1)
61 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
62 |
63 | console.log('Token Account Mint: ' + tokenMint.toString())
64 | console.log('Token Account Owner: ' + provider.wallet.publicKey.toString())
65 | console.log('Token Account Assoc: ' + tokenAccount.toString())
66 |
67 | console.log('Merchant Account: ' + merchantPK.toString())
68 | console.log('Merchant Token: ' + merchantTK.pubkey)
69 |
70 | /* var spjs
71 | try {
72 | spjs = await fs.readFile('../../data/swap.json')
73 | } catch (error) {
74 | console.error('File Error: ', error)
75 | }
76 | const swapCache = JSON.parse(spjs.toString())
77 |
78 | var djs
79 | try {
80 | djs = await fs.readFile('../../data/swap-usdv-wsol.json')
81 | } catch (error) {
82 | console.error('File Error: ', error)
83 | }
84 | const swapSpec = JSON.parse(djs.toString())
85 |
86 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
87 | const tokenMint1 = new PublicKey(swapSpec.tokenMint1)
88 | const tokenMint2 = new PublicKey(swapSpec.tokenMint2)
89 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
90 | const swapDataPK = new PublicKey(swapSpec.swapData)
91 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
92 |
93 | const swapRootData = await programAddress([swapContractPK.toBuffer()], swapContractPK)
94 | const tkiData1 = await programAddress([tokenMint1.toBuffer()], swapContractPK)
95 | const tkiData2 = await programAddress([tokenMint2.toBuffer()], swapContractPK)
96 | const tokData1 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint1)
97 | const tokData2 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint2)
98 |
99 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
100 |
101 | console.log('User Token 1: ' + userToken1.pubkey)
102 | console.log('Payment Token: ' + tokenAccount.toString()) */
103 |
104 | var l1 = tokenAgent.addEventListener('PaymentEvent', (evt, slot) => {
105 | console.log('PaymentEvent - Slot: ' + slot)
106 | console.log(evt.eventHash.toString())
107 | console.log(evt)
108 | })
109 |
110 | const transactId = uuidv4()
111 | console.log('Merchant Payment: ' + transactId)
112 | console.log({
113 | netAuth: netAuth.toString(),
114 | rootKey: new PublicKey(rootKey.pubkey).toString(),
115 | merchantApproval: merchantAP.toString(),
116 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
117 | userKey: provider.wallet.publicKey.toString(),
118 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
119 | tokenAccount: tokenAccount.toString(),
120 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
121 | })
122 | let apires = await tokenAgent.rpc.merchantPayment(
123 | merchantTK.nonce, // inp_dest_nonce (merchant associated token dest account nonce)
124 | rootKey.nonce, // inp_root_nonce
125 | new anchor.BN(1234), // inp_payment_id
126 | new anchor.BN(20 * (10**4)), // inp_amount
127 | false, // inp_swap
128 | false, // inp_swap_direction
129 | 0, // inp_swap_mode
130 | 0, // inp_swap_data_nonce
131 | 0, // inp_swap_inb_nonce
132 | 0, // inp_swap_out_nonce
133 | 0, // inp_swap_dst_nonce
134 | {
135 | accounts: {
136 | netAuth: netAuth,
137 | rootKey: new PublicKey(rootKey.pubkey),
138 | merchantApproval: merchantAP,
139 | merchantToken: new PublicKey(merchantTK.pubkey),
140 | userKey: provider.wallet.publicKey,
141 | tokenProgram: TOKEN_PROGRAM_ID,
142 | tokenAccount: tokenAccount,
143 | feesAccount: new PublicKey(feesTK.pubkey),
144 | },
145 | /*remainingAccounts: [
146 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
147 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
148 | { pubkey: new PublicKey(swapRootData.pubkey), isWritable: false, isSigner: false },
149 | { pubkey: swapAuthDataPK, isWritable: false, isSigner: false },
150 | { pubkey: provider.wallet.publicKey, isWritable: false, isSigner: true },
151 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
152 | { pubkey: new PublicKey(tkiData1.pubkey), isWritable: true, isSigner: false },
153 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
154 | { pubkey: new PublicKey(tkiData2.pubkey), isWritable: true, isSigner: false },
155 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
156 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
157 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
158 | ],*/
159 | }
160 | )
161 | console.log(apires)
162 | }
163 |
164 | console.log('Begin')
165 | main().then(() => console.log('Success')).catch(error => {
166 | console.log(error)
167 | })
168 |
--------------------------------------------------------------------------------
/js/merchant_payment_swap.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 |
48 | var swidl
49 | try {
50 | swidl = await fs.readFile('../../swap-contract/target/idl/swap_contract.json')
51 | } catch (error) {
52 | console.error('File Error: ', error)
53 | }
54 | const swapContractIDL = JSON.parse(swidl.toString())
55 |
56 | //console.log(netData)
57 | const netAuth = new PublicKey(netData.netAuthorityProgram)
58 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
59 | const walletToken = await associatedTokenAddress(provider.wallet.publicKey, tokenMint)
60 | //const tokenAccount = new PublicKey(walletToken.pubkey)
61 |
62 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
63 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
64 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
65 |
66 | const merchantAP = new PublicKey(netData.merchantApproval1)
67 | const merchantPK = new PublicKey(netData.merchant1_dest)
68 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
69 | const feesPK = new PublicKey(netData.fees1)
70 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
71 |
72 | console.log('Token Account Mint: ' + tokenMint.toString())
73 | console.log('Token Account Owner: ' + provider.wallet.publicKey.toString())
74 |
75 | console.log('Merchant Account: ' + merchantPK.toString())
76 | console.log('Merchant Token: ' + merchantTK.pubkey)
77 |
78 | var spjs
79 | try {
80 | spjs = await fs.readFile('../../data/swap.json')
81 | } catch (error) {
82 | console.error('File Error: ', error)
83 | }
84 | const swapCache = JSON.parse(spjs.toString())
85 |
86 | var djs
87 | try {
88 | djs = await fs.readFile('../../data/swap-wsol-usdv.json')
89 | } catch (error) {
90 | console.error('File Error: ', error)
91 | }
92 | const swapSpec = JSON.parse(djs.toString())
93 |
94 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
95 | const tokenMint1 = new PublicKey(swapSpec.inbMint)
96 | const tokenMint2 = new PublicKey(swapSpec.outMint)
97 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
98 | const swapDataPK = new PublicKey(swapSpec.swapData)
99 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
100 |
101 | const swapId = 0
102 | var buf = Buffer.alloc(2)
103 | buf.writeInt16LE(swapId)
104 | const swapData = await programAddress([tokenMint1.toBuffer(), tokenMint2.toBuffer(), buf], swapContractPK)
105 | const tokData1 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint1)
106 | const tokData2 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint2)
107 |
108 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
109 |
110 | const agentToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint)
111 | const tokenAccount = new PublicKey(agentToken.pubkey)
112 | console.log('Token Account Assoc: ' + tokenAccount.toString())
113 |
114 | console.log('User Token 1: ' + userToken1.pubkey)
115 | console.log('Payment Token: ' + tokenAccount.toString())
116 |
117 | const swapContract = new anchor.Program(swapContractIDL, swapContractPK)
118 | var l1 = swapContract.addEventListener('SwapEvent', (evt, slot) => {
119 | console.log('Event - Slot: ' + slot)
120 | console.log(evt.eventHash.toString())
121 | console.log(evt)
122 | })
123 |
124 | var l2 = tokenAgent.addEventListener('PaymentEvent', (evt, slot) => {
125 | console.log('Event - Slot: ' + slot)
126 | console.log(evt.eventHash.toString())
127 | console.log(evt)
128 | })
129 |
130 | const transactId = uuidv4()
131 | console.log('Merchant Payment: ' + transactId)
132 | console.log([
133 | {
134 | netAuth: netAuth.toString(),
135 | rootKey: new PublicKey(rootKey.pubkey).toString(),
136 | merchantKey: merchantPK.toString(),
137 | merchantApproval: merchantAP.toString(),
138 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
139 | userKey: provider.wallet.publicKey.toString(),
140 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
141 | tokenMint: tokenMint.toString(),
142 | tokenAccount: tokenAccount.toString(),
143 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
144 | },
145 | [
146 | { pubkey: new PublicKey(userToken1.pubkey).toString() },
147 | { pubkey: swapContractPK.toString() },
148 | { pubkey: new PublicKey(swapData.pubkey).toString() },
149 | { pubkey: new PublicKey(tokData1.pubkey).toString() },
150 | { pubkey: new PublicKey(tokData2.pubkey).toString() },
151 | { pubkey: swapFeesTK.toString() },
152 | { pubkey: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR').toString() },
153 | ],
154 | ])
155 |
156 | let apires = await tokenAgent.rpc.merchantPayment(
157 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
158 | rootKey.nonce, // inp_root_nonce
159 | new anchor.BN(12345), // inp_payment_id
160 | new anchor.BN(20 * (10**4)), // inp_amount
161 | true, // inp_swap
162 | true, // inp_swap_direction
163 | 0, // inp_swap_mode: 0 = AtxSwapContractV1
164 | swapData.nonce, // inp_swap_data_nonce
165 | tokData1.nonce, // inp_swap_inb_nonce
166 | tokData2.nonce, // inp_swap_out_nonce
167 | agentToken.nonce, // inp_swap_dst_nonce
168 | {
169 | accounts: {
170 | netAuth: netAuth,
171 | rootKey: new PublicKey(rootKey.pubkey),
172 | merchantKey: merchantPK,
173 | merchantApproval: merchantAP,
174 | merchantToken: new PublicKey(merchantTK.pubkey),
175 | userKey: provider.wallet.publicKey,
176 | tokenProgram: TOKEN_PROGRAM_ID,
177 | tokenMint: tokenMint,
178 | tokenAccount: tokenAccount,
179 | feesAccount: new PublicKey(feesTK.pubkey),
180 | },
181 | remainingAccounts: [
182 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
183 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
184 | { pubkey: new PublicKey(swapData.pubkey), isWritable: true, isSigner: false },
185 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
186 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
187 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
188 | { pubkey: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'), isWritable: false, isSigner: false },
189 | ],
190 | }
191 | )
192 | console.log(apires)
193 | }
194 |
195 | console.log('Begin')
196 | main().then(() => console.log('Success')).catch(error => {
197 | console.log(error)
198 | })
199 |
--------------------------------------------------------------------------------
/js/update_subscr.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, Transaction, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | const subscrData = new PublicKey('89inGna9CbNqkVwsGQoKMidDe6Duz2rbFib1ByCq5sum')
41 |
42 | var ndjs
43 | try {
44 | ndjs = await fs.readFile('../../data/net.json')
45 | } catch (error) {
46 | console.error('File Error: ', error)
47 | }
48 | const netData = JSON.parse(ndjs.toString())
49 | //console.log(netData)
50 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
51 | const tokenAccount = await associatedTokenAddress(provider.wallet.publicKey, tokenMint)
52 | const tokenAccountPK = new PublicKey(tokenAccount.pubkey)
53 | const netAuth = new PublicKey(netData.netAuthorityProgram)
54 | const rootKey = await programAddress([tokenAgentPK.toBuffer()], tokenAgentPK)
55 | const rootKeyPK = new PublicKey(rootKey.pubkey)
56 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
57 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
58 | const feesPK = new PublicKey(netData.fees1)
59 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
60 | const merchantPK = new PublicKey(netData.merchant1)
61 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
62 | const merchantToken = await associatedTokenAddress(merchantPK, tokenMint)
63 | const managerSK = importSecretKey(netData.manager1_secret)
64 |
65 | const delegateProgram = new PublicKey('TDLGbdMdskdC2DPz2eSeW3tuxtqRchjt5JMsUrdGTGm')
66 | const delegateRoot = await programAddress([delegateProgram.toBuffer()], delegateProgram)
67 | const delegateRootPK = new PublicKey(delegateRoot.pubkey)
68 | const allowance = await programAddress([tokenAccountPK.toBuffer(), rootKeyPK.toBuffer()], delegateProgram)
69 | const allowancePK = new PublicKey(allowance.pubkey)
70 |
71 | var act = await tokenAgent.account.subscrData.fetch(subscrData)
72 | console.log('Initial Subscription Data')
73 | console.log(act)
74 |
75 | console.log('Update Subscription')
76 | var dt0 = DateTime.now().setZone('utc')
77 | //dt0 = dt0.minus({ days: dt0.day - 1, hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ months: 1 })
78 | dt0 = dt0.minus({ hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ days: 1 })
79 | var dts0 = dt0.toFormat("yyyyLLdd")
80 | console.log('Next Rebill: ' + dts0 + ' - ' + dt0.toISO())
81 | var period = 0
82 | var periodBudget = 200000
83 | //act.useTotal = false
84 | //act.totalBudget = new anchor.BN(0)
85 | let nextRebill = new anchor.BN(Math.floor(dt0.toSeconds()))
86 | let maxDelay = new anchor.BN(act.maxDelay.toString())
87 | let pmtId = new anchor.BN(uuidparse(uuidv4()))
88 | console.log('Payment ID: ' + pmtId.toString())
89 | console.log('Max Delay: ' + maxDelay.toString())
90 | let tx = new Transaction()
91 | tx.add(tokenAgent.transaction.updateSubscription(
92 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
93 | rootKey.nonce, // inp_root_nonce
94 | true, // inp_active
95 | true, // inp_link_token
96 | new anchor.BN(100000), // inp_amount
97 | pmtId, // inp_payment_id
98 | nextRebill, // inp_next_rebill
99 | period, // inp_period (2 = monthly)
100 | new anchor.BN(periodBudget), // inp_period_budget
101 | maxDelay, // inp_max_delay
102 | new anchor.BN(0), // inp_not_valid_before
103 | new anchor.BN(0), // inp_not_valid_after
104 | false, // act.swap, // inp_swap
105 | false, // act.swap_direction, // inp_swap_direction
106 | 0, // inp_swap_mode
107 | 1, // inp_swap_data_nonce
108 | 2, // inp_swap_inb_nonce
109 | 3, // inp_swap_out_nonce
110 | 4, // inp_swap_dst_nonce
111 | {
112 | accounts: {
113 | subscrData: subscrData,
114 | netAuth: netAuth,
115 | netRoot: new PublicKey(netRoot.pubkey),
116 | netRbac: netRBAC,
117 | rootKey: new PublicKey(rootKey.pubkey),
118 | merchantKey: act.merchantKey,
119 | merchantApproval: act.merchantApproval,
120 | merchantToken: new PublicKey(merchantToken.pubkey),
121 | managerKey: act.managerKey,
122 | managerApproval: act.managerApproval,
123 | userKey: act.userKey,
124 | tokenProgram: TOKEN_PROGRAM_ID,
125 | tokenMint: act.tokenMint,
126 | tokenAccount: new PublicKey(tokenAccount.pubkey),
127 | feesAccount: new PublicKey(feesTK.pubkey),
128 | delegateProgram: delegateProgram,
129 | delegateRoot: delegateRootPK,
130 | allowance: allowancePK,
131 | systemProgram: SystemProgram.programId,
132 | }
133 | }
134 | ))
135 | var txsig = await provider.sendAndConfirm(tx, [], { 'skipPreflight': true })
136 | console.log(txsig)
137 | var act2 = await tokenAgent.account.subscrData.fetch(subscrData)
138 | console.log('Updated Subscription Data')
139 | console.log(act2)
140 |
141 | var dt1
142 | var dts1
143 | var rbtx
144 | for (var x = 0; x < 3; x++) {
145 | dt1 = dt0.plus({ days: 1 })
146 | dts1 = dt1.toFormat("yyyyLLdd")
147 | console.log('Current Rebill: ' + dts0 + ' (' + Math.floor(dt0.toSeconds()) + ')')
148 | console.log('Next Rebill: ' + dts1 + ' - ' + dt1.toISO() + ' (' + Math.floor(dt1.toSeconds()) + ')')
149 | const tx3 = await tokenAgent.transaction.process(
150 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
151 | rootKey.nonce, // inp_root_nonce
152 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_rebill_ts
153 | dts0, // inp_rebill_str
154 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_next_rebill
155 | new anchor.BN(10000), // inp_amount
156 | new anchor.BN(38483483), // inp_payment_id
157 | 0, // inp_swap_root_nonce
158 | 0, // inp_swap_inb_nonce
159 | 0, // inp_swap_out_nonce
160 | new anchor.BN(0), // inp_swap_estimate
161 | {
162 | accounts: {
163 | subscrData: subscrData,
164 | netAuth: netAuth,
165 | netRoot: new PublicKey(netRoot.pubkey),
166 | netRbac: netRBAC,
167 | rootKey: new PublicKey(rootKey.pubkey),
168 | merchantKey: act.merchantKey,
169 | merchantApproval: act.merchantApproval,
170 | merchantToken: new PublicKey(merchantToken.pubkey),
171 | managerKey: act.managerKey,
172 | managerApproval: act.managerApproval,
173 | tokenProgram: TOKEN_PROGRAM_ID,
174 | tokenMint: act.tokenMint,
175 | tokenAccount: new PublicKey(tokenAccount.pubkey),
176 | feesAccount: new PublicKey(feesTK.pubkey),
177 | delegateProgram: delegateProgram,
178 | delegateRoot: delegateRootPK,
179 | allowance: allowancePK,
180 | }
181 | }
182 | )
183 | rbtx = await provider.sendAndConfirm(tx3, [managerSK])
184 | console.log(rbtx)
185 | dt0 = dt1
186 | dts0 = dts1
187 | }
188 | }
189 |
190 | console.log('Begin')
191 | main().then(() => console.log('Success')).catch(error => {
192 | console.log(error)
193 | })
194 |
--------------------------------------------------------------------------------
/js/update_subscr_swap.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | const subscrData = new PublicKey('7Zj1XZybxxhrXSYmy9JtF5KqRZXFrSZ6GVnCv6C3Tcdz')
41 |
42 | var ndjs
43 | try {
44 | ndjs = await fs.readFile('../../data/net.json')
45 | } catch (error) {
46 | console.error('File Error: ', error)
47 | }
48 | const netData = JSON.parse(ndjs.toString())
49 | //console.log(netData)
50 |
51 | var spjs
52 | try {
53 | spjs = await fs.readFile('../../data/swap.json')
54 | } catch (error) {
55 | console.error('File Error: ', error)
56 | }
57 | const swapCache = JSON.parse(spjs.toString())
58 |
59 | var djs
60 | try {
61 | djs = await fs.readFile('../../data/swap-wsol-usdv.json')
62 | } catch (error) {
63 | console.error('File Error: ', error)
64 | }
65 | const swapSpec = JSON.parse(djs.toString())
66 |
67 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
68 | const tokenMint1 = new PublicKey(swapSpec.inbMint)
69 | const tokenMint2 = new PublicKey(swapSpec.outMint)
70 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
71 | const swapDataPK = new PublicKey(swapSpec.swapData)
72 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
73 |
74 | const swapId = 0
75 | var buf = Buffer.alloc(2)
76 | buf.writeInt16LE(swapId)
77 | const swapData = await programAddress([tokenMint1.toBuffer(), tokenMint2.toBuffer(), buf], swapContractPK)
78 | const tokData1 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint1)
79 | const tokData2 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint2)
80 |
81 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
82 |
83 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
84 | const netAuth = new PublicKey(netData.netAuthorityProgram)
85 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
86 | const rootKeyPK = new PublicKey(rootKey.pubkey)
87 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
88 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
89 | const feesPK = new PublicKey(netData.fees1)
90 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
91 | const merchantPK = new PublicKey(netData.merchant1)
92 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
93 | const managerSK = importSecretKey(netData.manager1_secret)
94 |
95 | const inputToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint1)
96 | const inputAccount = new PublicKey(inputToken.pubkey)
97 | const agentToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint)
98 | const tokenAccount = new PublicKey(agentToken.pubkey)
99 |
100 | const delegateProgram = new PublicKey('TDLGbdMdskdC2DPz2eSeW3tuxtqRchjt5JMsUrdGTGm')
101 | const delegateRoot = await programAddress([delegateProgram.toBuffer()], delegateProgram)
102 | const delegateRootPK = new PublicKey(delegateRoot.pubkey)
103 | const allowance = await programAddress([new PublicKey(userToken1.pubkey).toBuffer(), rootKeyPK.toBuffer()], delegateProgram)
104 | const allowancePK = new PublicKey(allowance.pubkey)
105 |
106 | var act = await tokenAgent.account.subscrData.fetch(subscrData)
107 | console.log('Initial Subscription Data')
108 | console.log(act)
109 |
110 | console.log('Update Subscription')
111 | var dt0 = DateTime.now().setZone('utc')
112 | //dt0 = dt0.minus({ days: dt0.day - 1, hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ months: 1 })
113 | dt0 = dt0.minus({ hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ days: 1 })
114 | var dts0 = dt0.toFormat("yyyyLLdd")
115 | console.log('Next Rebill: ' + dts0 + ' - ' + dt0.toISO())
116 | act.period = 0
117 | act.periodBudget = new anchor.BN(100000)
118 | act.useTotal = false
119 | act.totalBudget = new anchor.BN(0)
120 | act.nextRebill = new anchor.BN(Math.floor(dt0.toSeconds()))
121 | let txsig = await tokenAgent.rpc.updateSubscription(
122 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
123 | rootKey.nonce, // inp_root_nonce
124 | act.active, // inp_active
125 | true, // inp_link_token
126 | new anchor.BN(100000), // inp_amount
127 | new anchor.BN(uuidparse(uuidv4())), // inp_payment_id
128 | act.nextRebill, // inp_next_rebill
129 | act.period, // inp_period (2 = monthly)
130 | act.periodBudget, // inp_period_budget
131 | act.maxDelay, // inp_max_delay
132 | act.notValidBefore, // inp_not_valid_before
133 | act.notValidAfter, // inp_not_valid_after
134 | true, // act.swap, // inp_swap
135 | true, // act.swap_direction, // inp_swap_direction
136 | 0, // inp_swap_mode: 0 = AtxSwapContractV1
137 | swapData.nonce, // inp_swap_data_nonce
138 | tokData1.nonce, // inp_swap_inb_nonce
139 | tokData2.nonce, // inp_swap_out_nonce
140 | agentToken.nonce, // inp_swap_dst_nonce
141 | {
142 | accounts: {
143 | subscrData: subscrData,
144 | netAuth: netAuth,
145 | rootKey: new PublicKey(rootKey.pubkey),
146 | merchantApproval: act.merchantApproval,
147 | merchantToken: new PublicKey(merchantTK.pubkey),
148 | managerApproval: act.managerApproval,
149 | userKey: act.userKey,
150 | tokenProgram: TOKEN_PROGRAM_ID,
151 | tokenMint: act.tokenMint,
152 | tokenAccount: tokenAccount,
153 | feesAccount: new PublicKey(feesTK.pubkey),
154 | delegateProgram: delegateProgram,
155 | delegateRoot: delegateRootPK,
156 | allowance: allowancePK,
157 | systemProgram: SystemProgram.programId,
158 | },
159 | remainingAccounts: [
160 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
161 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
162 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
163 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
164 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
165 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
166 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
167 | ],
168 | }
169 | )
170 | console.log(txsig)
171 | var act2 = await tokenAgent.account.subscrData.fetch(subscrData)
172 | console.log('Updated Subscription Data')
173 | console.log(act2)
174 |
175 | var dt1
176 | var dts1
177 | var rbtx
178 | for (var x = 0; x < 3; x++) {
179 | dt1 = dt0.plus({ days: 1 })
180 | dts1 = dt1.toFormat("yyyyLLdd")
181 | console.log('Current Rebill: ' + dts0 + ' (' + Math.floor(dt0.toSeconds()) + ')')
182 | console.log('Next Rebill: ' + dts1 + ' - ' + dt1.toISO() + ' (' + Math.floor(dt1.toSeconds()) + ')')
183 | const tx3 = await tokenAgent.transaction.process(
184 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
185 | rootKey.nonce, // inp_root_nonce
186 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_rebill_ts
187 | dts0, // inp_rebill_str
188 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_next_rebill
189 | new anchor.BN(10000), // inp_amount
190 | new anchor.BN(4364634), // inp_payment_id
191 | swapData.nonce, // inp_swap_data_nonce
192 | tokData1.nonce, // inp_swap_inb_nonce
193 | tokData2.nonce, // inp_swap_out_nonce
194 | new anchor.BN(0), // inp_swap_estimate
195 | {
196 | accounts: {
197 | subscrData: subscrData,
198 | netAuth: netAuth,
199 | rootKey: new PublicKey(rootKey.pubkey),
200 | merchantApproval: act.merchantApproval,
201 | merchantToken: new PublicKey(merchantTK.pubkey),
202 | managerKey: managerSK.publicKey,
203 | managerApproval: act.managerApproval,
204 | tokenProgram: TOKEN_PROGRAM_ID,
205 | tokenAccount: act.tokenAccount,
206 | feesAccount: new PublicKey(feesTK.pubkey),
207 | delegateProgram: delegateProgram,
208 | delegateRoot: delegateRootPK,
209 | allowance: allowancePK,
210 | },
211 | remainingAccounts: [
212 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
213 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
214 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
215 | { pubkey: inputAccount, isWritable: true, isSigner: false },
216 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
217 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
218 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
219 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
220 | ],
221 | }
222 | )
223 | rbtx = await provider.sendAndConfirm(tx3, [managerSK])
224 | console.log(rbtx)
225 | dt0 = dt1
226 | dts0 = dts1
227 | }
228 | }
229 |
230 | console.log('Begin')
231 | main().then(() => console.log('Success')).catch(error => {
232 | console.log(error)
233 | })
234 |
--------------------------------------------------------------------------------
/js/subscribe.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | //console.log(netData)
48 | const netAuth = new PublicKey(netData.netAuthorityProgram)
49 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
50 | const walletToken = await associatedTokenAddress(provider.wallet.publicKey, tokenMint)
51 | const tokenAccount = new PublicKey(walletToken.pubkey)
52 |
53 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
54 | const rootKeyPK = new PublicKey(rootKey.pubkey)
55 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
56 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
57 |
58 | const delegateProgram = new PublicKey('TDLGbdMdskdC2DPz2eSeW3tuxtqRchjt5JMsUrdGTGm')
59 | const delegateRoot = await programAddress([delegateProgram.toBuffer()], delegateProgram)
60 | const delegateRootPK = new PublicKey(delegateRoot.pubkey)
61 | const allowance = await programAddress([tokenAccount.toBuffer(), rootKeyPK.toBuffer()], delegateProgram)
62 | const allowancePK = new PublicKey(allowance.pubkey)
63 |
64 | const subscrId = uuidv4()
65 | const subscrData = anchor.web3.Keypair.generate()
66 | const subscrDataBytes = tokenAgent.account.subscrData.size
67 | console.log('Subscr Data Bytes: ' + subscrDataBytes)
68 | const subscrDataRent = await provider.connection.getMinimumBalanceForRentExemption(subscrDataBytes)
69 | console.log('Subscr Data Rent: ' + subscrDataRent)
70 | //const merchantPK = anchor.web3.Keypair.generate()
71 | //const merchantAP = anchor.web3.Keypair.generate()
72 | const merchantPK = new PublicKey(netData.merchant1)
73 | const merchantAP = new PublicKey(netData.merchantApproval1)
74 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
75 | //const managerPK = anchor.web3.Keypair.generate()
76 | //const managerAP = anchor.web3.Keypair.generate()
77 | const managerPK = new PublicKey(netData.manager1)
78 | const managerSK = importSecretKey(netData.manager1_secret)
79 | const managerAP = new PublicKey(netData.managerApproval1)
80 | const feesPK = new PublicKey(netData.fees1)
81 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
82 |
83 | console.log('Token Account Mint: ' + tokenMint.toString())
84 | console.log('Token Account Owner: ' + provider.wallet.publicKey.toString())
85 | console.log('Token Account Assoc: ' + tokenAccount.toString())
86 |
87 | console.log('Merchant Account: ' + merchantPK.toString())
88 | console.log('Merchant Token: ' + merchantTK.pubkey)
89 | console.log('Subscription Data: ' + subscrData.publicKey.toString())
90 |
91 | const tx = new anchor.web3.Transaction()
92 | tx.add(
93 | anchor.web3.SystemProgram.createAccount({
94 | fromPubkey: provider.wallet.publicKey,
95 | newAccountPubkey: subscrData.publicKey,
96 | space: subscrDataBytes,
97 | lamports: subscrDataRent,
98 | programId: tokenAgentPK,
99 | })
100 | )
101 |
102 | var l1 = tokenAgent.addEventListener('SubscrEvent', (evt, slot) => {
103 | console.log('SubscrEvent - Slot: ' + slot)
104 | console.log(evt.eventHash.toString())
105 | console.log(evt)
106 | })
107 |
108 | console.log('Subscribe')
109 |
110 | console.log({
111 | subscrData: subscrData.publicKey.toString(),
112 | netAuth: netAuth.toString(),
113 | rootKey: new PublicKey(rootKey.pubkey).toString(),
114 | merchantApproval: merchantAP.toString(),
115 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
116 | managerApproval: managerAP.toString(),
117 | userKey: provider.wallet.publicKey.toString(),
118 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
119 | tokenAccount: tokenAccount.toString(),
120 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
121 | delegateProgram: delegateProgram.toString(),
122 | delegateRoot: delegateRootPK.toString(),
123 | allowance: allowancePK.toString(),
124 | systemProgram: SystemProgram.programId.toString(),
125 | })
126 |
127 | var dt0 = DateTime.now().setZone('utc')
128 | dt0 = dt0.minus({ days: dt0.day - 1, hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ months: 1 })
129 | var dts0 = dt0.toFormat("yyyyLL")
130 | console.log('Next Rebill: ' + dts0 + ' - ' + dt0.toISO())
131 | tx.add(tokenAgent.instruction.subscribe(
132 | true, // link_token
133 | new anchor.BN(100000), // initial_amount
134 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
135 | rootKey.nonce, // inp_root_nonce
136 | new anchor.BN(777), // inp_subscr_id
137 | new anchor.BN(888), // inp_payment_id
138 | 2, // inp_period (2 = monthly)
139 | new anchor.BN(10000), // inp_budget
140 | false, // inp_use_total
141 | new anchor.BN(0), // inp_total_budget
142 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_next_rebill
143 | 0, // inp_rebill_max
144 | new anchor.BN(0), // inp_not_valid_before
145 | new anchor.BN(0), // inp_not_valid_after
146 | new anchor.BN(0), // inp_max_delay
147 | false, // inp_swap
148 | false, // inp_swap_direction
149 | 0, // inp_swap_mode
150 | 0, // inp_swap_root_nonce
151 | 0, // inp_swap_inb_nonce
152 | 0, // inp_swap_out_nonce
153 | 0, // inp_swap_dst_nonce
154 | {
155 | accounts: {
156 | subscrData: subscrData.publicKey,
157 | netAuth: netAuth,
158 | rootKey: new PublicKey(rootKey.pubkey),
159 | merchantApproval: merchantAP,
160 | merchantToken: new PublicKey(merchantTK.pubkey),
161 | managerApproval: managerAP,
162 | userKey: provider.wallet.publicKey,
163 | tokenProgram: TOKEN_PROGRAM_ID,
164 | tokenAccount: tokenAccount,
165 | feesAccount: new PublicKey(feesTK.pubkey),
166 | delegateProgram: delegateProgram,
167 | delegateRoot: delegateRootPK,
168 | allowance: allowancePK,
169 | systemProgram: SystemProgram.programId,
170 | },
171 | }
172 | ))
173 | let txid = await provider.sendAndConfirm(tx, [subscrData])
174 | console.log(txid)
175 |
176 | if (true) {
177 | console.log('Process 1')
178 |
179 | console.log({
180 | subscrData: subscrData.publicKey.toString(),
181 | merchantKey: merchantPK.toString(),
182 | merchantApproval: merchantAP.toString(),
183 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
184 | managerKey: managerPK.toString(),
185 | managerApproval: managerAP.toString(),
186 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
187 | tokenMint: tokenMint.toString(),
188 | tokenAccount: tokenAccount.toString(),
189 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
190 | delegateProgram: delegateProgram.toString(),
191 | delegateRoot: delegateRootPK.toString(),
192 | allowance: allowancePK.toString(),
193 | })
194 |
195 | var dt1 = dt0.plus({ months: 1 })
196 | var dts1 = dt1.toFormat("yyyyLL")
197 | console.log('Next Rebill: ' + dts1 + ' - ' + dt1.toISO())
198 | const tx3 = await tokenAgent.transaction.process(
199 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
200 | rootKey.nonce, // inp_root_nonce
201 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_rebill_ts
202 | dts0, // inp_rebill_str
203 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_next_rebill
204 | new anchor.BN(10000), // inp_amount
205 | new anchor.BN(121212), // inp_payment_id
206 | 0, // inp_swap_root_nonce
207 | 0, // inp_swap_inb_nonce
208 | 0, // inp_swap_out_nonce
209 | new anchor.BN(0), // inp_swap_estimate
210 | {
211 | accounts: {
212 | subscrData: subscrData.publicKey,
213 | netAuth: netAuth,
214 | rootKey: new PublicKey(rootKey.pubkey),
215 | merchantApproval: merchantAP,
216 | merchantToken: new PublicKey(merchantTK.pubkey),
217 | managerKey: managerPK,
218 | managerApproval: managerAP,
219 | tokenProgram: TOKEN_PROGRAM_ID,
220 | tokenAccount: tokenAccount,
221 | feesAccount: new PublicKey(feesTK.pubkey),
222 | delegateProgram: delegateProgram,
223 | delegateRoot: delegateRootPK,
224 | allowance: allowancePK,
225 | }
226 | }
227 | )
228 | console.log(await provider.sendAndConfirm(tx3, [managerSK]))
229 |
230 | /* console.log('Process 2')
231 | eventId = uuidv4()
232 | dt2 = dt1.plus({ months: 1 })
233 | dts2 = dt2.toFormat("yyyyLL")
234 | console.log('Next Rebill: ' + dts2 + ' - ' + dt2.toISO())
235 | const tx4 = await tokenAgent.transaction.processSubscription(
236 | new anchor.BN(uuidparse(eventId)), // inp_event_uuid
237 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_rebill_ts
238 | dts1, // inp_rebill_str
239 | new anchor.BN(Math.floor(dt2.toSeconds())), // inp_next_rebill
240 | new anchor.BN(5000), // inp_amount
241 | {
242 | accounts: {
243 | subscrData: subscrData.publicKey,
244 | managerKey: managerPK.publicKey,
245 | managerApproval: managerAP.publicKey
246 | }
247 | }
248 | )
249 | await provider.send(tx4, [managerPK]) */
250 | }
251 | }
252 |
253 | console.log('Begin')
254 | main().then(() => console.log('Success')).catch(error => {
255 | console.log(error)
256 | })
257 |
--------------------------------------------------------------------------------
/js/prev/subscribe_swap_create.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.Provider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | //console.log(netData)
48 | const netAuth = new PublicKey(netData.netAuthorityProgram)
49 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
50 |
51 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
52 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
53 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
54 |
55 | const agentToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint)
56 | const tokenAccount = new PublicKey(agentToken.pubkey)
57 |
58 | const subscrId = uuidv4()
59 | const subscrData = anchor.web3.Keypair.generate()
60 | const subscrDataBytes = tokenAgent.account.subscrData.size
61 | const subscrDataRent = await provider.connection.getMinimumBalanceForRentExemption(subscrDataBytes)
62 | console.log('Subscr Data Rent: ' + subscrDataRent)
63 | //const merchantPK = anchor.web3.Keypair.generate()
64 | //const merchantAP = anchor.web3.Keypair.generate()
65 | const merchantPK = new PublicKey(netData.merchant1)
66 | const merchantAP = new PublicKey(netData.merchantApproval1)
67 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
68 | //const managerPK = anchor.web3.Keypair.generate()
69 | //const managerAP = anchor.web3.Keypair.generate()
70 | const managerPK = new PublicKey(netData.manager1)
71 | const managerSK = importSecretKey(netData.manager1_secret)
72 | const managerAP = new PublicKey(netData.managerApproval1)
73 | const feesPK = new PublicKey(netData.fees1)
74 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
75 |
76 | console.log('Token Account Mint: ' + tokenMint.toString())
77 | console.log('Token Account Owner: ' + provider.wallet.publicKey.toString())
78 | console.log('Token Account Assoc: ' + tokenAccount.toString())
79 |
80 | console.log('Merchant Account: ' + merchantPK.toString())
81 | console.log('Merchant Token: ' + merchantTK.pubkey)
82 |
83 | const userAgent = await programAddress([provider.wallet.publicKey.toBuffer()])
84 |
85 | console.log('Fund Account: Subscription 1')
86 | const tx = new anchor.web3.Transaction()
87 | tx.add(
88 | anchor.web3.SystemProgram.createAccount({
89 | fromPubkey: provider.wallet.publicKey,
90 | newAccountPubkey: subscrData.publicKey,
91 | space: subscrDataBytes,
92 | lamports: subscrDataRent,
93 | programId: tokenAgentPK,
94 | })
95 | )
96 |
97 | var spjs
98 | try {
99 | spjs = await fs.readFile('../../data/swap.json')
100 | } catch (error) {
101 | console.error('File Error: ', error)
102 | }
103 | const swapCache = JSON.parse(spjs.toString())
104 |
105 | var djs
106 | try {
107 | djs = await fs.readFile('../../data/swap-usdv-wsol.json')
108 | } catch (error) {
109 | console.error('File Error: ', error)
110 | }
111 | const swapSpec = JSON.parse(djs.toString())
112 |
113 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
114 | const tokenMint1 = new PublicKey(swapSpec.tokenMint1)
115 | const tokenMint2 = new PublicKey(swapSpec.tokenMint2)
116 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
117 | const swapDataPK = new PublicKey(swapSpec.swapData)
118 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
119 |
120 | const swapRootData = await programAddress([swapContractPK.toBuffer()], swapContractPK)
121 | const tkiData1 = await programAddress([tokenMint1.toBuffer()], swapContractPK)
122 | const tkiData2 = await programAddress([tokenMint2.toBuffer()], swapContractPK)
123 | const tokData1 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint1)
124 | const tokData2 = await associatedTokenAddress(new PublicKey(swapRootData.pubkey), tokenMint2)
125 |
126 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
127 |
128 | console.log('User Token 1: ' + userToken1.pubkey)
129 | console.log('Payment Token: ' + tokenAccount.toString())
130 |
131 | console.log('Subscribe Swap: ' + swapSpec.swapData)
132 | var dt0 = DateTime.now().setZone('utc')
133 | dt0 = dt0.minus({ days: dt0.day - 1, hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ months: 1 })
134 | var dts0 = dt0.toFormat("yyyyLL")
135 | console.log('Next Rebill: ' + dts0 + ' - ' + dt0.toISO())
136 | let op = await tokenAgent.instruction.subscribe(
137 | true, // link_token
138 | new anchor.BN(100000), // initial_amount
139 | userAgent.nonce, // inp_user_nonce
140 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
141 | rootKey.nonce, // inp_root_nonce
142 | netRoot.nonce, // inp_net_nonce
143 | new anchor.BN(0), // inp_subscr_id
144 | 2, // inp_period (2 = monthly)
145 | new anchor.BN(150000), // inp_budget
146 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_next_rebill
147 | true, // inp_swap
148 | swapRootData.nonce, // inp_swap_root_nonce
149 | tokData1.nonce, // inp_swap_inb_nonce
150 | tokData2.nonce, // inp_swap_out_nonce
151 | agentToken.nonce, // inp_swap_dst_nonce
152 | {
153 | accounts: {
154 | subscrData: subscrData.publicKey,
155 | netAuth: netAuth,
156 | netRoot: new PublicKey(netRoot.pubkey),
157 | netRbac: netRBAC,
158 | rootKey: new PublicKey(rootKey.pubkey),
159 | merchantKey: merchantPK,
160 | merchantApproval: merchantAP,
161 | merchantToken: new PublicKey(merchantTK.pubkey),
162 | managerKey: managerPK,
163 | managerApproval: managerAP,
164 | userKey: provider.wallet.publicKey,
165 | userAgent: new PublicKey(userAgent.pubkey),
166 | tokenProgram: TOKEN_PROGRAM_ID,
167 | tokenMint: tokenMint,
168 | tokenAccount: tokenAccount,
169 | feesAccount: new PublicKey(feesTK.pubkey),
170 | },
171 | remainingAccounts: [
172 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
173 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
174 | { pubkey: new PublicKey(swapRootData.pubkey), isWritable: false, isSigner: false },
175 | { pubkey: swapAuthDataPK, isWritable: false, isSigner: false },
176 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
177 | { pubkey: new PublicKey(tkiData1.pubkey), isWritable: true, isSigner: false },
178 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
179 | { pubkey: new PublicKey(tkiData2.pubkey), isWritable: true, isSigner: false },
180 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
181 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
182 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
183 | ],
184 | }
185 | )
186 | tx.add(op)
187 | let apires = await provider.send(tx, [subscrData])
188 | console.log(apires)
189 |
190 | if (true) {
191 | console.log('Process 1')
192 |
193 | console.log({
194 | subscrData: subscrData.publicKey.toString(),
195 | merchantKey: merchantPK.toString(),
196 | merchantApproval: merchantAP.toString(),
197 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
198 | managerKey: managerPK.toString(),
199 | managerApproval: managerAP.toString(),
200 | userAgent: new PublicKey(userAgent.pubkey).toString(),
201 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
202 | tokenMint: tokenMint.toString(),
203 | tokenAccount: tokenAccount.toString(),
204 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
205 | })
206 |
207 | var eventId = uuidv4()
208 | var dt1 = dt0.plus({ months: 1 })
209 | var dts1 = dt1.toFormat("yyyyLL")
210 | console.log('Next Rebill: ' + dts1 + ' - ' + dt1.toISO())
211 | const tx3 = await tokenAgent.transaction.process(
212 | userAgent.nonce, // inp_user_nonce
213 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
214 | rootKey.nonce, // inp_root_nonce
215 | netRoot.nonce, // inp_net_nonce
216 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_rebill_ts
217 | dts0, // inp_rebill_str
218 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_next_rebill
219 | new anchor.BN(100000), // inp_amount
220 | swapRootData.nonce, // inp_swap_root_nonce
221 | tokData1.nonce, // inp_swap_inb_nonce
222 | tokData2.nonce, // inp_swap_out_nonce
223 | {
224 | accounts: {
225 | subscrData: subscrData.publicKey,
226 | netAuth: netAuth,
227 | netRoot: new PublicKey(netRoot.pubkey),
228 | netRbac: netRBAC,
229 | rootKey: new PublicKey(rootKey.pubkey),
230 | merchantKey: merchantPK,
231 | merchantApproval: merchantAP,
232 | merchantToken: new PublicKey(merchantTK.pubkey),
233 | managerKey: managerPK,
234 | managerApproval: managerAP,
235 | userAgent: new PublicKey(userAgent.pubkey),
236 | tokenProgram: TOKEN_PROGRAM_ID,
237 | tokenMint: tokenMint,
238 | tokenAccount: tokenAccount,
239 | feesAccount: new PublicKey(feesTK.pubkey),
240 | },
241 | remainingAccounts: [
242 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
243 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
244 | { pubkey: new PublicKey(swapRootData.pubkey), isWritable: false, isSigner: false },
245 | { pubkey: swapAuthDataPK, isWritable: false, isSigner: false },
246 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
247 | { pubkey: new PublicKey(tkiData1.pubkey), isWritable: true, isSigner: false },
248 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
249 | { pubkey: new PublicKey(tkiData2.pubkey), isWritable: true, isSigner: false },
250 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
251 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
252 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
253 | ],
254 | },
255 | )
256 | let apires2 = await provider.send(tx3, [managerSK])
257 | console.log(apires2)
258 |
259 | /* console.log('Process 2')
260 | eventId = uuidv4()
261 | dt2 = dt1.plus({ months: 1 })
262 | dts2 = dt2.toFormat("yyyyLL")
263 | console.log('Next Rebill: ' + dts2 + ' - ' + dt2.toISO())
264 | const tx4 = await tokenAgent.transaction.processSubscription(
265 | new anchor.BN(uuidparse(eventId)), // inp_event_uuid
266 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_rebill_ts
267 | dts1, // inp_rebill_str
268 | new anchor.BN(Math.floor(dt2.toSeconds())), // inp_next_rebill
269 | new anchor.BN(5000), // inp_amount
270 | {
271 | accounts: {
272 | subscrData: subscrData.publicKey,
273 | managerKey: managerPK.publicKey,
274 | managerApproval: managerAP.publicKey
275 | }
276 | }
277 | )
278 | await provider.send(tx4, [managerPK]) */
279 | }
280 | }
281 |
282 | console.log('Begin')
283 | main().then(() => console.log('Success')).catch(error => {
284 | console.log(error)
285 | })
286 |
--------------------------------------------------------------------------------
/js/subscribe_swap.js:
--------------------------------------------------------------------------------
1 | const { Buffer } = require('buffer')
2 | const { DateTime } = require("luxon")
3 | const { v4: uuidv4, parse: uuidparse } = require('uuid')
4 | const { Keypair, PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY } = require('@solana/web3.js')
5 | const { TOKEN_PROGRAM_ID } = require('@solana/spl-token')
6 | const fs = require('fs').promises
7 | const base32 = require("base32.js")
8 |
9 | const anchor = require('@project-serum/anchor')
10 | const provider = anchor.AnchorProvider.env()
11 | //const provider = anchor.Provider.local()
12 | anchor.setProvider(provider)
13 | const tokenAgent = anchor.workspace.TokenAgent
14 | const tokenAgentPK = tokenAgent.programId
15 | //console.log(tokenAgent)
16 |
17 | const SPL_ASSOCIATED_TOKEN = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL')
18 | async function associatedTokenAddress(walletAddress, tokenMintAddress) {
19 | const addr = await PublicKey.findProgramAddress(
20 | [walletAddress.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), tokenMintAddress.toBuffer()],
21 | SPL_ASSOCIATED_TOKEN
22 | )
23 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
24 | return res
25 | }
26 |
27 | async function programAddress(inputs, programPK = tokenAgentPK) {
28 | const addr = await PublicKey.findProgramAddress(inputs, programPK)
29 | const res = { 'pubkey': await addr[0].toString(), 'nonce': addr[1] }
30 | return res
31 | }
32 |
33 | function importSecretKey(keyStr) {
34 | var dec = new base32.Decoder({ type: "crockford" })
35 | var spec = dec.write(keyStr).finalize()
36 | return Keypair.fromSecretKey(new Uint8Array(spec))
37 | }
38 |
39 | async function main() {
40 | var ndjs
41 | try {
42 | ndjs = await fs.readFile('../../data/net.json')
43 | } catch (error) {
44 | console.error('File Error: ', error)
45 | }
46 | const netData = JSON.parse(ndjs.toString())
47 | //console.log(netData)
48 | const netAuth = new PublicKey(netData.netAuthorityProgram)
49 | const tokenMint = new PublicKey(netData.tokenMintUSDV)
50 |
51 | const rootKey = await programAddress([tokenAgentPK.toBuffer()])
52 | const rootKeyPK = new PublicKey(rootKey.pubkey)
53 | const netRoot = await programAddress([netAuth.toBuffer()], netAuth)
54 | const netRBAC = new PublicKey(netData.netAuthorityRBAC)
55 |
56 | const agentToken = await associatedTokenAddress(new PublicKey(rootKey.pubkey), tokenMint)
57 | const tokenAccount = new PublicKey(agentToken.pubkey)
58 |
59 | const subscrId = uuidv4()
60 | const subscrData = anchor.web3.Keypair.generate()
61 | const subscrDataBytes = tokenAgent.account.subscrData.size
62 | const subscrDataRent = await provider.connection.getMinimumBalanceForRentExemption(subscrDataBytes)
63 | console.log('Subscr Data Rent: ' + subscrDataRent)
64 | //const merchantPK = anchor.web3.Keypair.generate()
65 | //const merchantAP = anchor.web3.Keypair.generate()
66 | const merchantPK = new PublicKey(netData.merchant1)
67 | const merchantAP = new PublicKey(netData.merchantApproval1)
68 | const merchantTK = await associatedTokenAddress(merchantPK, tokenMint)
69 | //const managerPK = anchor.web3.Keypair.generate()
70 | //const managerAP = anchor.web3.Keypair.generate()
71 | const managerPK = new PublicKey(netData.manager1)
72 | const managerSK = importSecretKey(netData.manager1_secret)
73 | const managerAP = new PublicKey(netData.managerApproval1)
74 | const feesPK = new PublicKey(netData.fees1)
75 | const feesTK = await associatedTokenAddress(feesPK, tokenMint)
76 |
77 | console.log('Token Account Mint: ' + tokenMint.toString())
78 | console.log('Token Account Owner: ' + provider.wallet.publicKey.toString())
79 | console.log('Token Account Assoc: ' + tokenAccount.toString())
80 |
81 | console.log('Merchant Account: ' + merchantPK.toString())
82 | console.log('Merchant Token: ' + merchantTK.pubkey)
83 |
84 | var spjs
85 | try {
86 | spjs = await fs.readFile('../../data/swap.json')
87 | } catch (error) {
88 | console.error('File Error: ', error)
89 | }
90 | const swapCache = JSON.parse(spjs.toString())
91 |
92 | var djs
93 | try {
94 | djs = await fs.readFile('../../data/swap-wsol-usdv.json')
95 | } catch (error) {
96 | console.error('File Error: ', error)
97 | }
98 | const swapSpec = JSON.parse(djs.toString())
99 |
100 | const swapContractPK = new PublicKey(swapCache.swapContractProgram)
101 | const tokenMint1 = new PublicKey(swapSpec.inbMint) // WSOL
102 | const tokenMint2 = new PublicKey(swapSpec.outMint) // USDV
103 | const swapAuthDataPK = new PublicKey(swapCache.swapContractRBAC)
104 | const swapDataPK = new PublicKey(swapSpec.swapData)
105 | const swapFeesTK = new PublicKey(swapSpec.feesToken)
106 |
107 | const swapId = 0
108 | var buf = Buffer.alloc(2)
109 | buf.writeInt16LE(swapId)
110 | const swapData = await programAddress([tokenMint1.toBuffer(), tokenMint2.toBuffer(), buf], swapContractPK)
111 | const tokData1 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint1)
112 | const tokData2 = await associatedTokenAddress(new PublicKey(swapData.pubkey), tokenMint2)
113 |
114 | const userToken1 = await associatedTokenAddress(provider.wallet.publicKey, tokenMint1)
115 | const userToken1PK = new PublicKey(userToken1.pubkey)
116 |
117 | const delegateProgram = new PublicKey('TDLGbdMdskdC2DPz2eSeW3tuxtqRchjt5JMsUrdGTGm')
118 | const delegateRoot = await programAddress([delegateProgram.toBuffer()], delegateProgram)
119 | const delegateRootPK = new PublicKey(delegateRoot.pubkey)
120 | const allowance = await programAddress([userToken1PK.toBuffer(), rootKeyPK.toBuffer()], delegateProgram)
121 | const allowancePK = new PublicKey(allowance.pubkey)
122 | const agentSwap = await associatedTokenAddress(rootKeyPK, tokenMint1)
123 | const agentSwapPK = new PublicKey(agentSwap.pubkey)
124 |
125 | console.log('User Token 1: ' + userToken1.pubkey)
126 | console.log('Payment Token: ' + tokenAccount.toString())
127 |
128 | console.log('Subscribe Swap: ' + swapSpec.swapData)
129 | var dt0 = DateTime.now().setZone('utc')
130 | dt0 = dt0.minus({ days: dt0.day - 1, hours: dt0.hour, minutes: dt0.minute, seconds: dt0.second }).plus({ months: 1 })
131 | var dts0 = dt0.toFormat("yyyyLL")
132 | console.log('Next Rebill: ' + dts0 + ' - ' + dt0.toISO())
133 |
134 | console.log({
135 | subscrData: subscrData.publicKey.toString(),
136 | netAuth: netAuth.toString(),
137 | rootKey: new PublicKey(rootKey.pubkey).toString(),
138 | merchantApproval: merchantAP.toString(),
139 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
140 | managerApproval: managerAP.toString(),
141 | userKey: provider.wallet.publicKey.toString(),
142 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
143 | tokenAccount: tokenAccount.toString(),
144 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
145 | swapData: new PublicKey(swapData.pubkey).toString(),
146 | delegateProgram: delegateProgram.toString(),
147 | delegateRoot: delegateRootPK.toString(),
148 | allowance: allowancePK.toString(),
149 | systemProgram: SystemProgram.programId.toString(),
150 | })
151 |
152 | const tx = new anchor.web3.Transaction()
153 | tx.add(anchor.web3.SystemProgram.createAccount({
154 | fromPubkey: provider.wallet.publicKey,
155 | newAccountPubkey: subscrData.publicKey,
156 | space: subscrDataBytes,
157 | lamports: subscrDataRent,
158 | programId: tokenAgentPK,
159 | }))
160 | tx.add(tokenAgent.instruction.subscribe(
161 | true, // link_token
162 | new anchor.BN(100000), // initial_amount
163 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
164 | rootKey.nonce, // inp_root_nonce
165 | new anchor.BN(777), // inp_subscr_id
166 | new anchor.BN(888), // inp_payment_id
167 | 2, // inp_period (2 = monthly)
168 | new anchor.BN(150000), // inp_budget
169 | false, // inp_use_total
170 | new anchor.BN(0), // inp_total_budget
171 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_next_rebill
172 | 0, // inp_rebill_max
173 | new anchor.BN(0), // inp_not_valid_before
174 | new anchor.BN(0), // inp_not_valid_after
175 | new anchor.BN(0), // inp_max_delay
176 | true, // inp_swap
177 | true, // inp_swap_direction
178 | 0, // inp_swap_mode: 0 = AtxSwapContractV1
179 | swapData.nonce, // inp_swap_data_nonce
180 | tokData1.nonce, // inp_swap_inb_nonce
181 | tokData2.nonce, // inp_swap_out_nonce
182 | agentToken.nonce, // inp_swap_dst_nonce
183 | {
184 | accounts: {
185 | subscrData: subscrData.publicKey,
186 | netAuth: netAuth,
187 | rootKey: new PublicKey(rootKey.pubkey),
188 | merchantApproval: merchantAP,
189 | merchantToken: new PublicKey(merchantTK.pubkey),
190 | managerApproval: managerAP,
191 | userKey: provider.wallet.publicKey,
192 | tokenProgram: TOKEN_PROGRAM_ID,
193 | tokenAccount: tokenAccount,
194 | feesAccount: new PublicKey(feesTK.pubkey),
195 | delegateProgram: delegateProgram,
196 | delegateRoot: delegateRootPK,
197 | allowance: allowancePK,
198 | systemProgram: SystemProgram.programId,
199 | },
200 | remainingAccounts: [
201 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
202 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
203 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
204 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
205 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
206 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
207 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
208 | ],
209 | }
210 | ))
211 | let apires = await provider.sendAndConfirm(tx, [subscrData])
212 | console.log(apires)
213 |
214 | if (true) {
215 | console.log('Process 1')
216 |
217 | console.log({
218 | subscrData: subscrData.publicKey.toString(),
219 | merchantKey: merchantPK.toString(),
220 | merchantApproval: merchantAP.toString(),
221 | merchantToken: new PublicKey(merchantTK.pubkey).toString(),
222 | managerKey: managerPK.toString(),
223 | managerApproval: managerAP.toString(),
224 | tokenProgram: TOKEN_PROGRAM_ID.toString(),
225 | tokenMint: tokenMint.toString(),
226 | tokenAccount: tokenAccount.toString(),
227 | feesAccount: new PublicKey(feesTK.pubkey).toString(),
228 | delegateProgram: delegateProgram.toString(),
229 | delegateRoot: delegateRootPK.toString(),
230 | allowance: allowancePK.toString(),
231 | })
232 |
233 | var eventId = uuidv4()
234 | var dt1 = dt0.plus({ months: 1 })
235 | var dts1 = dt1.toFormat("yyyyLL")
236 | console.log('Next Rebill: ' + dts1 + ' - ' + dt1.toISO())
237 | const tx3 = await tokenAgent.transaction.process(
238 | merchantTK.nonce, // inp_merchant_nonce (merchant associated token account nonce)
239 | rootKey.nonce, // inp_root_nonce
240 | new anchor.BN(Math.floor(dt0.toSeconds())), // inp_rebill_ts
241 | dts0, // inp_rebill_str
242 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_next_rebill
243 | new anchor.BN(100000), // inp_amount
244 | new anchor.BN(5757575), // inp_payment_id
245 | swapData.nonce, // inp_swap_data_nonce
246 | tokData1.nonce, // inp_swap_inb_nonce
247 | tokData2.nonce, // inp_swap_out_nonce
248 | new anchor.BN(0), // inp_swap_estimate
249 | {
250 | accounts: {
251 | subscrData: subscrData.publicKey,
252 | netAuth: netAuth,
253 | rootKey: new PublicKey(rootKey.pubkey),
254 | merchantApproval: merchantAP,
255 | merchantToken: new PublicKey(merchantTK.pubkey),
256 | managerKey: managerPK,
257 | managerApproval: managerAP,
258 | tokenProgram: TOKEN_PROGRAM_ID,
259 | tokenAccount: tokenAccount,
260 | feesAccount: new PublicKey(feesTK.pubkey),
261 | delegateProgram: delegateProgram,
262 | delegateRoot: delegateRootPK,
263 | allowance: allowancePK,
264 | },
265 | remainingAccounts: [
266 | { pubkey: new PublicKey(userToken1.pubkey), isWritable: true, isSigner: false },
267 | { pubkey: swapContractPK, isWritable: false, isSigner: false },
268 | { pubkey: swapDataPK, isWritable: true, isSigner: false },
269 | { pubkey: agentSwapPK, isWritable: true, isSigner: false },
270 | { pubkey: new PublicKey(tokData1.pubkey), isWritable: true, isSigner: false },
271 | { pubkey: new PublicKey(tokData2.pubkey), isWritable: true, isSigner: false },
272 | { pubkey: swapFeesTK, isWritable: true, isSigner: false },
273 | { pubkey: new PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'), isWritable: false, isSigner: false },
274 | ],
275 | },
276 | )
277 | let apires2 = await provider.sendAndConfirm(tx3, [managerSK])
278 | console.log(apires2)
279 |
280 | /* console.log('Process 2')
281 | eventId = uuidv4()
282 | dt2 = dt1.plus({ months: 1 })
283 | dts2 = dt2.toFormat("yyyyLL")
284 | console.log('Next Rebill: ' + dts2 + ' - ' + dt2.toISO())
285 | const tx4 = await tokenAgent.transaction.processSubscription(
286 | new anchor.BN(uuidparse(eventId)), // inp_event_uuid
287 | new anchor.BN(Math.floor(dt1.toSeconds())), // inp_rebill_ts
288 | dts1, // inp_rebill_str
289 | new anchor.BN(Math.floor(dt2.toSeconds())), // inp_next_rebill
290 | new anchor.BN(5000), // inp_amount
291 | {
292 | accounts: {
293 | subscrData: subscrData.publicKey,
294 | managerKey: managerPK.publicKey,
295 | managerApproval: managerAP.publicKey
296 | }
297 | }
298 | )
299 | await provider.send(tx4, [managerPK]) */
300 | }
301 | }
302 |
303 | console.log('Begin')
304 | main().then(() => console.log('Success')).catch(error => {
305 | console.log(error)
306 | })
307 |
--------------------------------------------------------------------------------
/Cargo.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Cargo.
2 | # It is not intended for manual editing.
3 | version = 3
4 |
5 | [[package]]
6 | name = "ahash"
7 | version = "0.4.7"
8 | source = "registry+https://github.com/rust-lang/crates.io-index"
9 | checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
10 |
11 | [[package]]
12 | name = "aho-corasick"
13 | version = "0.7.18"
14 | source = "registry+https://github.com/rust-lang/crates.io-index"
15 | checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
16 | dependencies = [
17 | "memchr",
18 | ]
19 |
20 | [[package]]
21 | name = "anchor-attribute-access-control"
22 | version = "0.25.0"
23 | source = "registry+https://github.com/rust-lang/crates.io-index"
24 | checksum = "70f6ee9518f50ff4d434471ccf569186022bdd5ef65a21d14da3ea5231af944f"
25 | dependencies = [
26 | "anchor-syn",
27 | "anyhow",
28 | "proc-macro2",
29 | "quote",
30 | "regex",
31 | "syn",
32 | ]
33 |
34 | [[package]]
35 | name = "anchor-attribute-account"
36 | version = "0.25.0"
37 | source = "registry+https://github.com/rust-lang/crates.io-index"
38 | checksum = "32c92bcf5388b52676d990f85bbfd838a8f5672393135063a50dc79b2b837c79"
39 | dependencies = [
40 | "anchor-syn",
41 | "anyhow",
42 | "bs58 0.4.0",
43 | "proc-macro2",
44 | "quote",
45 | "rustversion",
46 | "syn",
47 | ]
48 |
49 | [[package]]
50 | name = "anchor-attribute-constant"
51 | version = "0.25.0"
52 | source = "registry+https://github.com/rust-lang/crates.io-index"
53 | checksum = "0844974ac35e8ced62056b0d63777ebcdc5807438b8b189c881e2b647450b70a"
54 | dependencies = [
55 | "anchor-syn",
56 | "proc-macro2",
57 | "syn",
58 | ]
59 |
60 | [[package]]
61 | name = "anchor-attribute-error"
62 | version = "0.25.0"
63 | source = "registry+https://github.com/rust-lang/crates.io-index"
64 | checksum = "0f7467345e67a6f1d4b862b9763a4160ad89d18c247b8c902807768f7b6e23df"
65 | dependencies = [
66 | "anchor-syn",
67 | "proc-macro2",
68 | "quote",
69 | "syn",
70 | ]
71 |
72 | [[package]]
73 | name = "anchor-attribute-event"
74 | version = "0.25.0"
75 | source = "registry+https://github.com/rust-lang/crates.io-index"
76 | checksum = "8774e4c1ac71f71a5aea7e4932fb69c30e3b8155c4fa59fd69401195434528a9"
77 | dependencies = [
78 | "anchor-syn",
79 | "anyhow",
80 | "proc-macro2",
81 | "quote",
82 | "syn",
83 | ]
84 |
85 | [[package]]
86 | name = "anchor-attribute-interface"
87 | version = "0.25.0"
88 | source = "registry+https://github.com/rust-lang/crates.io-index"
89 | checksum = "90eeb6e1c80f9f94fcef93a52813f6472186200e275e83cb3fac92b801de92f7"
90 | dependencies = [
91 | "anchor-syn",
92 | "anyhow",
93 | "heck",
94 | "proc-macro2",
95 | "quote",
96 | "syn",
97 | ]
98 |
99 | [[package]]
100 | name = "anchor-attribute-program"
101 | version = "0.25.0"
102 | source = "registry+https://github.com/rust-lang/crates.io-index"
103 | checksum = "ac515a7a5a4fea7fc768b1cec40ddb948e148ea657637c75f94f283212326cb9"
104 | dependencies = [
105 | "anchor-syn",
106 | "anyhow",
107 | "proc-macro2",
108 | "quote",
109 | "syn",
110 | ]
111 |
112 | [[package]]
113 | name = "anchor-attribute-state"
114 | version = "0.25.0"
115 | source = "registry+https://github.com/rust-lang/crates.io-index"
116 | checksum = "43dc667b62ff71450f19dcfcc37b0c408fd4ddd89e8650368c2b0984b110603f"
117 | dependencies = [
118 | "anchor-syn",
119 | "anyhow",
120 | "proc-macro2",
121 | "quote",
122 | "syn",
123 | ]
124 |
125 | [[package]]
126 | name = "anchor-derive-accounts"
127 | version = "0.25.0"
128 | source = "registry+https://github.com/rust-lang/crates.io-index"
129 | checksum = "7354d583a06701d24800a8ec4c2b0491f62581a331af349205e23421e0b56643"
130 | dependencies = [
131 | "anchor-syn",
132 | "anyhow",
133 | "proc-macro2",
134 | "quote",
135 | "syn",
136 | ]
137 |
138 | [[package]]
139 | name = "anchor-lang"
140 | version = "0.25.0"
141 | source = "registry+https://github.com/rust-lang/crates.io-index"
142 | checksum = "ff5f57ec5e12fa6874b27f3d5c1f6f44302d3ad86c1266197ff7611bf6f5d251"
143 | dependencies = [
144 | "anchor-attribute-access-control",
145 | "anchor-attribute-account",
146 | "anchor-attribute-constant",
147 | "anchor-attribute-error",
148 | "anchor-attribute-event",
149 | "anchor-attribute-interface",
150 | "anchor-attribute-program",
151 | "anchor-attribute-state",
152 | "anchor-derive-accounts",
153 | "arrayref",
154 | "base64 0.13.0",
155 | "bincode",
156 | "borsh",
157 | "bytemuck",
158 | "solana-program",
159 | "thiserror",
160 | ]
161 |
162 | [[package]]
163 | name = "anchor-spl"
164 | version = "0.25.0"
165 | source = "registry+https://github.com/rust-lang/crates.io-index"
166 | checksum = "d65904c3106851f6d1bb87d504044764819d69c51d2b4346d59d399d8afa7d18"
167 | dependencies = [
168 | "anchor-lang",
169 | "solana-program",
170 | "spl-associated-token-account",
171 | "spl-token",
172 | ]
173 |
174 | [[package]]
175 | name = "anchor-syn"
176 | version = "0.25.0"
177 | source = "registry+https://github.com/rust-lang/crates.io-index"
178 | checksum = "55aa1e680d9471342122ed5b6bc13bf5da473b0f7e4677d41a6954e5cc8ad155"
179 | dependencies = [
180 | "anyhow",
181 | "bs58 0.3.1",
182 | "heck",
183 | "proc-macro2",
184 | "proc-macro2-diagnostics",
185 | "quote",
186 | "serde",
187 | "serde_json",
188 | "sha2 0.9.9",
189 | "syn",
190 | "thiserror",
191 | ]
192 |
193 | [[package]]
194 | name = "anyhow"
195 | version = "1.0.43"
196 | source = "registry+https://github.com/rust-lang/crates.io-index"
197 | checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
198 |
199 | [[package]]
200 | name = "arrayref"
201 | version = "0.3.6"
202 | source = "registry+https://github.com/rust-lang/crates.io-index"
203 | checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
204 |
205 | [[package]]
206 | name = "arrayvec"
207 | version = "0.7.2"
208 | source = "registry+https://github.com/rust-lang/crates.io-index"
209 | checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
210 |
211 | [[package]]
212 | name = "autocfg"
213 | version = "1.1.0"
214 | source = "registry+https://github.com/rust-lang/crates.io-index"
215 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
216 |
217 | [[package]]
218 | name = "base64"
219 | version = "0.12.3"
220 | source = "registry+https://github.com/rust-lang/crates.io-index"
221 | checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
222 |
223 | [[package]]
224 | name = "base64"
225 | version = "0.13.0"
226 | source = "registry+https://github.com/rust-lang/crates.io-index"
227 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
228 |
229 | [[package]]
230 | name = "bincode"
231 | version = "1.3.3"
232 | source = "registry+https://github.com/rust-lang/crates.io-index"
233 | checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
234 | dependencies = [
235 | "serde",
236 | ]
237 |
238 | [[package]]
239 | name = "bitflags"
240 | version = "1.3.2"
241 | source = "registry+https://github.com/rust-lang/crates.io-index"
242 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
243 |
244 | [[package]]
245 | name = "bitmaps"
246 | version = "2.1.0"
247 | source = "registry+https://github.com/rust-lang/crates.io-index"
248 | checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2"
249 | dependencies = [
250 | "typenum",
251 | ]
252 |
253 | [[package]]
254 | name = "blake3"
255 | version = "1.3.1"
256 | source = "registry+https://github.com/rust-lang/crates.io-index"
257 | checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f"
258 | dependencies = [
259 | "arrayref",
260 | "arrayvec",
261 | "cc",
262 | "cfg-if",
263 | "constant_time_eq",
264 | "digest 0.10.3",
265 | ]
266 |
267 | [[package]]
268 | name = "block-buffer"
269 | version = "0.9.0"
270 | source = "registry+https://github.com/rust-lang/crates.io-index"
271 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
272 | dependencies = [
273 | "generic-array",
274 | ]
275 |
276 | [[package]]
277 | name = "block-buffer"
278 | version = "0.10.2"
279 | source = "registry+https://github.com/rust-lang/crates.io-index"
280 | checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324"
281 | dependencies = [
282 | "generic-array",
283 | ]
284 |
285 | [[package]]
286 | name = "borsh"
287 | version = "0.9.1"
288 | source = "registry+https://github.com/rust-lang/crates.io-index"
289 | checksum = "18dda7dc709193c0d86a1a51050a926dc3df1cf262ec46a23a25dba421ea1924"
290 | dependencies = [
291 | "borsh-derive",
292 | "hashbrown",
293 | ]
294 |
295 | [[package]]
296 | name = "borsh-derive"
297 | version = "0.9.1"
298 | source = "registry+https://github.com/rust-lang/crates.io-index"
299 | checksum = "684155372435f578c0fa1acd13ebbb182cc19d6b38b64ae7901da4393217d264"
300 | dependencies = [
301 | "borsh-derive-internal",
302 | "borsh-schema-derive-internal",
303 | "proc-macro-crate 0.1.5",
304 | "proc-macro2",
305 | "syn",
306 | ]
307 |
308 | [[package]]
309 | name = "borsh-derive-internal"
310 | version = "0.9.1"
311 | source = "registry+https://github.com/rust-lang/crates.io-index"
312 | checksum = "2102f62f8b6d3edeab871830782285b64cc1830168094db05c8e458f209bc5c3"
313 | dependencies = [
314 | "proc-macro2",
315 | "quote",
316 | "syn",
317 | ]
318 |
319 | [[package]]
320 | name = "borsh-schema-derive-internal"
321 | version = "0.9.1"
322 | source = "registry+https://github.com/rust-lang/crates.io-index"
323 | checksum = "196c978c4c9b0b142d446ef3240690bf5a8a33497074a113ff9a337ccb750483"
324 | dependencies = [
325 | "proc-macro2",
326 | "quote",
327 | "syn",
328 | ]
329 |
330 | [[package]]
331 | name = "bs58"
332 | version = "0.3.1"
333 | source = "registry+https://github.com/rust-lang/crates.io-index"
334 | checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
335 |
336 | [[package]]
337 | name = "bs58"
338 | version = "0.4.0"
339 | source = "registry+https://github.com/rust-lang/crates.io-index"
340 | checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
341 |
342 | [[package]]
343 | name = "bumpalo"
344 | version = "3.9.1"
345 | source = "registry+https://github.com/rust-lang/crates.io-index"
346 | checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
347 |
348 | [[package]]
349 | name = "bv"
350 | version = "0.11.1"
351 | source = "registry+https://github.com/rust-lang/crates.io-index"
352 | checksum = "8834bb1d8ee5dc048ee3124f2c7c1afcc6bc9aed03f11e9dfd8c69470a5db340"
353 | dependencies = [
354 | "feature-probe",
355 | "serde",
356 | ]
357 |
358 | [[package]]
359 | name = "byte-slice-cast"
360 | version = "1.2.0"
361 | source = "registry+https://github.com/rust-lang/crates.io-index"
362 | checksum = "1d30c751592b77c499e7bce34d99d67c2c11bdc0574e9a488ddade14150a4698"
363 |
364 | [[package]]
365 | name = "bytemuck"
366 | version = "1.7.2"
367 | source = "registry+https://github.com/rust-lang/crates.io-index"
368 | checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
369 | dependencies = [
370 | "bytemuck_derive",
371 | ]
372 |
373 | [[package]]
374 | name = "bytemuck_derive"
375 | version = "1.0.1"
376 | source = "registry+https://github.com/rust-lang/crates.io-index"
377 | checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
378 | dependencies = [
379 | "proc-macro2",
380 | "quote",
381 | "syn",
382 | ]
383 |
384 | [[package]]
385 | name = "byteorder"
386 | version = "1.4.3"
387 | source = "registry+https://github.com/rust-lang/crates.io-index"
388 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
389 |
390 | [[package]]
391 | name = "cc"
392 | version = "1.0.69"
393 | source = "registry+https://github.com/rust-lang/crates.io-index"
394 | checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
395 |
396 | [[package]]
397 | name = "cfg-if"
398 | version = "1.0.0"
399 | source = "registry+https://github.com/rust-lang/crates.io-index"
400 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
401 |
402 | [[package]]
403 | name = "chrono"
404 | version = "0.4.19"
405 | source = "registry+https://github.com/rust-lang/crates.io-index"
406 | checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
407 | dependencies = [
408 | "num-integer",
409 | "num-traits",
410 | ]
411 |
412 | [[package]]
413 | name = "console_error_panic_hook"
414 | version = "0.1.7"
415 | source = "registry+https://github.com/rust-lang/crates.io-index"
416 | checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
417 | dependencies = [
418 | "cfg-if",
419 | "wasm-bindgen",
420 | ]
421 |
422 | [[package]]
423 | name = "console_log"
424 | version = "0.2.0"
425 | source = "registry+https://github.com/rust-lang/crates.io-index"
426 | checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494"
427 | dependencies = [
428 | "log",
429 | "web-sys",
430 | ]
431 |
432 | [[package]]
433 | name = "constant_time_eq"
434 | version = "0.1.5"
435 | source = "registry+https://github.com/rust-lang/crates.io-index"
436 | checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
437 |
438 | [[package]]
439 | name = "cpufeatures"
440 | version = "0.2.2"
441 | source = "registry+https://github.com/rust-lang/crates.io-index"
442 | checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
443 | dependencies = [
444 | "libc",
445 | ]
446 |
447 | [[package]]
448 | name = "crossbeam-channel"
449 | version = "0.5.6"
450 | source = "registry+https://github.com/rust-lang/crates.io-index"
451 | checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
452 | dependencies = [
453 | "cfg-if",
454 | "crossbeam-utils",
455 | ]
456 |
457 | [[package]]
458 | name = "crossbeam-deque"
459 | version = "0.8.2"
460 | source = "registry+https://github.com/rust-lang/crates.io-index"
461 | checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
462 | dependencies = [
463 | "cfg-if",
464 | "crossbeam-epoch",
465 | "crossbeam-utils",
466 | ]
467 |
468 | [[package]]
469 | name = "crossbeam-epoch"
470 | version = "0.9.10"
471 | source = "registry+https://github.com/rust-lang/crates.io-index"
472 | checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1"
473 | dependencies = [
474 | "autocfg",
475 | "cfg-if",
476 | "crossbeam-utils",
477 | "memoffset",
478 | "once_cell",
479 | "scopeguard",
480 | ]
481 |
482 | [[package]]
483 | name = "crossbeam-utils"
484 | version = "0.8.11"
485 | source = "registry+https://github.com/rust-lang/crates.io-index"
486 | checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
487 | dependencies = [
488 | "cfg-if",
489 | "once_cell",
490 | ]
491 |
492 | [[package]]
493 | name = "crunchy"
494 | version = "0.2.2"
495 | source = "registry+https://github.com/rust-lang/crates.io-index"
496 | checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
497 |
498 | [[package]]
499 | name = "crypto-common"
500 | version = "0.1.3"
501 | source = "registry+https://github.com/rust-lang/crates.io-index"
502 | checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
503 | dependencies = [
504 | "generic-array",
505 | "typenum",
506 | ]
507 |
508 | [[package]]
509 | name = "crypto-mac"
510 | version = "0.8.0"
511 | source = "registry+https://github.com/rust-lang/crates.io-index"
512 | checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
513 | dependencies = [
514 | "generic-array",
515 | "subtle",
516 | ]
517 |
518 | [[package]]
519 | name = "curve25519-dalek"
520 | version = "3.2.1"
521 | source = "registry+https://github.com/rust-lang/crates.io-index"
522 | checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0"
523 | dependencies = [
524 | "byteorder",
525 | "digest 0.9.0",
526 | "rand_core 0.5.1",
527 | "subtle",
528 | "zeroize",
529 | ]
530 |
531 | [[package]]
532 | name = "derivative"
533 | version = "2.2.0"
534 | source = "registry+https://github.com/rust-lang/crates.io-index"
535 | checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
536 | dependencies = [
537 | "proc-macro2",
538 | "quote",
539 | "syn",
540 | ]
541 |
542 | [[package]]
543 | name = "digest"
544 | version = "0.9.0"
545 | source = "registry+https://github.com/rust-lang/crates.io-index"
546 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
547 | dependencies = [
548 | "generic-array",
549 | ]
550 |
551 | [[package]]
552 | name = "digest"
553 | version = "0.10.3"
554 | source = "registry+https://github.com/rust-lang/crates.io-index"
555 | checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
556 | dependencies = [
557 | "block-buffer 0.10.2",
558 | "crypto-common",
559 | "subtle",
560 | ]
561 |
562 | [[package]]
563 | name = "either"
564 | version = "1.6.1"
565 | source = "registry+https://github.com/rust-lang/crates.io-index"
566 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
567 |
568 | [[package]]
569 | name = "feature-probe"
570 | version = "0.1.1"
571 | source = "registry+https://github.com/rust-lang/crates.io-index"
572 | checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da"
573 |
574 | [[package]]
575 | name = "generic-array"
576 | version = "0.14.6"
577 | source = "registry+https://github.com/rust-lang/crates.io-index"
578 | checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
579 | dependencies = [
580 | "serde",
581 | "typenum",
582 | "version_check",
583 | ]
584 |
585 | [[package]]
586 | name = "getrandom"
587 | version = "0.1.16"
588 | source = "registry+https://github.com/rust-lang/crates.io-index"
589 | checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
590 | dependencies = [
591 | "cfg-if",
592 | "js-sys",
593 | "libc",
594 | "wasi",
595 | "wasm-bindgen",
596 | ]
597 |
598 | [[package]]
599 | name = "hashbrown"
600 | version = "0.9.1"
601 | source = "registry+https://github.com/rust-lang/crates.io-index"
602 | checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
603 | dependencies = [
604 | "ahash",
605 | ]
606 |
607 | [[package]]
608 | name = "heck"
609 | version = "0.3.3"
610 | source = "registry+https://github.com/rust-lang/crates.io-index"
611 | checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
612 | dependencies = [
613 | "unicode-segmentation",
614 | ]
615 |
616 | [[package]]
617 | name = "hermit-abi"
618 | version = "0.1.19"
619 | source = "registry+https://github.com/rust-lang/crates.io-index"
620 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
621 | dependencies = [
622 | "libc",
623 | ]
624 |
625 | [[package]]
626 | name = "hmac"
627 | version = "0.8.1"
628 | source = "registry+https://github.com/rust-lang/crates.io-index"
629 | checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840"
630 | dependencies = [
631 | "crypto-mac",
632 | "digest 0.9.0",
633 | ]
634 |
635 | [[package]]
636 | name = "hmac-drbg"
637 | version = "0.3.0"
638 | source = "registry+https://github.com/rust-lang/crates.io-index"
639 | checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1"
640 | dependencies = [
641 | "digest 0.9.0",
642 | "generic-array",
643 | "hmac",
644 | ]
645 |
646 | [[package]]
647 | name = "im"
648 | version = "15.1.0"
649 | source = "registry+https://github.com/rust-lang/crates.io-index"
650 | checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9"
651 | dependencies = [
652 | "bitmaps",
653 | "rand_core 0.6.3",
654 | "rand_xoshiro",
655 | "rayon",
656 | "serde",
657 | "sized-chunks",
658 | "typenum",
659 | "version_check",
660 | ]
661 |
662 | [[package]]
663 | name = "itertools"
664 | version = "0.10.3"
665 | source = "registry+https://github.com/rust-lang/crates.io-index"
666 | checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
667 | dependencies = [
668 | "either",
669 | ]
670 |
671 | [[package]]
672 | name = "itoa"
673 | version = "0.4.8"
674 | source = "registry+https://github.com/rust-lang/crates.io-index"
675 | checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
676 |
677 | [[package]]
678 | name = "js-sys"
679 | version = "0.3.57"
680 | source = "registry+https://github.com/rust-lang/crates.io-index"
681 | checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397"
682 | dependencies = [
683 | "wasm-bindgen",
684 | ]
685 |
686 | [[package]]
687 | name = "keccak"
688 | version = "0.1.0"
689 | source = "registry+https://github.com/rust-lang/crates.io-index"
690 | checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7"
691 |
692 | [[package]]
693 | name = "lazy_static"
694 | version = "1.4.0"
695 | source = "registry+https://github.com/rust-lang/crates.io-index"
696 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
697 |
698 | [[package]]
699 | name = "libc"
700 | version = "0.2.100"
701 | source = "registry+https://github.com/rust-lang/crates.io-index"
702 | checksum = "a1fa8cddc8fbbee11227ef194b5317ed014b8acbf15139bd716a18ad3fe99ec5"
703 |
704 | [[package]]
705 | name = "libsecp256k1"
706 | version = "0.6.0"
707 | source = "registry+https://github.com/rust-lang/crates.io-index"
708 | checksum = "c9d220bc1feda2ac231cb78c3d26f27676b8cf82c96971f7aeef3d0cf2797c73"
709 | dependencies = [
710 | "arrayref",
711 | "base64 0.12.3",
712 | "digest 0.9.0",
713 | "hmac-drbg",
714 | "libsecp256k1-core",
715 | "libsecp256k1-gen-ecmult",
716 | "libsecp256k1-gen-genmult",
717 | "rand",
718 | "serde",
719 | "sha2 0.9.9",
720 | "typenum",
721 | ]
722 |
723 | [[package]]
724 | name = "libsecp256k1-core"
725 | version = "0.2.2"
726 | source = "registry+https://github.com/rust-lang/crates.io-index"
727 | checksum = "d0f6ab710cec28cef759c5f18671a27dae2a5f952cdaaee1d8e2908cb2478a80"
728 | dependencies = [
729 | "crunchy",
730 | "digest 0.9.0",
731 | "subtle",
732 | ]
733 |
734 | [[package]]
735 | name = "libsecp256k1-gen-ecmult"
736 | version = "0.2.1"
737 | source = "registry+https://github.com/rust-lang/crates.io-index"
738 | checksum = "ccab96b584d38fac86a83f07e659f0deafd0253dc096dab5a36d53efe653c5c3"
739 | dependencies = [
740 | "libsecp256k1-core",
741 | ]
742 |
743 | [[package]]
744 | name = "libsecp256k1-gen-genmult"
745 | version = "0.2.1"
746 | source = "registry+https://github.com/rust-lang/crates.io-index"
747 | checksum = "67abfe149395e3aa1c48a2beb32b068e2334402df8181f818d3aee2b304c4f5d"
748 | dependencies = [
749 | "libsecp256k1-core",
750 | ]
751 |
752 | [[package]]
753 | name = "lock_api"
754 | version = "0.4.7"
755 | source = "registry+https://github.com/rust-lang/crates.io-index"
756 | checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
757 | dependencies = [
758 | "autocfg",
759 | "scopeguard",
760 | ]
761 |
762 | [[package]]
763 | name = "log"
764 | version = "0.4.14"
765 | source = "registry+https://github.com/rust-lang/crates.io-index"
766 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
767 | dependencies = [
768 | "cfg-if",
769 | ]
770 |
771 | [[package]]
772 | name = "memchr"
773 | version = "2.4.1"
774 | source = "registry+https://github.com/rust-lang/crates.io-index"
775 | checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
776 |
777 | [[package]]
778 | name = "memmap2"
779 | version = "0.5.3"
780 | source = "registry+https://github.com/rust-lang/crates.io-index"
781 | checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f"
782 | dependencies = [
783 | "libc",
784 | ]
785 |
786 | [[package]]
787 | name = "memoffset"
788 | version = "0.6.5"
789 | source = "registry+https://github.com/rust-lang/crates.io-index"
790 | checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
791 | dependencies = [
792 | "autocfg",
793 | ]
794 |
795 | [[package]]
796 | name = "murmur3"
797 | version = "0.5.1"
798 | source = "registry+https://github.com/rust-lang/crates.io-index"
799 | checksum = "3ead5388e485d38e622630c6b05afd3761a6701ff15c55b279ea5b31dcb62cff"
800 |
801 | [[package]]
802 | name = "net-authority"
803 | version = "0.1.0"
804 | dependencies = [
805 | "anchor-lang",
806 | "byte-slice-cast",
807 | "bytemuck",
808 | "num_enum",
809 | "slab-alloc",
810 | "solana-program",
811 | "uuid",
812 | ]
813 |
814 | [[package]]
815 | name = "num-derive"
816 | version = "0.3.3"
817 | source = "registry+https://github.com/rust-lang/crates.io-index"
818 | checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
819 | dependencies = [
820 | "proc-macro2",
821 | "quote",
822 | "syn",
823 | ]
824 |
825 | [[package]]
826 | name = "num-integer"
827 | version = "0.1.44"
828 | source = "registry+https://github.com/rust-lang/crates.io-index"
829 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
830 | dependencies = [
831 | "autocfg",
832 | "num-traits",
833 | ]
834 |
835 | [[package]]
836 | name = "num-traits"
837 | version = "0.2.14"
838 | source = "registry+https://github.com/rust-lang/crates.io-index"
839 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
840 | dependencies = [
841 | "autocfg",
842 | ]
843 |
844 | [[package]]
845 | name = "num_cpus"
846 | version = "1.13.1"
847 | source = "registry+https://github.com/rust-lang/crates.io-index"
848 | checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
849 | dependencies = [
850 | "hermit-abi",
851 | "libc",
852 | ]
853 |
854 | [[package]]
855 | name = "num_enum"
856 | version = "0.5.4"
857 | source = "registry+https://github.com/rust-lang/crates.io-index"
858 | checksum = "3f9bd055fb730c4f8f4f57d45d35cd6b3f0980535b056dc7ff119cee6a66ed6f"
859 | dependencies = [
860 | "derivative",
861 | "num_enum_derive",
862 | ]
863 |
864 | [[package]]
865 | name = "num_enum_derive"
866 | version = "0.5.4"
867 | source = "registry+https://github.com/rust-lang/crates.io-index"
868 | checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9"
869 | dependencies = [
870 | "proc-macro-crate 1.0.0",
871 | "proc-macro2",
872 | "quote",
873 | "syn",
874 | ]
875 |
876 | [[package]]
877 | name = "once_cell"
878 | version = "1.14.0"
879 | source = "registry+https://github.com/rust-lang/crates.io-index"
880 | checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
881 |
882 | [[package]]
883 | name = "opaque-debug"
884 | version = "0.3.0"
885 | source = "registry+https://github.com/rust-lang/crates.io-index"
886 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
887 |
888 | [[package]]
889 | name = "parking_lot"
890 | version = "0.12.1"
891 | source = "registry+https://github.com/rust-lang/crates.io-index"
892 | checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
893 | dependencies = [
894 | "lock_api",
895 | "parking_lot_core",
896 | ]
897 |
898 | [[package]]
899 | name = "parking_lot_core"
900 | version = "0.9.3"
901 | source = "registry+https://github.com/rust-lang/crates.io-index"
902 | checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
903 | dependencies = [
904 | "cfg-if",
905 | "libc",
906 | "redox_syscall",
907 | "smallvec",
908 | "windows-sys",
909 | ]
910 |
911 | [[package]]
912 | name = "ppv-lite86"
913 | version = "0.2.10"
914 | source = "registry+https://github.com/rust-lang/crates.io-index"
915 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
916 |
917 | [[package]]
918 | name = "proc-macro-crate"
919 | version = "0.1.5"
920 | source = "registry+https://github.com/rust-lang/crates.io-index"
921 | checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785"
922 | dependencies = [
923 | "toml",
924 | ]
925 |
926 | [[package]]
927 | name = "proc-macro-crate"
928 | version = "1.0.0"
929 | source = "registry+https://github.com/rust-lang/crates.io-index"
930 | checksum = "41fdbd1df62156fbc5945f4762632564d7d038153091c3fcf1067f6aef7cff92"
931 | dependencies = [
932 | "thiserror",
933 | "toml",
934 | ]
935 |
936 | [[package]]
937 | name = "proc-macro2"
938 | version = "1.0.28"
939 | source = "registry+https://github.com/rust-lang/crates.io-index"
940 | checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612"
941 | dependencies = [
942 | "unicode-xid",
943 | ]
944 |
945 | [[package]]
946 | name = "proc-macro2-diagnostics"
947 | version = "0.9.1"
948 | source = "registry+https://github.com/rust-lang/crates.io-index"
949 | checksum = "4bf29726d67464d49fa6224a1d07936a8c08bb3fba727c7493f6cf1616fdaada"
950 | dependencies = [
951 | "proc-macro2",
952 | "quote",
953 | "syn",
954 | "version_check",
955 | "yansi",
956 | ]
957 |
958 | [[package]]
959 | name = "quote"
960 | version = "1.0.9"
961 | source = "registry+https://github.com/rust-lang/crates.io-index"
962 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
963 | dependencies = [
964 | "proc-macro2",
965 | ]
966 |
967 | [[package]]
968 | name = "rand"
969 | version = "0.7.3"
970 | source = "registry+https://github.com/rust-lang/crates.io-index"
971 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
972 | dependencies = [
973 | "getrandom",
974 | "libc",
975 | "rand_chacha",
976 | "rand_core 0.5.1",
977 | "rand_hc",
978 | ]
979 |
980 | [[package]]
981 | name = "rand_chacha"
982 | version = "0.2.2"
983 | source = "registry+https://github.com/rust-lang/crates.io-index"
984 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
985 | dependencies = [
986 | "ppv-lite86",
987 | "rand_core 0.5.1",
988 | ]
989 |
990 | [[package]]
991 | name = "rand_core"
992 | version = "0.5.1"
993 | source = "registry+https://github.com/rust-lang/crates.io-index"
994 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
995 | dependencies = [
996 | "getrandom",
997 | ]
998 |
999 | [[package]]
1000 | name = "rand_core"
1001 | version = "0.6.3"
1002 | source = "registry+https://github.com/rust-lang/crates.io-index"
1003 | checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
1004 |
1005 | [[package]]
1006 | name = "rand_hc"
1007 | version = "0.2.0"
1008 | source = "registry+https://github.com/rust-lang/crates.io-index"
1009 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1010 | dependencies = [
1011 | "rand_core 0.5.1",
1012 | ]
1013 |
1014 | [[package]]
1015 | name = "rand_xoshiro"
1016 | version = "0.6.0"
1017 | source = "registry+https://github.com/rust-lang/crates.io-index"
1018 | checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa"
1019 | dependencies = [
1020 | "rand_core 0.6.3",
1021 | ]
1022 |
1023 | [[package]]
1024 | name = "rayon"
1025 | version = "1.5.3"
1026 | source = "registry+https://github.com/rust-lang/crates.io-index"
1027 | checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
1028 | dependencies = [
1029 | "autocfg",
1030 | "crossbeam-deque",
1031 | "either",
1032 | "rayon-core",
1033 | ]
1034 |
1035 | [[package]]
1036 | name = "rayon-core"
1037 | version = "1.9.3"
1038 | source = "registry+https://github.com/rust-lang/crates.io-index"
1039 | checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
1040 | dependencies = [
1041 | "crossbeam-channel",
1042 | "crossbeam-deque",
1043 | "crossbeam-utils",
1044 | "num_cpus",
1045 | ]
1046 |
1047 | [[package]]
1048 | name = "redox_syscall"
1049 | version = "0.2.13"
1050 | source = "registry+https://github.com/rust-lang/crates.io-index"
1051 | checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
1052 | dependencies = [
1053 | "bitflags",
1054 | ]
1055 |
1056 | [[package]]
1057 | name = "regex"
1058 | version = "1.5.4"
1059 | source = "registry+https://github.com/rust-lang/crates.io-index"
1060 | checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
1061 | dependencies = [
1062 | "aho-corasick",
1063 | "memchr",
1064 | "regex-syntax",
1065 | ]
1066 |
1067 | [[package]]
1068 | name = "regex-syntax"
1069 | version = "0.6.25"
1070 | source = "registry+https://github.com/rust-lang/crates.io-index"
1071 | checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
1072 |
1073 | [[package]]
1074 | name = "rust_decimal"
1075 | version = "1.26.1"
1076 | source = "registry+https://github.com/rust-lang/crates.io-index"
1077 | checksum = "ee9164faf726e4f3ece4978b25ca877ddc6802fa77f38cdccb32c7f805ecd70c"
1078 | dependencies = [
1079 | "arrayvec",
1080 | "num-traits",
1081 | "serde",
1082 | ]
1083 |
1084 | [[package]]
1085 | name = "rustc_version"
1086 | version = "0.4.0"
1087 | source = "registry+https://github.com/rust-lang/crates.io-index"
1088 | checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
1089 | dependencies = [
1090 | "semver",
1091 | ]
1092 |
1093 | [[package]]
1094 | name = "rustversion"
1095 | version = "1.0.5"
1096 | source = "registry+https://github.com/rust-lang/crates.io-index"
1097 | checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
1098 |
1099 | [[package]]
1100 | name = "ryu"
1101 | version = "1.0.5"
1102 | source = "registry+https://github.com/rust-lang/crates.io-index"
1103 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
1104 |
1105 | [[package]]
1106 | name = "scopeguard"
1107 | version = "1.1.0"
1108 | source = "registry+https://github.com/rust-lang/crates.io-index"
1109 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
1110 |
1111 | [[package]]
1112 | name = "semver"
1113 | version = "1.0.7"
1114 | source = "registry+https://github.com/rust-lang/crates.io-index"
1115 | checksum = "d65bd28f48be7196d222d95b9243287f48d27aca604e08497513019ff0502cc4"
1116 |
1117 | [[package]]
1118 | name = "serde"
1119 | version = "1.0.136"
1120 | source = "registry+https://github.com/rust-lang/crates.io-index"
1121 | checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
1122 | dependencies = [
1123 | "serde_derive",
1124 | ]
1125 |
1126 | [[package]]
1127 | name = "serde_bytes"
1128 | version = "0.11.5"
1129 | source = "registry+https://github.com/rust-lang/crates.io-index"
1130 | checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
1131 | dependencies = [
1132 | "serde",
1133 | ]
1134 |
1135 | [[package]]
1136 | name = "serde_derive"
1137 | version = "1.0.136"
1138 | source = "registry+https://github.com/rust-lang/crates.io-index"
1139 | checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
1140 | dependencies = [
1141 | "proc-macro2",
1142 | "quote",
1143 | "syn",
1144 | ]
1145 |
1146 | [[package]]
1147 | name = "serde_json"
1148 | version = "1.0.66"
1149 | source = "registry+https://github.com/rust-lang/crates.io-index"
1150 | checksum = "336b10da19a12ad094b59d870ebde26a45402e5b470add4b5fd03c5048a32127"
1151 | dependencies = [
1152 | "itoa",
1153 | "ryu",
1154 | "serde",
1155 | ]
1156 |
1157 | [[package]]
1158 | name = "sha2"
1159 | version = "0.9.9"
1160 | source = "registry+https://github.com/rust-lang/crates.io-index"
1161 | checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
1162 | dependencies = [
1163 | "block-buffer 0.9.0",
1164 | "cfg-if",
1165 | "cpufeatures",
1166 | "digest 0.9.0",
1167 | "opaque-debug",
1168 | ]
1169 |
1170 | [[package]]
1171 | name = "sha2"
1172 | version = "0.10.5"
1173 | source = "registry+https://github.com/rust-lang/crates.io-index"
1174 | checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5"
1175 | dependencies = [
1176 | "cfg-if",
1177 | "cpufeatures",
1178 | "digest 0.10.3",
1179 | ]
1180 |
1181 | [[package]]
1182 | name = "sha3"
1183 | version = "0.10.4"
1184 | source = "registry+https://github.com/rust-lang/crates.io-index"
1185 | checksum = "eaedf34ed289ea47c2b741bb72e5357a209512d67bcd4bda44359e5bf0470f56"
1186 | dependencies = [
1187 | "digest 0.10.3",
1188 | "keccak",
1189 | ]
1190 |
1191 | [[package]]
1192 | name = "sized-chunks"
1193 | version = "0.6.5"
1194 | source = "registry+https://github.com/rust-lang/crates.io-index"
1195 | checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e"
1196 | dependencies = [
1197 | "bitmaps",
1198 | "typenum",
1199 | ]
1200 |
1201 | [[package]]
1202 | name = "slab-alloc"
1203 | version = "1.0.0"
1204 | dependencies = [
1205 | "arrayref",
1206 | "bytemuck",
1207 | "murmur3",
1208 | "num_enum",
1209 | "solana-program",
1210 | "static_assertions",
1211 | "thiserror",
1212 | ]
1213 |
1214 | [[package]]
1215 | name = "smallvec"
1216 | version = "1.8.0"
1217 | source = "registry+https://github.com/rust-lang/crates.io-index"
1218 | checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
1219 |
1220 | [[package]]
1221 | name = "solana-frozen-abi"
1222 | version = "1.10.38"
1223 | source = "registry+https://github.com/rust-lang/crates.io-index"
1224 | checksum = "95185172953a206d2aae8e4448d8f295c9b6e3304c43efded5192d3cc5b99d04"
1225 | dependencies = [
1226 | "bs58 0.4.0",
1227 | "bv",
1228 | "generic-array",
1229 | "im",
1230 | "lazy_static",
1231 | "log",
1232 | "memmap2",
1233 | "rustc_version",
1234 | "serde",
1235 | "serde_bytes",
1236 | "serde_derive",
1237 | "sha2 0.10.5",
1238 | "solana-frozen-abi-macro",
1239 | "thiserror",
1240 | ]
1241 |
1242 | [[package]]
1243 | name = "solana-frozen-abi-macro"
1244 | version = "1.10.38"
1245 | source = "registry+https://github.com/rust-lang/crates.io-index"
1246 | checksum = "289cfcb10682a5338f7eb2d6b1c3564975176ec7e4fb3ee1d3ff5c52f4c397fd"
1247 | dependencies = [
1248 | "proc-macro2",
1249 | "quote",
1250 | "rustc_version",
1251 | "syn",
1252 | ]
1253 |
1254 | [[package]]
1255 | name = "solana-program"
1256 | version = "1.10.38"
1257 | source = "registry+https://github.com/rust-lang/crates.io-index"
1258 | checksum = "7eca3c0f4eec9c7df7c950ac2410ccbbc9beecba19da3135c3ed68425242bb96"
1259 | dependencies = [
1260 | "base64 0.13.0",
1261 | "bincode",
1262 | "bitflags",
1263 | "blake3",
1264 | "borsh",
1265 | "borsh-derive",
1266 | "bs58 0.4.0",
1267 | "bv",
1268 | "bytemuck",
1269 | "console_error_panic_hook",
1270 | "console_log",
1271 | "curve25519-dalek",
1272 | "getrandom",
1273 | "itertools",
1274 | "js-sys",
1275 | "lazy_static",
1276 | "libsecp256k1",
1277 | "log",
1278 | "num-derive",
1279 | "num-traits",
1280 | "parking_lot",
1281 | "rand",
1282 | "rustc_version",
1283 | "rustversion",
1284 | "serde",
1285 | "serde_bytes",
1286 | "serde_derive",
1287 | "sha2 0.10.5",
1288 | "sha3",
1289 | "solana-frozen-abi",
1290 | "solana-frozen-abi-macro",
1291 | "solana-sdk-macro",
1292 | "thiserror",
1293 | "wasm-bindgen",
1294 | ]
1295 |
1296 | [[package]]
1297 | name = "solana-sdk-macro"
1298 | version = "1.10.38"
1299 | source = "registry+https://github.com/rust-lang/crates.io-index"
1300 | checksum = "dbabfc15b3d4ae7cb725b7959cf9de3ad29b53a76ec0babe6c2cb36049d2c582"
1301 | dependencies = [
1302 | "bs58 0.4.0",
1303 | "proc-macro2",
1304 | "quote",
1305 | "rustversion",
1306 | "syn",
1307 | ]
1308 |
1309 | [[package]]
1310 | name = "spl-associated-token-account"
1311 | version = "1.0.5"
1312 | source = "registry+https://github.com/rust-lang/crates.io-index"
1313 | checksum = "2b013067447a1396303ddfc294f36e3d260a32f8a16c501c295bcdc7de39b490"
1314 | dependencies = [
1315 | "borsh",
1316 | "solana-program",
1317 | "spl-token",
1318 | ]
1319 |
1320 | [[package]]
1321 | name = "spl-token"
1322 | version = "3.3.1"
1323 | source = "registry+https://github.com/rust-lang/crates.io-index"
1324 | checksum = "32d05653bed5932064a287340dbc8a3cb298ee717e5c7ec3353d7cdb9f8fb7e1"
1325 | dependencies = [
1326 | "arrayref",
1327 | "bytemuck",
1328 | "num-derive",
1329 | "num-traits",
1330 | "num_enum",
1331 | "solana-program",
1332 | "thiserror",
1333 | ]
1334 |
1335 | [[package]]
1336 | name = "static_assertions"
1337 | version = "1.1.0"
1338 | source = "registry+https://github.com/rust-lang/crates.io-index"
1339 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
1340 |
1341 | [[package]]
1342 | name = "subtle"
1343 | version = "2.4.1"
1344 | source = "registry+https://github.com/rust-lang/crates.io-index"
1345 | checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
1346 |
1347 | [[package]]
1348 | name = "superslice"
1349 | version = "1.0.0"
1350 | source = "registry+https://github.com/rust-lang/crates.io-index"
1351 | checksum = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
1352 |
1353 | [[package]]
1354 | name = "swap-contract"
1355 | version = "0.1.0"
1356 | dependencies = [
1357 | "anchor-lang",
1358 | "anchor-spl",
1359 | "byte-slice-cast",
1360 | "bytemuck",
1361 | "net-authority",
1362 | "num_enum",
1363 | "slab-alloc",
1364 | "solana-program",
1365 | "switchboard-v2",
1366 | ]
1367 |
1368 | [[package]]
1369 | name = "switchboard-v2"
1370 | version = "0.1.14"
1371 | dependencies = [
1372 | "anchor-lang",
1373 | "anchor-spl",
1374 | "bytemuck",
1375 | "rust_decimal",
1376 | "solana-program",
1377 | "spl-token",
1378 | "superslice",
1379 | ]
1380 |
1381 | [[package]]
1382 | name = "syn"
1383 | version = "1.0.75"
1384 | source = "registry+https://github.com/rust-lang/crates.io-index"
1385 | checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7"
1386 | dependencies = [
1387 | "proc-macro2",
1388 | "quote",
1389 | "unicode-xid",
1390 | ]
1391 |
1392 | [[package]]
1393 | name = "thiserror"
1394 | version = "1.0.26"
1395 | source = "registry+https://github.com/rust-lang/crates.io-index"
1396 | checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
1397 | dependencies = [
1398 | "thiserror-impl",
1399 | ]
1400 |
1401 | [[package]]
1402 | name = "thiserror-impl"
1403 | version = "1.0.26"
1404 | source = "registry+https://github.com/rust-lang/crates.io-index"
1405 | checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
1406 | dependencies = [
1407 | "proc-macro2",
1408 | "quote",
1409 | "syn",
1410 | ]
1411 |
1412 | [[package]]
1413 | name = "token-agent"
1414 | version = "0.1.0"
1415 | dependencies = [
1416 | "anchor-lang",
1417 | "anchor-spl",
1418 | "arrayref",
1419 | "bytemuck",
1420 | "chrono",
1421 | "net-authority",
1422 | "num_enum",
1423 | "solana-program",
1424 | "spl-associated-token-account",
1425 | "swap-contract",
1426 | "token-delegate",
1427 | ]
1428 |
1429 | [[package]]
1430 | name = "token-delegate"
1431 | version = "1.0.0"
1432 | dependencies = [
1433 | "anchor-lang",
1434 | "anchor-spl",
1435 | "solana-program",
1436 | ]
1437 |
1438 | [[package]]
1439 | name = "toml"
1440 | version = "0.5.8"
1441 | source = "registry+https://github.com/rust-lang/crates.io-index"
1442 | checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
1443 | dependencies = [
1444 | "serde",
1445 | ]
1446 |
1447 | [[package]]
1448 | name = "typenum"
1449 | version = "1.15.0"
1450 | source = "registry+https://github.com/rust-lang/crates.io-index"
1451 | checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
1452 |
1453 | [[package]]
1454 | name = "unicode-segmentation"
1455 | version = "1.8.0"
1456 | source = "registry+https://github.com/rust-lang/crates.io-index"
1457 | checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
1458 |
1459 | [[package]]
1460 | name = "unicode-xid"
1461 | version = "0.2.2"
1462 | source = "registry+https://github.com/rust-lang/crates.io-index"
1463 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
1464 |
1465 | [[package]]
1466 | name = "uuid"
1467 | version = "0.8.2"
1468 | source = "registry+https://github.com/rust-lang/crates.io-index"
1469 | checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
1470 |
1471 | [[package]]
1472 | name = "version_check"
1473 | version = "0.9.3"
1474 | source = "registry+https://github.com/rust-lang/crates.io-index"
1475 | checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
1476 |
1477 | [[package]]
1478 | name = "wasi"
1479 | version = "0.9.0+wasi-snapshot-preview1"
1480 | source = "registry+https://github.com/rust-lang/crates.io-index"
1481 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1482 |
1483 | [[package]]
1484 | name = "wasm-bindgen"
1485 | version = "0.2.80"
1486 | source = "registry+https://github.com/rust-lang/crates.io-index"
1487 | checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
1488 | dependencies = [
1489 | "cfg-if",
1490 | "wasm-bindgen-macro",
1491 | ]
1492 |
1493 | [[package]]
1494 | name = "wasm-bindgen-backend"
1495 | version = "0.2.80"
1496 | source = "registry+https://github.com/rust-lang/crates.io-index"
1497 | checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4"
1498 | dependencies = [
1499 | "bumpalo",
1500 | "lazy_static",
1501 | "log",
1502 | "proc-macro2",
1503 | "quote",
1504 | "syn",
1505 | "wasm-bindgen-shared",
1506 | ]
1507 |
1508 | [[package]]
1509 | name = "wasm-bindgen-macro"
1510 | version = "0.2.80"
1511 | source = "registry+https://github.com/rust-lang/crates.io-index"
1512 | checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5"
1513 | dependencies = [
1514 | "quote",
1515 | "wasm-bindgen-macro-support",
1516 | ]
1517 |
1518 | [[package]]
1519 | name = "wasm-bindgen-macro-support"
1520 | version = "0.2.80"
1521 | source = "registry+https://github.com/rust-lang/crates.io-index"
1522 | checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
1523 | dependencies = [
1524 | "proc-macro2",
1525 | "quote",
1526 | "syn",
1527 | "wasm-bindgen-backend",
1528 | "wasm-bindgen-shared",
1529 | ]
1530 |
1531 | [[package]]
1532 | name = "wasm-bindgen-shared"
1533 | version = "0.2.80"
1534 | source = "registry+https://github.com/rust-lang/crates.io-index"
1535 | checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
1536 |
1537 | [[package]]
1538 | name = "web-sys"
1539 | version = "0.3.57"
1540 | source = "registry+https://github.com/rust-lang/crates.io-index"
1541 | checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283"
1542 | dependencies = [
1543 | "js-sys",
1544 | "wasm-bindgen",
1545 | ]
1546 |
1547 | [[package]]
1548 | name = "windows-sys"
1549 | version = "0.36.1"
1550 | source = "registry+https://github.com/rust-lang/crates.io-index"
1551 | checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
1552 | dependencies = [
1553 | "windows_aarch64_msvc",
1554 | "windows_i686_gnu",
1555 | "windows_i686_msvc",
1556 | "windows_x86_64_gnu",
1557 | "windows_x86_64_msvc",
1558 | ]
1559 |
1560 | [[package]]
1561 | name = "windows_aarch64_msvc"
1562 | version = "0.36.1"
1563 | source = "registry+https://github.com/rust-lang/crates.io-index"
1564 | checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
1565 |
1566 | [[package]]
1567 | name = "windows_i686_gnu"
1568 | version = "0.36.1"
1569 | source = "registry+https://github.com/rust-lang/crates.io-index"
1570 | checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
1571 |
1572 | [[package]]
1573 | name = "windows_i686_msvc"
1574 | version = "0.36.1"
1575 | source = "registry+https://github.com/rust-lang/crates.io-index"
1576 | checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
1577 |
1578 | [[package]]
1579 | name = "windows_x86_64_gnu"
1580 | version = "0.36.1"
1581 | source = "registry+https://github.com/rust-lang/crates.io-index"
1582 | checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
1583 |
1584 | [[package]]
1585 | name = "windows_x86_64_msvc"
1586 | version = "0.36.1"
1587 | source = "registry+https://github.com/rust-lang/crates.io-index"
1588 | checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
1589 |
1590 | [[package]]
1591 | name = "yansi"
1592 | version = "0.5.0"
1593 | source = "registry+https://github.com/rust-lang/crates.io-index"
1594 | checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71"
1595 |
1596 | [[package]]
1597 | name = "zeroize"
1598 | version = "1.3.0"
1599 | source = "registry+https://github.com/rust-lang/crates.io-index"
1600 | checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd"
1601 |
--------------------------------------------------------------------------------